Generate compdb for all targets (#4149)
This commit is contained in:
committed by
GitHub
parent
74cbc01a04
commit
3a41617160
@@ -21,23 +21,23 @@ import java.io.FileReader
|
|||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
|
|
||||||
internal data class Entry(
|
internal data class Entry(
|
||||||
@Expose val directory: String,
|
@Expose val directory: String,
|
||||||
@Expose val file: String,
|
@Expose val file: String,
|
||||||
@Expose val arguments: List<String>,
|
@Expose val arguments: List<String>,
|
||||||
@Expose val output: String
|
@Expose val output: String
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(
|
fun create(
|
||||||
directory: File,
|
directory: File,
|
||||||
file: File,
|
file: File,
|
||||||
args: List<String>,
|
args: List<String>,
|
||||||
outputDir: File
|
outputDir: File
|
||||||
): Entry {
|
): Entry {
|
||||||
return Entry(
|
return Entry(
|
||||||
directory.absolutePath,
|
directory.absolutePath,
|
||||||
file.absolutePath,
|
file.absolutePath,
|
||||||
args + listOf(file.absolutePath),
|
args + listOf(file.absolutePath),
|
||||||
File(outputDir, file.name + ".o").absolutePath
|
File(outputDir, file.name + ".o").absolutePath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ internal data class Entry(
|
|||||||
gson.toJson(entries, it)
|
gson.toJson(entries, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readListFrom(file: File): Array<Entry> = FileReader(file).use{
|
fun readListFrom(file: File): Array<Entry> = FileReader(file).use {
|
||||||
gson.fromJson(it, Array<Entry>::class.java)
|
gson.fromJson(it, Array<Entry>::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ open class GenerateCompilationDatabase @Inject constructor(@Input val target: St
|
|||||||
@Input val executable: String,
|
@Input val executable: String,
|
||||||
@Input val compilerFlags: List<String>,
|
@Input val compilerFlags: List<String>,
|
||||||
@Input val outputDir: File
|
@Input val outputDir: File
|
||||||
): DefaultTask() {
|
) : DefaultTask() {
|
||||||
@OutputFile
|
@OutputFile
|
||||||
var outputFile = File(outputDir, "compile_commands.json")
|
var outputFile = File(outputDir, "compile_commands.json")
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ open class GenerateCompilationDatabase @Inject constructor(@Input val target: St
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class MergeCompilationDatabases @Inject constructor(): DefaultTask() {
|
open class MergeCompilationDatabases @Inject constructor() : DefaultTask() {
|
||||||
@InputFiles
|
@InputFiles
|
||||||
val inputFiles = mutableListOf<File>()
|
val inputFiles = mutableListOf<File>()
|
||||||
|
|
||||||
@@ -102,25 +102,28 @@ fun mergeCompilationDatabases(project: Project, name: String, paths: List<String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCompilationDatabaseFromCompileToBitcodeTasks(project: Project, name: String): Task {
|
/**
|
||||||
|
* Get all [CompileToBitcode] tasks in the project, group them by target, and generate
|
||||||
|
* compilation database for each target. Tasks will be named <target>[name]. Databases
|
||||||
|
* will be placed in a build dir in <target>/compile_commands.json
|
||||||
|
*/
|
||||||
|
fun createCompilationDatabasesFromCompileToBitcodeTasks(project: Project, name: String) {
|
||||||
val compileTasks = project.tasks.withType(CompileToBitcode::class.java).toList()
|
val compileTasks = project.tasks.withType(CompileToBitcode::class.java).toList()
|
||||||
val compdbTasks = compileTasks.mapNotNull { task ->
|
val compdbTasks = compileTasks.groupBy({ task -> task.target }) { task ->
|
||||||
// TODO: consider generating databases for more than just current host target.
|
project.tasks.create("${task.name}_CompilationDatabase",
|
||||||
if (task.target != HostManager.hostName) {
|
GenerateCompilationDatabase::class.java,
|
||||||
null
|
task.target,
|
||||||
} else {
|
task.srcRoot,
|
||||||
project.tasks.create("${task.name}_CompilationDatabase",
|
task.inputFiles,
|
||||||
GenerateCompilationDatabase::class.java,
|
task.executable,
|
||||||
task.target,
|
task.compilerFlags,
|
||||||
task.srcRoot,
|
task.objDir)
|
||||||
task.inputFiles,
|
}
|
||||||
task.executable,
|
for ((target, tasks) in compdbTasks) {
|
||||||
task.compilerFlags,
|
project.tasks.create("${target}${name}", MergeCompilationDatabases::class.java) { task ->
|
||||||
task.objDir)
|
task.dependsOn(tasks)
|
||||||
|
task.inputFiles.addAll(tasks.map { it.outputFile })
|
||||||
|
task.outputFile = File(File(project.buildDir, target), "compile_commands.json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return project.tasks.create(name, MergeCompilationDatabases::class.java) { task ->
|
|
||||||
task.dependsOn(compdbTasks)
|
|
||||||
task.inputFiles.addAll(compdbTasks.map { it.outputFile })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-6
@@ -739,7 +739,7 @@ task clean {
|
|||||||
doLast {
|
doLast {
|
||||||
delete distDir
|
delete distDir
|
||||||
delete bundle.outputs.files
|
delete bundle.outputs.files
|
||||||
delete tasks.findByName("compdb").outputFile
|
delete "${projectDir}/compile_commands.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,9 +752,17 @@ task pusher(type: KotlinBuildPusher){
|
|||||||
token = project.findProperty("teamcityBearToken") ?: System.getenv("TEAMCITY_BEAR_TOKEN")
|
token = project.findProperty("teamcityBearToken") ?: System.getenv("TEAMCITY_BEAR_TOKEN")
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilationDatabaseKt.mergeCompilationDatabases(project, "compdb", [
|
targetList.each { target ->
|
||||||
":common:compdb",
|
CompilationDatabaseKt.mergeCompilationDatabases(project, "${target}CompilationDatabase".toString(), [
|
||||||
":runtime:compdb"
|
":common:${target}CompilationDatabase".toString(),
|
||||||
]).configure {
|
":runtime:${target}CompilationDatabase".toString()
|
||||||
outputFile = file("$projectDir/compile_commands.json")
|
]).configure {
|
||||||
|
outputFile = file("$buildDir/${target}/compile_commands.json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task compdb(type: Copy) {
|
||||||
|
dependsOn "${hostName}CompilationDatabase"
|
||||||
|
from "$buildDir/${hostName}/compile_commands.json"
|
||||||
|
into "$projectDir"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ targetList.each { targetName ->
|
|||||||
tasks.create("${targetName}Files", CompileToBitcode, file("src/files"), 'files', targetName)
|
tasks.create("${targetName}Files", CompileToBitcode, file("src/files"), 'files', targetName)
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilationDatabaseKt.createCompilationDatabaseFromCompileToBitcodeTasks(project, "compdb")
|
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
|
||||||
|
|
||||||
task build {
|
task build {
|
||||||
dependsOn "${hostName}Hash"
|
dependsOn "${hostName}Hash"
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ targetList.each { targetName ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompilationDatabaseKt.createCompilationDatabaseFromCompileToBitcodeTasks(project, "compdb")
|
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
|
||||||
|
|
||||||
task hostRuntime(dependsOn: "${hostName}Runtime")
|
task hostRuntime(dependsOn: "${hostName}Runtime")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user