[K/N] More idiomatic configurations usage for CompilationDatabasePlugin ^KT-53776
This commit is contained in:
committed by
Space Team
parent
f2835f3534
commit
41dbbd1fc8
+41
-34
@@ -33,9 +33,7 @@ import javax.inject.Inject
|
|||||||
* target(someTarget1) {
|
* target(someTarget1) {
|
||||||
* entry { ... }
|
* entry { ... }
|
||||||
* }
|
* }
|
||||||
* allTargets {
|
* allTargets {}
|
||||||
* mergeFrom(compilationDatabase)
|
|
||||||
* }
|
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
* Adds an entry for target `someTarget1`, and for each known target merges in databases from `:some:other:project`.
|
* Adds an entry for target `someTarget1`, and for each known target merges in databases from `:some:other:project`.
|
||||||
@@ -50,12 +48,40 @@ abstract class CompilationDatabaseExtension @Inject constructor(private val proj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val outgoingConfiguration = project.configurations.create("generateCompilationDatabase") {
|
/**
|
||||||
description = "Generate Compilation Database"
|
* Bucket of dependencies with compilation databases to merge in.
|
||||||
|
*/
|
||||||
|
val compilationDatabase: Configuration by project.configurations.creating {
|
||||||
|
description = "Compilation Database dependencies"
|
||||||
|
isCanBeConsumed = false
|
||||||
|
isCanBeResolved = false
|
||||||
|
attributes {
|
||||||
|
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(USAGE))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal resolvable configuration of compilation database dependencies.
|
||||||
|
*/
|
||||||
|
private val compilationDatabaseJSON by project.configurations.creating {
|
||||||
|
description = "Compilation Database dependencies (internal)"
|
||||||
|
isCanBeConsumed = false
|
||||||
|
isCanBeResolved = true
|
||||||
|
attributes {
|
||||||
|
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(USAGE))
|
||||||
|
}
|
||||||
|
extendsFrom(compilationDatabase)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains produced compilation database.
|
||||||
|
*/
|
||||||
|
val compilationDatabaseElements: Configuration by project.configurations.creating {
|
||||||
|
description = "Compilation Database"
|
||||||
isCanBeConsumed = true
|
isCanBeConsumed = true
|
||||||
isCanBeResolved = false
|
isCanBeResolved = false
|
||||||
attributes {
|
attributes {
|
||||||
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, USAGE))
|
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(USAGE))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,38 +169,24 @@ abstract class CompilationDatabaseExtension @Inject constructor(private val proj
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract val mergeFrom: ListProperty<Configuration>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge compilation database entries from given [configuration].
|
|
||||||
*
|
|
||||||
* @param configuration provider of additional compilation database entries
|
|
||||||
*/
|
|
||||||
fun mergeFrom(configuration: Configuration) {
|
|
||||||
mergeFrom.add(configuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gradle task that generates compilation database for [target] with optional [sanitizer].
|
* Gradle task that generates compilation database for [target] with optional [sanitizer].
|
||||||
*/
|
*/
|
||||||
val task = project.tasks.register<GenerateCompilationDatabase>("compilationDatabase${_target.name.capitalized}") {
|
val task = project.tasks.register<GenerateCompilationDatabase>("compilationDatabase${_target.name.capitalized}") {
|
||||||
description = "Generate compilation database for $_target"
|
description = "Generate compilation database for $_target"
|
||||||
group = TASK_GROUP
|
group = TASK_GROUP
|
||||||
mergeFiles.from(mergeFrom.map { configurations ->
|
mergeFiles.from(
|
||||||
configurations.map {
|
owner.compilationDatabaseJSON.incoming.artifactView {
|
||||||
it.incoming.artifactView {
|
|
||||||
attributes {
|
attributes {
|
||||||
attribute(TargetWithSanitizer.TARGET_ATTRIBUTE, _target)
|
attribute(TargetWithSanitizer.TARGET_ATTRIBUTE, _target)
|
||||||
}
|
}
|
||||||
}.files
|
}.files)
|
||||||
}
|
|
||||||
})
|
|
||||||
entries.set(this@Target.entries)
|
entries.set(this@Target.entries)
|
||||||
outputFile.set(project.layout.buildDirectory.file("$_target/compile_commands.json"))
|
outputFile.set(project.layout.buildDirectory.file("$_target/compile_commands.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
owner.outgoingConfiguration.outgoing {
|
owner.compilationDatabaseElements.outgoing {
|
||||||
variants {
|
variants {
|
||||||
create("$_target") {
|
create("$_target") {
|
||||||
attributes {
|
attributes {
|
||||||
@@ -200,23 +212,18 @@ abstract class CompilationDatabaseExtension @Inject constructor(private val proj
|
|||||||
* Generating [JSON Compilation Database](https://clang.llvm.org/docs/JSONCompilationDatabase.html).
|
* Generating [JSON Compilation Database](https://clang.llvm.org/docs/JSONCompilationDatabase.html).
|
||||||
*
|
*
|
||||||
* Creates [CompilationDatabaseExtension] extension named `compilationDatabase`.
|
* Creates [CompilationDatabaseExtension] extension named `compilationDatabase`.
|
||||||
* Creates [Configuration][org.gradle.api.artifacts.Configuration] named `compilationDatabase`.
|
*
|
||||||
|
* Creates the following [configurations][org.gradle.api.artifacts.Configuration]:
|
||||||
|
* * `compilationDatabase` - like `implementation` from java or C++ plugin. Bucket of dependencies to get other compilation databases from.
|
||||||
|
* * `compilationDatabaseElements` - like `apiElements` (sort of) from java plugin or `{variant}LinkElements` from C++ plugin. Contains produced compilation database.
|
||||||
*
|
*
|
||||||
* @see CompilationDatabaseExtension extension that this plugin creates.
|
* @see CompilationDatabaseExtension extension that this plugin creates.
|
||||||
*/
|
*/
|
||||||
open class CompilationDatabasePlugin : Plugin<Project> {
|
open class CompilationDatabasePlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
project.extensions.create<CompilationDatabaseExtension>("compilationDatabase", project)
|
|
||||||
project.dependencies.attributesSchema {
|
project.dependencies.attributesSchema {
|
||||||
attribute(TargetWithSanitizer.TARGET_ATTRIBUTE)
|
attribute(TargetWithSanitizer.TARGET_ATTRIBUTE)
|
||||||
}
|
}
|
||||||
project.configurations.create("compilationDatabase") {
|
project.extensions.create<CompilationDatabaseExtension>("compilationDatabase", project)
|
||||||
description = "Compilation Database"
|
|
||||||
isCanBeConsumed = false
|
|
||||||
isCanBeResolved = true
|
|
||||||
attributes {
|
|
||||||
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(CompilationDatabaseExtension.USAGE))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -740,11 +740,11 @@ task pusher(type: KotlinBuildPusher){
|
|||||||
}
|
}
|
||||||
|
|
||||||
compilationDatabase {
|
compilationDatabase {
|
||||||
allTargets {
|
allTargets {}
|
||||||
mergeFrom(configurations.compilationDatabase)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Replace with a more convenient user-facing task that can build for a specific target.
|
||||||
|
// like compilationDatabase with optional argument --target.
|
||||||
tasks.register("compdb", Copy) {
|
tasks.register("compdb", Copy) {
|
||||||
from compilationDatabase.hostTarget.task
|
from compilationDatabase.hostTarget.task
|
||||||
into layout.projectDirectory
|
into layout.projectDirectory
|
||||||
|
|||||||
Reference in New Issue
Block a user