Unverified Commit c932de4c authored by Ilya Ryzhenkov's avatar Ilya Ryzhenkov Committed by GitHub

Generate compile_commands.json from Gradle C++ compilation tasks (#721)

parent ea067413
......@@ -9,3 +9,4 @@ deploy.sh
deploy.bat
*.xcodeproj
skiko/src/jvmMain/java
.cache
......@@ -11,6 +11,8 @@ import org.gradle.work.InputChanges
import org.gradle.workers.WorkerExecutionException
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import java.util.concurrent.Callable
import kotlin.collections.HashSet
......@@ -145,6 +147,9 @@ abstract class CompileSkikoCppTask() : AbstractSkikoNativeToolTask() {
// Replace slash for Windows paths
arg("-o", outputFile.absolutePath.replace("\\", "/"))
arg(value = sourceFile.absolutePath.replace("\\", "/"))
if (compiler.get().startsWith("clang")) {
arg("-MJ", outputFile.absolutePath + ".json")
}
}
val argFile = run {
......@@ -178,6 +183,17 @@ abstract class CompileSkikoCppTask() : AbstractSkikoNativeToolTask() {
RunExternalProcessWork.workResults.remove(work)
}
}
if (compiler.get().startsWith("clang")) {
val compileCommands = buildString {
appendLine("[")
append(sourceOutputPairs.joinToString(",\n") { (_, outputFile) ->
Files.readString(Path.of(outputFile.absolutePath + ".json")).trim().removeSuffix(",")
})
appendLine("]")
}
Files.writeString(outDir.toPath().resolve("compile_commands.json"), compileCommands)
}
}
private fun findCompilerExecutable(): File {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment