gradle-plugin: Improve artifact naming in DSL
* Replace 'baseDir' task method with 'destinationDir' allowing a user to set the full path to an artifact built * Rename outputName -> artifactName
This commit is contained in:
@@ -31,7 +31,7 @@ konanTargets = ["android_arm32", "android_arm64"]
|
||||
konanArtifacts {
|
||||
program('Polyhedron') {
|
||||
baseDir 'Polyhedron'
|
||||
outputName 'libpoly'
|
||||
artifactName 'libpoly'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -55,7 +55,7 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
protected abstract fun generateAggregateTaskDescription(task: Task): String
|
||||
protected abstract fun generateHostTaskDescription(task: Task, hostTarget: KonanTarget): String
|
||||
|
||||
protected abstract val defaultOutputDir: File
|
||||
protected abstract val defaultBaseDir: File
|
||||
|
||||
override fun didAdd(toAdd: T) {
|
||||
super.didAdd(toAdd)
|
||||
@@ -66,7 +66,7 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
|
||||
protected fun createTask(target: KonanTarget): T =
|
||||
project.tasks.create(generateTaskName(target), type) {
|
||||
it.init(defaultOutputDir, name, target)
|
||||
it.init(defaultBaseDir.targetSubdir(target), name, target)
|
||||
it.group = BasePlugin.BUILD_GROUP
|
||||
it.description = generateTaskDescription(it)
|
||||
} ?: throw Exception("Cannot create task for target: ${target.userName}")
|
||||
@@ -96,8 +96,9 @@ abstract class KonanBuildingConfig<T: KonanBuildingTask>(private val name_: Stri
|
||||
|
||||
// Common building DSL.
|
||||
|
||||
override fun outputName(name: String) = forEach { it.outputName(name) }
|
||||
override fun baseDir(dir: Any) = forEach { it.baseDir(dir) }
|
||||
override fun artifactName(name: String) = forEach { it.artifactName(name) }
|
||||
|
||||
fun baseDir(dir: Any) = forEach { it.destinationDir(project.file(dir).targetSubdir(it.target)) }
|
||||
|
||||
override fun libraries(closure: Closure<Unit>) = forEach { it.libraries(closure) }
|
||||
override fun libraries(action: Action<KonanLibrariesSpec>) = forEach { it.libraries(action) }
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ open class KonanProgram(name: String, project: ProjectInternal, instantiator: In
|
||||
override val typeForDescription: String
|
||||
get() = "executable"
|
||||
|
||||
override val defaultOutputDir: File
|
||||
override val defaultBaseDir: File
|
||||
get() = project.konanBinBaseDir
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ open class KonanLibrary(name: String, project: ProjectInternal, instantiator: In
|
||||
override val typeForDescription: String
|
||||
get() = "library"
|
||||
|
||||
override val defaultOutputDir: File
|
||||
override val defaultBaseDir: File
|
||||
get() = project.konanLibsBaseDir
|
||||
}
|
||||
|
||||
@@ -85,6 +85,6 @@ open class KonanBitcode(name: String, project: ProjectInternal, instantiator: In
|
||||
override fun generateHostTaskDescription(task: Task, hostTarget: KonanTarget) =
|
||||
"Generates bitcode for the artifact '${task.name}' for current host"
|
||||
|
||||
override val defaultOutputDir: File
|
||||
override val defaultBaseDir: File
|
||||
get() = project.konanBitcodeBaseDir
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ open class KonanInteropLibrary(name: String, project: ProjectInternal, instantia
|
||||
override fun generateHostTaskDescription(task: Task, hostTarget: KonanTarget) =
|
||||
"Build the Kotlin/Native interop library '${task.name}' for current host"
|
||||
|
||||
override val defaultOutputDir: File
|
||||
override val defaultBaseDir: File
|
||||
get() = project.konanLibsBaseDir
|
||||
|
||||
// DSL
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
||||
val repos: Set<File>
|
||||
@Input get() = mutableSetOf<File>().apply {
|
||||
addAll(explicitRepos)
|
||||
add(task.outputDir) // TODO: Check if task is a library - create a Library interface
|
||||
add(task.project.konanLibsBaseDir.resolve(target.userName))
|
||||
add(task.destinationDir) // TODO: Check if task is a library - create a Library interface
|
||||
add(task.project.konanLibsBaseDir.targetSubdir(target))
|
||||
addAll(artifacts.flatMap { it.libraries.repos })
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -25,6 +25,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin.Companion.COMPILE_ALL_TASK_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.tasks.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -59,6 +60,8 @@ internal val Project.konanBinBaseDir get() = konanBuildRoot.resolve("bin
|
||||
internal val Project.konanLibsBaseDir get() = konanBuildRoot.resolve("libs")
|
||||
internal val Project.konanBitcodeBaseDir get() = konanBuildRoot.resolve("bitcode")
|
||||
|
||||
internal fun File.targetSubdir(target: KonanTarget) = resolve(target.userName)
|
||||
|
||||
internal val Project.konanDefaultSrcFiles get() = fileTree("${projectDir.canonicalPath}/src/main/kotlin")
|
||||
internal fun Project.konanDefaultDefFile(libName: String)
|
||||
= file("${projectDir.canonicalPath}/src/main/c_interop/$libName.def")
|
||||
@@ -158,7 +161,7 @@ internal fun dumpProperties(task: Task) {
|
||||
is KonanCompileTask -> with(task) {
|
||||
println()
|
||||
println("Compilation task: ${name}")
|
||||
println("outputDir : ${outputDir}")
|
||||
println("destinationDir : ${destinationDir}")
|
||||
println("artifact : ${artifact.canonicalPath}")
|
||||
println("inputFiles : ${inputFiles.dump()}")
|
||||
println("produce : ${produce}")
|
||||
@@ -185,7 +188,7 @@ internal fun dumpProperties(task: Task) {
|
||||
is KonanInteropTask -> with(task) {
|
||||
println()
|
||||
println("Stub generation task: ${name}")
|
||||
println("outputDir : ${outputDir}")
|
||||
println("destinationDir : ${destinationDir}")
|
||||
println("artifact : ${artifact}")
|
||||
println("libraries : ${libraries.files.dump()}")
|
||||
println(" : ${libraries.artifacts.map {
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@ import org.gradle.api.Action
|
||||
import org.gradle.api.file.FileCollection
|
||||
|
||||
interface KonanArtifactSpec {
|
||||
fun outputName(name: String)
|
||||
fun baseDir(dir: Any)
|
||||
fun artifactName(name: String)
|
||||
}
|
||||
|
||||
interface KonanArtifactWithLibrariesSpec: KonanArtifactSpec {
|
||||
|
||||
+12
-15
@@ -59,37 +59,34 @@ abstract class KonanTargetableTask: DefaultTask() {
|
||||
abstract class KonanArtifactTask: KonanTargetableTask(), KonanArtifactSpec {
|
||||
|
||||
val artifact: File
|
||||
@OutputFile get() = outputDir.resolve(artifactNameWithSuffix)
|
||||
@OutputFile get() = destinationDir.resolve(artifactNameWithSuffix)
|
||||
|
||||
@Internal lateinit var baseDir: File
|
||||
@Internal lateinit var outputName: String
|
||||
|
||||
val outputDir
|
||||
@Internal get() = baseDir.resolve(target.userName)
|
||||
@Internal lateinit var destinationDir: File
|
||||
@Internal lateinit var artifactName: String
|
||||
|
||||
protected val artifactNameWithSuffix: String
|
||||
@Internal get() = "$outputName$artifactSuffix"
|
||||
@Internal get() = "$artifactName$artifactSuffix"
|
||||
|
||||
protected val artifactPath: String
|
||||
val artifactPath: String
|
||||
@Internal get() = artifact.canonicalPath
|
||||
|
||||
protected abstract val artifactSuffix: String
|
||||
@Internal get
|
||||
|
||||
internal open fun init(baseDir: File, outputName: String, target: KonanTarget) {
|
||||
internal open fun init(destinationDir: File, artifactName: String, target: KonanTarget) {
|
||||
super.init(target)
|
||||
this.baseDir = baseDir
|
||||
this.outputName = outputName
|
||||
this.destinationDir = destinationDir
|
||||
this.artifactName = artifactName
|
||||
}
|
||||
|
||||
// DSL.
|
||||
|
||||
override fun outputName(name: String) {
|
||||
outputName = name
|
||||
override fun artifactName(name: String) {
|
||||
artifactName = name
|
||||
}
|
||||
|
||||
override fun baseDir(dir: Any) {
|
||||
baseDir = project.file(dir)
|
||||
fun destinationDir(dir: Any) {
|
||||
destinationDir = project.file(dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@ abstract class KonanBuildingTask: KonanArtifactWithLibrariesTask(), KonanBuildin
|
||||
|
||||
internal abstract val toolRunner: KonanToolRunner
|
||||
|
||||
override fun init(baseDir: File, outputName: String, target: KonanTarget) {
|
||||
override fun init(destinationDir: File, artifactName: String, target: KonanTarget) {
|
||||
dependsOn(project.konanCompilerDownloadTask)
|
||||
super.init(baseDir, outputName, target)
|
||||
super.init(destinationDir, artifactName, target)
|
||||
}
|
||||
|
||||
@Input
|
||||
@@ -31,7 +31,7 @@ abstract class KonanBuildingTask: KonanArtifactWithLibrariesTask(), KonanBuildin
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
outputDir.mkdirs()
|
||||
destinationDir.mkdirs()
|
||||
if (dumpParameters) { dumpProperties(this) }
|
||||
toolRunner.run(buildArgs())
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ open class KonanInteropTask: KonanBuildingTask(), KonanInteropSpec {
|
||||
|
||||
@Internal override val toolRunner: KonanToolRunner = KonanInteropRunner(project)
|
||||
|
||||
override fun init(baseDir: File, outputName: String, target: KonanTarget) {
|
||||
super.init(baseDir, outputName, target)
|
||||
this.defFile = project.konanDefaultDefFile(outputName)
|
||||
override fun init(destinationDir: File, artifactName: String, target: KonanTarget) {
|
||||
super.init(destinationDir, artifactName, target)
|
||||
this.defFile = project.konanDefaultDefFile(artifactName)
|
||||
}
|
||||
|
||||
// Output directories -----------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user