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
|
||||
|
||||
internal data class Entry(
|
||||
@Expose val directory: String,
|
||||
@Expose val file: String,
|
||||
@Expose val arguments: List<String>,
|
||||
@Expose val output: String
|
||||
@Expose val directory: String,
|
||||
@Expose val file: String,
|
||||
@Expose val arguments: List<String>,
|
||||
@Expose val output: String
|
||||
) {
|
||||
companion object {
|
||||
fun create(
|
||||
directory: File,
|
||||
file: File,
|
||||
args: List<String>,
|
||||
outputDir: File
|
||||
directory: File,
|
||||
file: File,
|
||||
args: List<String>,
|
||||
outputDir: File
|
||||
): Entry {
|
||||
return Entry(
|
||||
directory.absolutePath,
|
||||
file.absolutePath,
|
||||
args + listOf(file.absolutePath),
|
||||
File(outputDir, file.name + ".o").absolutePath
|
||||
directory.absolutePath,
|
||||
file.absolutePath,
|
||||
args + listOf(file.absolutePath),
|
||||
File(outputDir, file.name + ".o").absolutePath
|
||||
)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ internal data class Entry(
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ open class GenerateCompilationDatabase @Inject constructor(@Input val target: St
|
||||
@Input val executable: String,
|
||||
@Input val compilerFlags: List<String>,
|
||||
@Input val outputDir: File
|
||||
): DefaultTask() {
|
||||
) : DefaultTask() {
|
||||
@OutputFile
|
||||
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
|
||||
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 compdbTasks = compileTasks.mapNotNull { task ->
|
||||
// TODO: consider generating databases for more than just current host target.
|
||||
if (task.target != HostManager.hostName) {
|
||||
null
|
||||
} else {
|
||||
project.tasks.create("${task.name}_CompilationDatabase",
|
||||
GenerateCompilationDatabase::class.java,
|
||||
task.target,
|
||||
task.srcRoot,
|
||||
task.inputFiles,
|
||||
task.executable,
|
||||
task.compilerFlags,
|
||||
task.objDir)
|
||||
val compdbTasks = compileTasks.groupBy({ task -> task.target }) { task ->
|
||||
project.tasks.create("${task.name}_CompilationDatabase",
|
||||
GenerateCompilationDatabase::class.java,
|
||||
task.target,
|
||||
task.srcRoot,
|
||||
task.inputFiles,
|
||||
task.executable,
|
||||
task.compilerFlags,
|
||||
task.objDir)
|
||||
}
|
||||
for ((target, tasks) in compdbTasks) {
|
||||
project.tasks.create("${target}${name}", MergeCompilationDatabases::class.java) { task ->
|
||||
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 {
|
||||
delete distDir
|
||||
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")
|
||||
}
|
||||
|
||||
CompilationDatabaseKt.mergeCompilationDatabases(project, "compdb", [
|
||||
":common:compdb",
|
||||
":runtime:compdb"
|
||||
]).configure {
|
||||
outputFile = file("$projectDir/compile_commands.json")
|
||||
targetList.each { target ->
|
||||
CompilationDatabaseKt.mergeCompilationDatabases(project, "${target}CompilationDatabase".toString(), [
|
||||
":common:${target}CompilationDatabase".toString(),
|
||||
":runtime:${target}CompilationDatabase".toString()
|
||||
]).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)
|
||||
}
|
||||
|
||||
CompilationDatabaseKt.createCompilationDatabaseFromCompileToBitcodeTasks(project, "compdb")
|
||||
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
|
||||
|
||||
task build {
|
||||
dependsOn "${hostName}Hash"
|
||||
|
||||
@@ -78,7 +78,7 @@ targetList.each { targetName ->
|
||||
}
|
||||
}
|
||||
|
||||
CompilationDatabaseKt.createCompilationDatabaseFromCompileToBitcodeTasks(project, "compdb")
|
||||
CompilationDatabaseKt.createCompilationDatabasesFromCompileToBitcodeTasks(project, "CompilationDatabase")
|
||||
|
||||
task hostRuntime(dependsOn: "${hostName}Runtime")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user