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
This commit is contained in:
Alexander Udalov
2014-07-22 17:16:37 +04:00
parent 125c5e2942
commit 87439b8e0b
14 changed files with 22 additions and 39 deletions
@@ -26,7 +26,6 @@ import org.jetbrains.jet.cli.js.K2JSCompiler
import java.io.File import java.io.File
import org.apache.tools.ant.BuildException import org.apache.tools.ant.BuildException
import org.jetbrains.jet.cli.common.ExitCode import org.jetbrains.jet.cli.common.ExitCode
import java.util.Arrays
/** /**
* Kotlin JavaScript compiler Ant task. * Kotlin JavaScript compiler Ant task.
@@ -76,7 +75,7 @@ public class Kotlin2JsCompilerTask : Task() {
val arguments = K2JSCompilerArguments() val arguments = K2JSCompilerArguments()
val sourcePaths = src ?: throw BuildException("\"src\" should be specified") 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") val outputFile = output ?: throw BuildException("\"output\" should be specified")
arguments.outputFile = outputFile.canonicalPath arguments.outputFile = outputFile.canonicalPath
@@ -87,7 +86,7 @@ public class Kotlin2JsCompilerTask : Task() {
arguments.main = main arguments.main = main
arguments.sourcemap = sourcemap arguments.sourcemap = sourcemap
log("Compiling [${arguments.sourceFiles?.makeString(",")}] => [${arguments.outputFile}]"); log("Compiling ${arguments.freeArgs} => [${arguments.outputFile}]");
val compiler = K2JSCompiler() val compiler = K2JSCompiler()
val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, arguments) val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, arguments)
@@ -21,16 +21,10 @@ import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
/**
* General convenient utilities.
*/
public final class Util { public final class Util {
private Util() { private Util() {
} }
/** /**
* {@code file.getCanonicalPath()} convenience wrapper. * {@code file.getCanonicalPath()} convenience wrapper.
* *
@@ -47,6 +41,7 @@ public final class Util {
} }
} }
@NotNull
public static String[] getPaths(String[] paths) { public static String[] getPaths(String[] paths) {
String[] result = new String[paths.length]; String[] result = new String[paths.length];
for (int i = 0; i < paths.length; i++) { for (int i = 0; i < paths.length; i++) {
@@ -35,10 +35,6 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
@ValueDescription("<path[,]>") @ValueDescription("<path[,]>")
public String[] libraryFiles; public String[] libraryFiles;
@Argument(value = "sourceFiles", description = "Source files or directories separated by commas")
@ValueDescription("<path[,]>")
public String[] sourceFiles;
@Argument(value = "sourcemap", description = "Generate SourceMap") @Argument(value = "sourcemap", description = "Generate SourceMap")
public boolean sourcemap; public boolean sourcemap;
@@ -76,13 +76,13 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
@NotNull MessageCollector messageCollector, @NotNull MessageCollector messageCollector,
@NotNull Disposable rootDisposable @NotNull Disposable rootDisposable
) { ) {
if (arguments.sourceFiles == null) { if (arguments.freeArgs.isEmpty()) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify sources location via -sourceFiles", NO_LOCATION); messageCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
return ExitCode.INTERNAL_ERROR; return ExitCode.INTERNAL_ERROR;
} }
CompilerConfiguration configuration = new CompilerConfiguration(); 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); JetCoreEnvironment environmentForJS = JetCoreEnvironment.createForProduction(rootDisposable, configuration);
Project project = environmentForJS.getProject(); Project project = environmentForJS.getProject();
@@ -50,9 +50,8 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
doAntTest(SUCCESSFUL, extraJavaArgs); doAntTest(SUCCESSFUL, extraJavaArgs);
String jar = getOutputFileByName(JVM_OUT_FILE).getAbsolutePath(); 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 { private void doJsAntTest() throws Exception {
@@ -107,20 +106,20 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
@Test @Test
public void javacCompiler() throws Exception { public void javacCompiler() throws Exception {
doJvmAntTest("-cp", getKotlinAntPath(), doJvmAntTest("-cp", getClassPathForAnt(),
"-Dkotlin.home", getCompilerLib().getAbsolutePath()); "-Dkotlin.home", getCompilerLib().getAbsolutePath());
} }
@Test @Test
public void externalAnnotations() throws Exception { public void externalAnnotations() throws Exception {
doJvmAntTest("-cp", getKotlinAntPath(), doJvmAntTest("-cp", getClassPathForAnt(),
"-Didea.sdk", getIdeaSdkHome(), "-Didea.sdk", getIdeaSdkHome(),
"-Dkotlin.home", getCompilerLib().getAbsolutePath()); "-Dkotlin.home", getCompilerLib().getAbsolutePath());
} }
@Test @Test
public void kotlinCompiler() throws Exception { public void kotlinCompiler() throws Exception {
doJvmAntTest("-cp", getKotlinAntPath(), doJvmAntTest("-cp", getClassPathForAnt(),
"-Didea.sdk", getIdeaSdkHome(), "-Didea.sdk", getIdeaSdkHome(),
"-Dkotlin.home", getCompilerLib().getAbsolutePath()); "-Dkotlin.home", getCompilerLib().getAbsolutePath());
} }
@@ -203,8 +202,8 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
return runJava(logName, ArrayUtil.toStringArray(strings)); return runJava(logName, ArrayUtil.toStringArray(strings));
} }
private static String getKotlinAntPath() { private static String getClassPathForAnt() {
return getCompilerLib() + File.separator + "kotlin-ant.jar"; return getCompilerLib() + File.separator + "kotlin-ant.jar" + File.pathSeparator + getKotlinRuntimePath();
} }
private static String getIdeaSdkHome() { private static String getIdeaSdkHome() {
@@ -2,7 +2,7 @@ OUT:
Buildfile: [TestData]/build.xml Buildfile: [TestData]/build.xml
build: 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 BUILD SUCCESSFUL
Total time: [time] Total time: [time]
-1
View File
@@ -2,7 +2,6 @@ Usage: kotlinc-js <options> <source files>
where possible options include: where possible options include:
-output <path> Output file path -output <path> Output file path
-libraryFiles <path[,]> Path to zipped library sources or kotlin files separated by commas -libraryFiles <path[,]> Path to zipped library sources or kotlin files separated by commas
-sourceFiles <path[,]> Source files or directories separated by commas
-sourcemap Generate SourceMap -sourcemap Generate SourceMap
-target <version> Generate JS files for specific ECMA version (only ECMA 5 is supported) -target <version> 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) -main {call,noCall} Whether a main function should be called; default 'call' (main function will be auto detected)
@@ -1,6 +1,5 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt $TESTDATA_DIR$/simple2js.kt
-output -output
$TEMP_DIR$/out.js $TEMP_DIR$/out.js
-outputPostfix -outputPostfix
not/existing/path not/existing/path
@@ -1,6 +1,5 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt $TESTDATA_DIR$/simple2js.kt
-output -output
$TEMP_DIR$/out.js $TEMP_DIR$/out.js
-outputPrefix -outputPrefix
not/existing/path not/existing/path
+1 -2
View File
@@ -1,4 +1,3 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt $TESTDATA_DIR$/simple2js.kt
-output -output
$TEMP_DIR$/out.js $TEMP_DIR$/out.js
@@ -1,6 +1,5 @@
-sourceFiles
$TESTDATA_DIR$/../warnings.kt $TESTDATA_DIR$/../warnings.kt
-suppress -suppress
WaRnInGs WaRnInGs
-output -output
$TEMP_DIR$/out.js $TEMP_DIR$/out.js
@@ -157,13 +157,12 @@ public class KotlinCompilerRunner {
) { ) {
setupCommonSettings(settings); setupCommonSettings(settings);
List<String> sourceFilePaths = ContainerUtil.map(sourceFiles, new Function<File, String>() { settings.freeArgs = ContainerUtil.map(sourceFiles, new Function<File, String>() {
@Override @Override
public String fun(File file) { public String fun(File file) {
return file.getPath(); return file.getPath();
} }
}); });
settings.sourceFiles = ArrayUtil.toStringArray(sourceFilePaths);
settings.outputFile = outputFile.getPath(); settings.outputFile = outputFile.getPath();
settings.libraryFiles = ArrayUtil.toStringArray(libraryFiles); settings.libraryFiles = ArrayUtil.toStringArray(libraryFiles);
} }
@@ -20,8 +20,8 @@ package org.jetbrains.k2js.test.semantics;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.ExitCode; 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.common.arguments.K2JSCompilerArguments;
import org.jetbrains.jet.cli.js.K2JSCompiler;
import org.jetbrains.k2js.config.EcmaVersion; import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.test.SingleFileTranslationTest; import org.jetbrains.k2js.test.SingleFileTranslationTest;
@@ -93,7 +93,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest {
K2JSCompiler compiler = new K2JSCompiler(); K2JSCompiler compiler = new K2JSCompiler();
K2JSCompilerArguments arguments = new K2JSCompilerArguments(); K2JSCompilerArguments arguments = new K2JSCompilerArguments();
arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version); arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
arguments.sourceFiles = files.toArray(new String[files.size()]); arguments.freeArgs = files;
arguments.verbose = true; arguments.verbose = true;
arguments.libraryFiles = new String[] {generatedJsDefinitionsDir}; arguments.libraryFiles = new String[] {generatedJsDefinitionsDir};
System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile);
@@ -102,7 +102,7 @@ public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest {
} }
} }
private void addAllSourceFiles(List<String> files, File dir) { private static void addAllSourceFiles(List<String> files, File dir) {
File[] children = dir.listFiles(); File[] children = dir.listFiles();
if (children != null && children.length > 0) { if (children != null && children.length > 0) {
for (File child : children) { for (File child : children) {
@@ -71,7 +71,7 @@ abstract class StdLibTestBase extends SingleFileTranslationTest {
K2JSCompiler compiler = new K2JSCompiler(); K2JSCompiler compiler = new K2JSCompiler();
K2JSCompilerArguments arguments = new K2JSCompilerArguments(); K2JSCompilerArguments arguments = new K2JSCompilerArguments();
arguments.outputFile = outputFilePath; arguments.outputFile = outputFilePath;
arguments.sourceFiles = ArrayUtil.toStringArray(files); arguments.freeArgs = files;
arguments.verbose = true; arguments.verbose = true;
arguments.libraryFiles = ArrayUtil.toStringArray(libFiles); arguments.libraryFiles = ArrayUtil.toStringArray(libFiles);
System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile); System.out.println("Compiling with version: " + version + " to: " + arguments.outputFile);