From d475401108d988c8630f94aedd8bd292b6204853 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 5 Jun 2015 16:17:51 +0300 Subject: [PATCH] Ant task: don't pass kotlin-runtime.jar to javac on "-no-stdlib" --- .../kotlin/ant/KotlinCompilerAdapter.java | 13 ++++++++++-- .../ant/jvm/noStdlibForJavac/J.java | 5 +++++ .../jvm/noStdlibForJavac/build.log.expected | 21 +++++++++++++++++++ .../ant/jvm/noStdlibForJavac/build.xml | 12 +++++++++++ .../integration/AntTaskTestGenerated.java | 6 ++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/integration/ant/jvm/noStdlibForJavac/J.java create mode 100644 compiler/testData/integration/ant/jvm/noStdlibForJavac/build.log.expected create mode 100644 compiler/testData/integration/ant/jvm/noStdlibForJavac/build.xml diff --git a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java index b07931fa5cc..c53558ce0f8 100644 --- a/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java +++ b/ant/src/org/jetbrains/kotlin/ant/KotlinCompilerAdapter.java @@ -98,12 +98,21 @@ public class KotlinCompilerAdapter extends Javac13 { // Javac13#execute passes everything in compileList to javac, which doesn't recognize .kt files compileList = filterOutKotlinSources(compileList); + addRuntimeToJavacClasspath(kotlinc); + + return compileList.length == 0 || super.execute(); + } + + private void addRuntimeToJavacClasspath(@NotNull Kotlin2JvmTask kotlinc) { + for (String arg : kotlinc.getArgs()) { + // If "-no-stdlib" was specified explicitly, probably the user also wanted the javac classpath to not have it + if ("-no-stdlib".equals(arg)) return; + } + if (compileClasspath == null) { compileClasspath = new Path(getProject()); } compileClasspath.add(new Path(getProject(), KotlinAntTaskUtil.INSTANCE$.getRuntimeJar().getAbsolutePath())); - - return compileList.length == 0 || super.execute(); } private void checkAntVersion() { diff --git a/compiler/testData/integration/ant/jvm/noStdlibForJavac/J.java b/compiler/testData/integration/ant/jvm/noStdlibForJavac/J.java new file mode 100644 index 00000000000..e14525bb20b --- /dev/null +++ b/compiler/testData/integration/ant/jvm/noStdlibForJavac/J.java @@ -0,0 +1,5 @@ +package test; + +import kotlin.Unit; + +public class J {} diff --git a/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.log.expected b/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.log.expected new file mode 100644 index 00000000000..b482a8f7883 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.log.expected @@ -0,0 +1,21 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [mkdir] Created dir: [Temp]/classes + [javac] Compiling 1 source file to [Temp]/classes + [javac] Compiling [[TestData]] => [[Temp]/classes] + [javac] Running javac... + [javac] [TestData]/J.java:3: package kotlin does not exist + [javac] import kotlin.Unit; + [javac] ^ + [javac] 1 error + +ERR: + +BUILD FAILED +[TestData]/build.xml:6: Compile failed; see the compiler error output for details. + +Total time: [time] + +Return code: 1 diff --git a/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.xml b/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.xml new file mode 100644 index 00000000000..81496fdf059 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/noStdlibForJavac/build.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java index 97f00ca2681..68a208950ea 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java @@ -59,6 +59,12 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest { doTest(fileName); } + @TestMetadata("noStdlibForJavac") + public void testNoStdlibForJavac() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/noStdlibForJavac/"); + doTest(fileName); + } + @TestMetadata("suppressWarnings") public void testSuppressWarnings() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/suppressWarnings/");