generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cpp): add CMakefileUtil and CppBuildSystemProvider
- Add CMakefileUtil to collect CMake-related config files in a project. - Add CppBuildSystemProvider to collect Dockerfile context for C++ projects using CMake. - Update plugin XML files to include the new providers.
- Loading branch information
Showing
6 changed files
with
75 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
cpp/src/main/kotlin/cc/unitmesh/cpp/provider/CMakefileUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cc.unitmesh.cpp.provider | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.ProjectRootManager | ||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
object CMakefileUtil { | ||
val configFiles = listOf( | ||
"CMakeLists.txt", "meson.build", "Makefile", "ninja.build", | ||
"vcpkg.json", "BUILD", "sln", "vcxproj", "vcproj" | ||
) | ||
|
||
fun collectConfigFiles(project: Project): Collection<VirtualFile> = | ||
ProjectRootManager.getInstance(project).contentRoots | ||
.asSequence() | ||
.filter { it.isDirectory } | ||
.map { it.children } | ||
.map { file -> | ||
file.filter { configFiles.contains(it.name) || configFiles.contains(it.extension) } | ||
} | ||
.flatten() | ||
.toList() | ||
} |
46 changes: 46 additions & 0 deletions
46
cpp/src/main/kotlin/cc/unitmesh/cpp/provider/CppBuildSystemProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cc.unitmesh.cpp.provider | ||
|
||
import cc.unitmesh.devti.provider.BuildSystemProvider | ||
import cc.unitmesh.devti.template.context.DockerfileContext | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.jetbrains.cidr.cpp.cmake.workspace.CMakeWorkspace | ||
|
||
class CppBuildSystemProvider : BuildSystemProvider() { | ||
override fun collect(project: Project): DockerfileContext? { | ||
val config = CMakefileUtil.collectConfigFiles(project) | ||
if (config.isEmpty()) { | ||
return null | ||
} | ||
|
||
if (config.any { it.name == "CMakeLists.txt" }) { | ||
return buildCMakefileContext(config.filter { it.name == "CMakeLists.txt" }, project) | ||
} | ||
|
||
return null | ||
} | ||
|
||
val cmakeMinimumRequiredRegex = Regex("""\bcmake_minimum_required\s*\(\s*VERSION\s*(\d+(\.\d+)*)\s*\)""") | ||
private fun buildCMakefileContext(config: Collection<VirtualFile>, project: Project): DockerfileContext? { | ||
val buildToolName = "CMake" | ||
val buildToolVersion = config.firstOrNull()?.let { | ||
val content = it.inputStream.bufferedReader().readText() | ||
val version = cmakeMinimumRequiredRegex.find(content)?.groupValues?.get(1) | ||
version | ||
} ?: "unknown" | ||
|
||
val cMakeWorkspace = CMakeWorkspace.getInstance(project) | ||
if (cMakeWorkspace.isInitialized) { | ||
// todo :load version from cmakefile | ||
} | ||
|
||
return DockerfileContext( | ||
buildToolName = buildToolName, | ||
buildToolVersion = buildToolVersion, | ||
languageName = "C++", | ||
languageVersion = "unknown", | ||
taskString = config.firstOrNull()?.contentsToByteArray()?.let { String(it) } ?: "" | ||
) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters