From 87439b8e0b60c298fd63eeb0f994268aa3a66668 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 22 Jul 2014 17:16:37 +0400 Subject: [PATCH] Drop "-sourceFiles" in kotlinc-js Use free arguments instead, as is done in kotlinc-jvm and all sensible compilers everywhere Also fix some cases of AntTaskTest to be able to run them locally --- .../jet/buildtools/ant/Kotlin2JsCompilerTask.kt | 5 ++--- .../src/org/jetbrains/jet/buildtools/core/Util.java | 7 +------ .../cli/common/arguments/K2JSCompilerArguments.java | 4 ---- .../src/org/jetbrains/jet/cli/js/K2JSCompiler.java | 6 +++--- .../src/org/jetbrains/kotlin/AntTaskTest.java | 13 ++++++------- .../testData/k2jsManySources/build.log.expected | 2 +- compiler/testData/cli/js/jsHelp.out | 1 - .../testData/cli/js/outputPostfixFileNotFound.args | 3 +-- .../testData/cli/js/outputPrefixFileNotFound.args | 3 +-- compiler/testData/cli/js/simple2js.args | 3 +-- compiler/testData/cli/js/suppressAllWarningsJS.args | 3 +-- .../jet/compiler/runner/KotlinCompilerRunner.java | 3 +-- .../semantics/CompileMavenGeneratedJSLibrary.java | 6 +++--- .../k2js/test/semantics/StdLibTestBase.java | 2 +- 14 files changed, 22 insertions(+), 39 deletions(-) diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt index 9dd9b96da24..e06db037c71 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt @@ -26,7 +26,6 @@ import org.jetbrains.jet.cli.js.K2JSCompiler import java.io.File import org.apache.tools.ant.BuildException import org.jetbrains.jet.cli.common.ExitCode -import java.util.Arrays /** * Kotlin JavaScript compiler Ant task. @@ -76,7 +75,7 @@ public class Kotlin2JsCompilerTask : Task() { val arguments = K2JSCompilerArguments() val sourcePaths = src ?: throw BuildException("\"src\" should be specified") - arguments.sourceFiles = Util.getPaths(sourcePaths.list()) + arguments.freeArgs = Util.getPaths(sourcePaths.list()).toList() val outputFile = output ?: throw BuildException("\"output\" should be specified") arguments.outputFile = outputFile.canonicalPath @@ -87,7 +86,7 @@ public class Kotlin2JsCompilerTask : Task() { arguments.main = main arguments.sourcemap = sourcemap - log("Compiling [${arguments.sourceFiles?.makeString(",")}] => [${arguments.outputFile}]"); + log("Compiling ${arguments.freeArgs} => [${arguments.outputFile}]"); val compiler = K2JSCompiler() val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, arguments) diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java index 79a35190372..2eb86c342ae 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/Util.java @@ -21,16 +21,10 @@ import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; - -/** - * General convenient utilities. - */ public final class Util { - private Util() { } - /** * {@code file.getCanonicalPath()} convenience wrapper. * @@ -47,6 +41,7 @@ public final class Util { } } + @NotNull public static String[] getPaths(String[] paths) { String[] result = new String[paths.length]; for (int i = 0; i < paths.length; i++) { diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java index f7a01cecdbd..b4f44dcf3d1 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java @@ -35,10 +35,6 @@ public class K2JSCompilerArguments extends CommonCompilerArguments { @ValueDescription("") public String[] libraryFiles; - @Argument(value = "sourceFiles", description = "Source files or directories separated by commas") - @ValueDescription("") - public String[] sourceFiles; - @Argument(value = "sourcemap", description = "Generate SourceMap") public boolean sourcemap; diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java index c0bf0bb0e31..a6d0143126c 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -76,13 +76,13 @@ public class K2JSCompiler extends CLICompiler { @NotNull MessageCollector messageCollector, @NotNull Disposable rootDisposable ) { - if (arguments.sourceFiles == null) { - messageCollector.report(CompilerMessageSeverity.ERROR, "Specify sources location via -sourceFiles", NO_LOCATION); + if (arguments.freeArgs.isEmpty()) { + messageCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION); return ExitCode.INTERNAL_ERROR; } CompilerConfiguration configuration = new CompilerConfiguration(); - configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(arguments.sourceFiles)); + configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, arguments.freeArgs); JetCoreEnvironment environmentForJS = JetCoreEnvironment.createForProduction(rootDisposable, configuration); Project project = environmentForJS.getProject(); diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java index c2af45ea708..d1756ff0f3e 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java @@ -50,9 +50,8 @@ public class AntTaskTest extends KotlinIntegrationTestBase { doAntTest(SUCCESSFUL, extraJavaArgs); String jar = getOutputFileByName(JVM_OUT_FILE).getAbsolutePath(); - String runtime = getKotlinRuntimePath(); - runJava("hello.run", "-cp", jar + File.pathSeparator + runtime, "hello.HelloPackage"); + runJava("hello.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "hello.HelloPackage"); } private void doJsAntTest() throws Exception { @@ -107,20 +106,20 @@ public class AntTaskTest extends KotlinIntegrationTestBase { @Test public void javacCompiler() throws Exception { - doJvmAntTest("-cp", getKotlinAntPath(), + doJvmAntTest("-cp", getClassPathForAnt(), "-Dkotlin.home", getCompilerLib().getAbsolutePath()); } @Test public void externalAnnotations() throws Exception { - doJvmAntTest("-cp", getKotlinAntPath(), + doJvmAntTest("-cp", getClassPathForAnt(), "-Didea.sdk", getIdeaSdkHome(), "-Dkotlin.home", getCompilerLib().getAbsolutePath()); } @Test public void kotlinCompiler() throws Exception { - doJvmAntTest("-cp", getKotlinAntPath(), + doJvmAntTest("-cp", getClassPathForAnt(), "-Didea.sdk", getIdeaSdkHome(), "-Dkotlin.home", getCompilerLib().getAbsolutePath()); } @@ -203,8 +202,8 @@ public class AntTaskTest extends KotlinIntegrationTestBase { return runJava(logName, ArrayUtil.toStringArray(strings)); } - private static String getKotlinAntPath() { - return getCompilerLib() + File.separator + "kotlin-ant.jar"; + private static String getClassPathForAnt() { + return getCompilerLib() + File.separator + "kotlin-ant.jar" + File.pathSeparator + getKotlinRuntimePath(); } private static String getIdeaSdkHome() { diff --git a/compiler/integration-tests/testData/k2jsManySources/build.log.expected b/compiler/integration-tests/testData/k2jsManySources/build.log.expected index cd08097efff..3f1c2bc5850 100644 --- a/compiler/integration-tests/testData/k2jsManySources/build.log.expected +++ b/compiler/integration-tests/testData/k2jsManySources/build.log.expected @@ -2,7 +2,7 @@ OUT: Buildfile: [TestData]/build.xml build: -[kotlin2js] Compiling [[TestData]/root1,[TestData]/bar.kt,[TestData]/root2/Foo.kt] => [[Temp]/out.js] +[kotlin2js] Compiling [[TestData]/root1, [TestData]/bar.kt, [TestData]/root2/Foo.kt] => [[Temp]/out.js] BUILD SUCCESSFUL Total time: [time] diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index c7779a9f2f9..3a8d8e3b134 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -2,7 +2,6 @@ Usage: kotlinc-js where possible options include: -output Output file path -libraryFiles Path to zipped library sources or kotlin files separated by commas - -sourceFiles Source files or directories separated by commas -sourcemap Generate SourceMap -target Generate JS files for specific ECMA version (only ECMA 5 is supported) -main {call,noCall} Whether a main function should be called; default 'call' (main function will be auto detected) diff --git a/compiler/testData/cli/js/outputPostfixFileNotFound.args b/compiler/testData/cli/js/outputPostfixFileNotFound.args index f9e5f026e0b..2ac3c1e3b42 100644 --- a/compiler/testData/cli/js/outputPostfixFileNotFound.args +++ b/compiler/testData/cli/js/outputPostfixFileNotFound.args @@ -1,6 +1,5 @@ --sourceFiles $TESTDATA_DIR$/simple2js.kt -output $TEMP_DIR$/out.js -outputPostfix -not/existing/path \ No newline at end of file +not/existing/path diff --git a/compiler/testData/cli/js/outputPrefixFileNotFound.args b/compiler/testData/cli/js/outputPrefixFileNotFound.args index 1a7231917e8..dab81c7e94f 100644 --- a/compiler/testData/cli/js/outputPrefixFileNotFound.args +++ b/compiler/testData/cli/js/outputPrefixFileNotFound.args @@ -1,6 +1,5 @@ --sourceFiles $TESTDATA_DIR$/simple2js.kt -output $TEMP_DIR$/out.js -outputPrefix -not/existing/path \ No newline at end of file +not/existing/path diff --git a/compiler/testData/cli/js/simple2js.args b/compiler/testData/cli/js/simple2js.args index 40f1df7ca8a..d99fe90b79c 100644 --- a/compiler/testData/cli/js/simple2js.args +++ b/compiler/testData/cli/js/simple2js.args @@ -1,4 +1,3 @@ --sourceFiles $TESTDATA_DIR$/simple2js.kt -output -$TEMP_DIR$/out.js \ No newline at end of file +$TEMP_DIR$/out.js diff --git a/compiler/testData/cli/js/suppressAllWarningsJS.args b/compiler/testData/cli/js/suppressAllWarningsJS.args index 73829cf76b0..2e51d88027b 100644 --- a/compiler/testData/cli/js/suppressAllWarningsJS.args +++ b/compiler/testData/cli/js/suppressAllWarningsJS.args @@ -1,6 +1,5 @@ --sourceFiles $TESTDATA_DIR$/../warnings.kt -suppress WaRnInGs -output -$TEMP_DIR$/out.js \ No newline at end of file +$TEMP_DIR$/out.js diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java index acc439c8b84..3d9cadb9635 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java @@ -157,13 +157,12 @@ public class KotlinCompilerRunner { ) { setupCommonSettings(settings); - List sourceFilePaths = ContainerUtil.map(sourceFiles, new Function() { + settings.freeArgs = ContainerUtil.map(sourceFiles, new Function() { @Override public String fun(File file) { return file.getPath(); } }); - settings.sourceFiles = ArrayUtil.toStringArray(sourceFilePaths); settings.outputFile = outputFile.getPath(); settings.libraryFiles = ArrayUtil.toStringArray(libraryFiles); } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java index dde5815d3e2..899bfde779e 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/CompileMavenGeneratedJSLibrary.java @@ -20,8 +20,8 @@ package org.jetbrains.k2js.test.semantics; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.ExitCode; -import org.jetbrains.jet.cli.js.K2JSCompiler; import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments; +import org.jetbrains.jet.cli.js.K2JSCompiler; import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.test.SingleFileTranslationTest; @@ -93,7 +93,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { K2JSCompiler compiler = new K2JSCompiler(); K2JSCompilerArguments arguments = new K2JSCompilerArguments(); arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version); - arguments.sourceFiles = files.toArray(new String[files.size()]); + arguments.freeArgs = files; arguments.verbose = true; arguments.libraryFiles = new String[] {generatedJsDefinitionsDir}; System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); @@ -102,7 +102,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest { } } - private void addAllSourceFiles(List files, File dir) { + private static void addAllSourceFiles(List files, File dir) { File[] children = dir.listFiles(); if (children != null && children.length > 0) { for (File child : children) { diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java index c998e629228..896f5959ac9 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTestBase.java @@ -71,7 +71,7 @@ abstract class StdLibTestBase extends SingleFileTranslationTest { K2JSCompiler compiler = new K2JSCompiler(); K2JSCompilerArguments arguments = new K2JSCompilerArguments(); arguments.outputFile = outputFilePath; - arguments.sourceFiles = ArrayUtil.toStringArray(files); + arguments.freeArgs = files; arguments.verbose = true; arguments.libraryFiles = ArrayUtil.toStringArray(libFiles); System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile);