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:
@@ -164,6 +164,9 @@ For this project the task graph will be the following:
|
|||||||
|
|
||||||
// Print all parameters during the build.
|
// Print all parameters during the build.
|
||||||
dumpParameters(true)
|
dumpParameters(true)
|
||||||
|
|
||||||
|
// Add the `anotherTask` to the compilation task dependencies.
|
||||||
|
dependsOn anotherTask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,5 +186,8 @@ 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.
|
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.Named
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.plugins.BasePlugin
|
import org.gradle.api.plugins.BasePlugin
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
@@ -333,4 +334,6 @@ open class KonanCompileConfig(
|
|||||||
fun dumpParameters(value: Boolean) = with(compilationTask) {
|
fun dumpParameters(value: Boolean) = with(compilationTask) {
|
||||||
dumpParameters = value
|
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.Named
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.plugins.BasePlugin
|
import org.gradle.api.plugins.BasePlugin
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
@@ -224,5 +225,6 @@ open class KonanInteropConfig(
|
|||||||
compileStubsTask.dumpParameters = value
|
compileStubsTask.dumpParameters = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dependsOn(task: Task) = generateStubsTask.dependsOn(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-11
@@ -5,6 +5,8 @@ import org.junit.rules.TemporaryFolder
|
|||||||
|
|
||||||
class KonanProject {
|
class KonanProject {
|
||||||
|
|
||||||
|
static String DEFAULT_ARTIFACT_NAME = 'main'
|
||||||
|
|
||||||
TemporaryFolder projectDir
|
TemporaryFolder projectDir
|
||||||
|
|
||||||
File getProjectDirRoot() { return projectDir.root }
|
File getProjectDirRoot() { return projectDir.root }
|
||||||
@@ -55,11 +57,11 @@ class KonanProject {
|
|||||||
plugins { id 'konan' }
|
plugins { id 'konan' }
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
main { }
|
$DEFAULT_ARTIFACT_NAME { }
|
||||||
}
|
}
|
||||||
""".stripIndent()
|
""".stripIndent()
|
||||||
)
|
)
|
||||||
compilationTasks = [":compileKonanMain", ":compileKonan", ":build"]
|
compilationTasks = [":compileKonan${DEFAULT_ARTIFACT_NAME.capitalize()}".toString(), ":compileKonan", ":build"]
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,11 +101,11 @@ class KonanProject {
|
|||||||
addSetting(container, section, parameter, "'${value.canonicalPath.replace('\\', '\\\\')}'")
|
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)
|
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)
|
addSetting("konanArtifacts", artifactName, parameter, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +141,8 @@ class KonanProject {
|
|||||||
|
|
||||||
class KonanInteropProject extends KonanProject {
|
class KonanInteropProject extends KonanProject {
|
||||||
|
|
||||||
|
static String DEFAULT_INTEROP_NAME = "stdio"
|
||||||
|
|
||||||
Set<File> defFiles = []
|
Set<File> defFiles = []
|
||||||
|
|
||||||
List<String> interopTasks = []
|
List<String> interopTasks = []
|
||||||
@@ -157,16 +161,17 @@ class KonanInteropProject extends KonanProject {
|
|||||||
plugins { id 'konan' }
|
plugins { id 'konan' }
|
||||||
|
|
||||||
konanInterop {
|
konanInterop {
|
||||||
stdio { }
|
$DEFAULT_INTEROP_NAME { }
|
||||||
}
|
}
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
main { useInterop 'stdio' }
|
$DEFAULT_ARTIFACT_NAME { useInterop '$DEFAULT_INTEROP_NAME' }
|
||||||
}
|
}
|
||||||
""".stripIndent()
|
""".stripIndent()
|
||||||
)
|
)
|
||||||
interopTasks = [":genStdioInteropStubs", ":compileStdioInteropStubs"]
|
interopTasks = [":gen${DEFAULT_INTEROP_NAME.capitalize()}InteropStubs".toString(),
|
||||||
compilationTasks = [":compileKonanMain", ":compileKonan", ":build"]
|
":compile${DEFAULT_INTEROP_NAME.capitalize()}InteropStubs".toString()]
|
||||||
|
compilationTasks = [":compileKonan${DEFAULT_ARTIFACT_NAME.capitalize()}".toString(), ":compileKonan", ":build"]
|
||||||
return result
|
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)
|
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)
|
addSetting("konanInterop", interopName, parameter, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
static KonanInteropProject create(TemporaryFolder projectDir) {
|
static KonanInteropProject create(TemporaryFolder projectDir) {
|
||||||
return createEmpty(projectDir) {
|
return createEmpty(projectDir) {
|
||||||
it.generateSrcFile("main.kt")
|
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