gradle-plugin: Add dependsOn methods into configs
This patch adds the `dependsOn(Task)` method to both interop and
compilation configs. It allows one to use a simple syntax to add
dependencies to compilation/stub generation tasks:
konanArtifacts {
foo { dependsOn anotherTask }
}
Issue: KT-19534
This commit is contained in:
+7
-1
@@ -164,6 +164,9 @@ For this project the task graph will be the following:
|
||||
|
||||
// Print all parameters during the build.
|
||||
dumpParameters(true)
|
||||
|
||||
// Add the `anotherTask` to the compilation task dependencies.
|
||||
dependsOn anotherTask
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +185,9 @@ For this project the task graph will be the following:
|
||||
|
||||
link <files which will be linked with native stubs> // Additional files to link with native stubs.
|
||||
|
||||
dumpParameters(true) // Print all parameters during the build.
|
||||
dumpParameters(true) // Print all parameters during the build.
|
||||
|
||||
// Add the `anotherTask` to the stub generation task dependencies.
|
||||
dependsOn anotherTask
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.api.tasks.*
|
||||
@@ -333,4 +334,6 @@ open class KonanCompileConfig(
|
||||
fun dumpParameters(value: Boolean) = with(compilationTask) {
|
||||
dumpParameters = value
|
||||
}
|
||||
|
||||
fun dependsOn(task: Task) = compilationTask.dependsOn(task)
|
||||
}
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.api.tasks.*
|
||||
@@ -224,5 +225,6 @@ open class KonanInteropConfig(
|
||||
compileStubsTask.dumpParameters = value
|
||||
}
|
||||
|
||||
fun dependsOn(task: Task) = generateStubsTask.dependsOn(task)
|
||||
}
|
||||
|
||||
|
||||
+16
-11
@@ -5,6 +5,8 @@ import org.junit.rules.TemporaryFolder
|
||||
|
||||
class KonanProject {
|
||||
|
||||
static String DEFAULT_ARTIFACT_NAME = 'main'
|
||||
|
||||
TemporaryFolder projectDir
|
||||
|
||||
File getProjectDirRoot() { return projectDir.root }
|
||||
@@ -55,11 +57,11 @@ class KonanProject {
|
||||
plugins { id 'konan' }
|
||||
|
||||
konanArtifacts {
|
||||
main { }
|
||||
$DEFAULT_ARTIFACT_NAME { }
|
||||
}
|
||||
""".stripIndent()
|
||||
)
|
||||
compilationTasks = [":compileKonanMain", ":compileKonan", ":build"]
|
||||
compilationTasks = [":compileKonan${DEFAULT_ARTIFACT_NAME.capitalize()}".toString(), ":compileKonan", ":build"]
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -99,11 +101,11 @@ class KonanProject {
|
||||
addSetting(container, section, parameter, "'${value.canonicalPath.replace('\\', '\\\\')}'")
|
||||
}
|
||||
|
||||
void addCompilationSetting(String artifactName, String parameter, String value) {
|
||||
void addCompilationSetting(String artifactName = DEFAULT_ARTIFACT_NAME, String parameter, String value) {
|
||||
addSetting("konanArtifacts", artifactName, parameter, value)
|
||||
}
|
||||
|
||||
void addCompilationSetting(String artifactName, String parameter, File value) {
|
||||
void addCompilationSetting(String artifactName = DEFAULT_ARTIFACT_NAME, String parameter, File value) {
|
||||
addSetting("konanArtifacts", artifactName, parameter, value)
|
||||
}
|
||||
|
||||
@@ -139,6 +141,8 @@ class KonanProject {
|
||||
|
||||
class KonanInteropProject extends KonanProject {
|
||||
|
||||
static String DEFAULT_INTEROP_NAME = "stdio"
|
||||
|
||||
Set<File> defFiles = []
|
||||
|
||||
List<String> interopTasks = []
|
||||
@@ -157,16 +161,17 @@ class KonanInteropProject extends KonanProject {
|
||||
plugins { id 'konan' }
|
||||
|
||||
konanInterop {
|
||||
stdio { }
|
||||
$DEFAULT_INTEROP_NAME { }
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
main { useInterop 'stdio' }
|
||||
$DEFAULT_ARTIFACT_NAME { useInterop '$DEFAULT_INTEROP_NAME' }
|
||||
}
|
||||
""".stripIndent()
|
||||
)
|
||||
interopTasks = [":genStdioInteropStubs", ":compileStdioInteropStubs"]
|
||||
compilationTasks = [":compileKonanMain", ":compileKonan", ":build"]
|
||||
interopTasks = [":gen${DEFAULT_INTEROP_NAME.capitalize()}InteropStubs".toString(),
|
||||
":compile${DEFAULT_INTEROP_NAME.capitalize()}InteropStubs".toString()]
|
||||
compilationTasks = [":compileKonan${DEFAULT_ARTIFACT_NAME.capitalize()}".toString(), ":compileKonan", ":build"]
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -184,18 +189,18 @@ class KonanInteropProject extends KonanProject {
|
||||
)
|
||||
}
|
||||
|
||||
void addInteropSetting(String interopName, String parameter, String value) {
|
||||
void addInteropSetting(String interopName = DEFAULT_INTEROP_NAME, String parameter, String value) {
|
||||
addSetting("konanInterop", interopName, parameter, value)
|
||||
}
|
||||
|
||||
void addInteropSetting(String interopName, String parameter, File value) {
|
||||
void addInteropSetting(String interopName = DEFAULT_INTEROP_NAME, String parameter, File value) {
|
||||
addSetting("konanInterop", interopName, parameter, value)
|
||||
}
|
||||
|
||||
static KonanInteropProject create(TemporaryFolder projectDir) {
|
||||
return createEmpty(projectDir) {
|
||||
it.generateSrcFile("main.kt")
|
||||
it.generateDefFile("stdio.def")
|
||||
it.generateDefFile("${DEFAULT_INTEROP_NAME}.def")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import spock.lang.Specification
|
||||
|
||||
|
||||
class TaskSpecification extends Specification {
|
||||
|
||||
@Rule
|
||||
TemporaryFolder tmpFolder = new TemporaryFolder()
|
||||
|
||||
def 'Configs should allow user to add dependencies to them'() {
|
||||
when:
|
||||
def project = KonanInteropProject.createEmpty(tmpFolder) { KonanInteropProject it ->
|
||||
it.generateSrcFile("main.kt")
|
||||
}
|
||||
project.buildFile.append("""
|
||||
task beforeInterop(type: DefaultTask) { doLast { println("Before Interop") } }
|
||||
task beforeCompilation(type: DefaultTask) { doLast { println("Before compilation") } }
|
||||
""".stripIndent())
|
||||
project.addInteropSetting("dependsOn", "beforeInterop")
|
||||
project.addCompilationSetting("dependsOn", "beforeCompilation")
|
||||
def result = project.createRunner().withArguments('build').build()
|
||||
|
||||
then:
|
||||
def beforeInterop = result.task(":beforeInterop")
|
||||
beforeInterop != null && beforeInterop.outcome == TaskOutcome.SUCCESS
|
||||
def beforeCompilation = result.task(":beforeCompilation")
|
||||
beforeCompilation != null && beforeCompilation.outcome == TaskOutcome.SUCCESS
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user