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:
@@ -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)
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
-4
@@ -35,10 +35,6 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("<path[,]>")
|
||||
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")
|
||||
public boolean sourcemap;
|
||||
|
||||
|
||||
@@ -76,13 +76,13 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
@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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -2,7 +2,6 @@ Usage: kotlinc-js <options> <source files>
|
||||
where possible options include:
|
||||
-output <path> Output file path
|
||||
-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
|
||||
-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)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
-sourceFiles
|
||||
$TESTDATA_DIR$/simple2js.kt
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
-outputPostfix
|
||||
not/existing/path
|
||||
not/existing/path
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
-sourceFiles
|
||||
$TESTDATA_DIR$/simple2js.kt
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
-outputPrefix
|
||||
not/existing/path
|
||||
not/existing/path
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
-sourceFiles
|
||||
$TESTDATA_DIR$/simple2js.kt
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
$TEMP_DIR$/out.js
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
-sourceFiles
|
||||
$TESTDATA_DIR$/../warnings.kt
|
||||
-suppress
|
||||
WaRnInGs
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
$TEMP_DIR$/out.js
|
||||
|
||||
@@ -157,13 +157,12 @@ public class KotlinCompilerRunner {
|
||||
) {
|
||||
setupCommonSettings(settings);
|
||||
|
||||
List<String> sourceFilePaths = ContainerUtil.map(sourceFiles, new Function<File, String>() {
|
||||
settings.freeArgs = ContainerUtil.map(sourceFiles, new Function<File, String>() {
|
||||
@Override
|
||||
public String fun(File file) {
|
||||
return file.getPath();
|
||||
}
|
||||
});
|
||||
settings.sourceFiles = ArrayUtil.toStringArray(sourceFilePaths);
|
||||
settings.outputFile = outputFile.getPath();
|
||||
settings.libraryFiles = ArrayUtil.toStringArray(libraryFiles);
|
||||
}
|
||||
|
||||
+3
-3
@@ -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<String> files, File dir) {
|
||||
private static void addAllSourceFiles(List<String> files, File dir) {
|
||||
File[] children = dir.listFiles();
|
||||
if (children != null && children.length > 0) {
|
||||
for (File child : children) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user