diff options
author | Sebastien Hertz <shertz@google.com> | 2017-09-11 11:03:26 +0200 |
---|---|---|
committer | Sebastien Hertz <shertz@google.com> | 2017-09-11 11:03:26 +0200 |
commit | 9006e9c85e7f2c28fe0b21b02ad91f7b1e12d372 (patch) | |
tree | 32dbae64ba1cd516efaa758cdd565ac4490a22d4 | |
parent | dbc024a997762158855aeca1f60d2c45ae690a0f (diff) | |
download | r8-9006e9c85e7f2c28fe0b21b02ad91f7b1e12d372.tar.gz |
Create gradle task for kotlin compiler
Also upgrade kotlin runtime dependencies to the same version.
Change-Id: Ie68a2f4479e5098528e13dd5540cfa1d34c28b24
-rw-r--r-- | build.gradle | 16 | ||||
-rw-r--r-- | buildSrc/src/main/java/kotlin/Kotlinc.java | 68 |
2 files changed, 72 insertions, 12 deletions
diff --git a/build.gradle b/build.gradle index 4060a7ac5..934c6509c 100644 --- a/build.gradle +++ b/build.gradle @@ -136,7 +136,7 @@ dependencies { supportLibs 'com.android.support:support-v4:25.4.0' supportLibs 'junit:junit:4.12' supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0' - debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3' + debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3' } protobuf { @@ -588,17 +588,9 @@ task buildDebugTestResourcesJars { } def kotlinResourcesDir = file("src/test/debugTestResourcesKotlin") def kotlinHostJar = "debug_test_resources_kotlin.jar" - task "jar_debugTestResourcesKotlin"(type: Exec) { - if (OperatingSystem.current().isWindows()) { - executable file("third_party/kotlin/kotlinc/bin/kotlinc.bat") - } else { - executable file("third_party/kotlin/kotlinc/bin/kotlinc"); - } - args "-include-runtime" - args "-nowarn" - args "-d" - args "build/test/${kotlinHostJar}" - args fileTree(dir: kotlinResourcesDir, include: '**/*.kt') + task "jar_debugTestResourcesKotlin"(type: kotlin.Kotlinc) { + source = fileTree(dir: kotlinResourcesDir, include: '**/*.kt') + destination = file("build/test/${kotlinHostJar}") } dependsOn downloadDeps dependsOn jar_debugTestResources diff --git a/buildSrc/src/main/java/kotlin/Kotlinc.java b/buildSrc/src/main/java/kotlin/Kotlinc.java new file mode 100644 index 000000000..261acc3d3 --- /dev/null +++ b/buildSrc/src/main/java/kotlin/Kotlinc.java @@ -0,0 +1,68 @@ +// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +package kotlin; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.gradle.api.Action; +import org.gradle.api.DefaultTask; +import org.gradle.api.UncheckedIOException; +import org.gradle.api.file.FileTree; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; +import org.gradle.process.ExecSpec; +import utils.Utils; + +/** + * Gradle task to compile Kotlin source files. + */ +public class Kotlinc extends DefaultTask { + + @InputFiles + private FileTree source; + + @OutputFile + private File destination; + + public FileTree getSource() { + return source; + } + + public void setSource(FileTree source) { + this.source = source; + } + + public File getDestination() { + return destination; + } + + public void setDestination(File destination) { + this.destination = destination; + } + + @TaskAction + public void compile() { + getProject().exec(new Action<ExecSpec>() { + @Override + public void execute(ExecSpec execSpec) { + try { + String kotlincExecName = Utils.toolsDir().equals("windows") ? "kotlinc.bat" : "kotlinc"; + Path kotlincExecPath = Paths + .get("third_party", "kotlin", "kotlinc", "bin", kotlincExecName); + execSpec.setExecutable(kotlincExecPath.toFile()); + execSpec.args("-include-runtime"); + execSpec.args("-nowarn"); + execSpec.args("-d", destination.getCanonicalPath()); + execSpec.args(source.getFiles()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + }); + } +} |