diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt index c19ac8710f5..f43e6e5e7b9 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsTask.kt @@ -18,12 +18,8 @@ package org.jetbrains.jet.buildtools.ant import org.apache.tools.ant.types.Path import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments -import org.jetbrains.jet.cli.common.messages.MessageCollectorPlainTextToStream 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 org.jetbrains.jet.config.Services /** * Kotlin JavaScript compiler Ant task. @@ -58,6 +54,13 @@ public class Kotlin2JsTask : KotlinCompilerBaseTask() { override fun fillSpecificArguments() { arguments.outputFile = getPath(output!!) + arguments.noStdlib = noStdlib + + // TODO: write test + library?.let { + arguments.libraryFiles = it.list().map { getPath(File(it)) }.copyToArray() + } + arguments.outputPrefix = outputPrefix?.canonicalPath arguments.outputPostfix = outputPostfix?.canonicalPath diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt index dbe9ac4c735..3e9abf7e7ee 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JvmTask.kt @@ -39,7 +39,6 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() override val arguments = K2JVMCompilerArguments() override val compiler = K2JVMCompiler() - public var noStdlib: Boolean = false public var externalAnnotations: Path? = null public var includeRuntime: Boolean = true diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt index d84fa58ed81..17afd5695eb 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/KotlinCompilerBaseTask.kt @@ -61,6 +61,8 @@ public abstract class KotlinCompilerBaseTask : Task public var verbose: Boolean = false public var printVersion: Boolean = false + public var noStdlib: Boolean = false + public val additionalArguments: MutableList = arrayListOf() public fun createSrc(): Path { diff --git a/build.xml b/build.xml index 64791c48c33..731d283ff24 100644 --- a/build.xml +++ b/build.xml @@ -221,7 +221,7 @@ - + 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 2a27693489e..2a3f817b4da 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 @@ -28,6 +28,9 @@ public class K2JSCompilerArguments extends CommonCompilerArguments { @ValueDescription("") public String outputFile; + @Argument(value = "no-stdlib", description = "Don't use bundled Kotlin stdlib") + public boolean noStdlib; + @Argument(value = "library-files", description = "Path to zipped library sources or kotlin files separated by commas") @ValueDescription("") public String[] libraryFiles; 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 7186730e057..bc080aa86c9 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.util.Consumer; import com.intellij.util.Function; +import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import kotlin.Function0; import org.jetbrains.annotations.NotNull; @@ -51,12 +52,12 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.DiagnosticsWithSuppression; import org.jetbrains.k2js.analyze.SuppressUnusedParameterForJsNative; import org.jetbrains.k2js.analyze.SuppressWarningsFromExternalModules; +import org.jetbrains.jet.utils.PathUtil; import org.jetbrains.k2js.analyze.TopDownAnalyzerFacadeForJS; import org.jetbrains.k2js.config.*; import org.jetbrains.k2js.facade.MainCallParameters; import java.io.File; -import java.util.Arrays; import java.util.List; import static org.jetbrains.jet.cli.common.ExitCode.COMPILATION_ERROR; @@ -211,8 +212,17 @@ public class K2JSCompiler extends CLICompiler { String moduleId = FileUtil.getNameWithoutExtension(new File(arguments.outputFile)); boolean inlineEnabled = !arguments.noInline; + List libraryFiles = new SmartList(); + if (!arguments.noStdlib) { + libraryFiles.add(0, PathUtil.getKotlinPathsForCompiler().getJsLibJarPath().getAbsolutePath()); + } + if (arguments.libraryFiles != null) { - return new LibrarySourcesConfig(project, moduleId, Arrays.asList(arguments.libraryFiles), ecmaVersion, arguments.sourceMap, inlineEnabled); + ContainerUtil.addAllNotNull(libraryFiles, arguments.libraryFiles); + } + + if (!libraryFiles.isEmpty()) { + return new LibrarySourcesConfig(project, moduleId, libraryFiles, ecmaVersion, arguments.sourceMap, inlineEnabled); } else { // lets discover the JS library definitions on the classpath diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java index 40a948170cd..66514c26de0 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskJsTest.java @@ -86,6 +86,11 @@ public class AntTaskJsTest extends AntTaskBaseTest { doJsAntTest(); } + @Test + public void simpleWithStdlib() throws Exception { + doJsAntTest(); + } + @Test public void simpleWithMainFQArgs() throws Exception { doJsAntTest(); diff --git a/compiler/integration-tests/testData/ant/js/additionalArguments/build.xml b/compiler/integration-tests/testData/ant/js/additionalArguments/build.xml index 92c46ef3e30..03b0b4f601b 100644 --- a/compiler/integration-tests/testData/ant/js/additionalArguments/build.xml +++ b/compiler/integration-tests/testData/ant/js/additionalArguments/build.xml @@ -2,7 +2,7 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/bothPrefixAndPostfix/build.xml b/compiler/integration-tests/testData/ant/js/bothPrefixAndPostfix/build.xml index f4fcf02f781..af46eb7631a 100644 --- a/compiler/integration-tests/testData/ant/js/bothPrefixAndPostfix/build.xml +++ b/compiler/integration-tests/testData/ant/js/bothPrefixAndPostfix/build.xml @@ -2,6 +2,10 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/manySources/build.xml b/compiler/integration-tests/testData/ant/js/manySources/build.xml index 6abaf7716c5..e2d9876848f 100644 --- a/compiler/integration-tests/testData/ant/js/manySources/build.xml +++ b/compiler/integration-tests/testData/ant/js/manySources/build.xml @@ -2,7 +2,7 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/outputPostfix/build.xml b/compiler/integration-tests/testData/ant/js/outputPostfix/build.xml index 76cd4eb8c8b..faec7db98a4 100644 --- a/compiler/integration-tests/testData/ant/js/outputPostfix/build.xml +++ b/compiler/integration-tests/testData/ant/js/outputPostfix/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/outputPrefix/build.xml b/compiler/integration-tests/testData/ant/js/outputPrefix/build.xml index 522ef33b8fa..701dcab9dbc 100644 --- a/compiler/integration-tests/testData/ant/js/outputPrefix/build.xml +++ b/compiler/integration-tests/testData/ant/js/outputPrefix/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/simple/build.xml b/compiler/integration-tests/testData/ant/js/simple/build.xml index ee620d63b7c..4f39f5e0ce7 100644 --- a/compiler/integration-tests/testData/ant/js/simple/build.xml +++ b/compiler/integration-tests/testData/ant/js/simple/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/simpleWithMain/build.xml b/compiler/integration-tests/testData/ant/js/simpleWithMain/build.xml index a80ea4410f9..a005566494b 100644 --- a/compiler/integration-tests/testData/ant/js/simpleWithMain/build.xml +++ b/compiler/integration-tests/testData/ant/js/simpleWithMain/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/simpleWithMainFQArgs/build.xml b/compiler/integration-tests/testData/ant/js/simpleWithMainFQArgs/build.xml index a80ea4410f9..dbadf1da772 100644 --- a/compiler/integration-tests/testData/ant/js/simpleWithMainFQArgs/build.xml +++ b/compiler/integration-tests/testData/ant/js/simpleWithMainFQArgs/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.log.expected b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.log.expected new file mode 100644 index 00000000000..438f56679ca --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.log.expected @@ -0,0 +1,10 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: +[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js] + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.xml b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.xml new file mode 100644 index 00000000000..a80ea4410f9 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/testData/ant/js/simpleWithStdlib/root1/foo.kt b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/root1/foo.kt new file mode 100644 index 00000000000..9c26449e6f4 --- /dev/null +++ b/compiler/integration-tests/testData/ant/js/simpleWithStdlib/root1/foo.kt @@ -0,0 +1,12 @@ +package foo + +var ok = "FAIL" + +val hello = Pair("Hello", "World") + +fun main(args: Array) { + ok = "OK" + println(hello.first + " " + hello.second) +} + +fun box(): String = ok diff --git a/compiler/integration-tests/testData/ant/js/simpleWithVarargMain/build.xml b/compiler/integration-tests/testData/ant/js/simpleWithVarargMain/build.xml index a80ea4410f9..dbadf1da772 100644 --- a/compiler/integration-tests/testData/ant/js/simpleWithVarargMain/build.xml +++ b/compiler/integration-tests/testData/ant/js/simpleWithVarargMain/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/sourcemap/build.xml b/compiler/integration-tests/testData/ant/js/sourcemap/build.xml index d677cbbee62..25eb0ecc0f4 100644 --- a/compiler/integration-tests/testData/ant/js/sourcemap/build.xml +++ b/compiler/integration-tests/testData/ant/js/sourcemap/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/verbose/build.xml b/compiler/integration-tests/testData/ant/js/verbose/build.xml index c6de721f6bc..13b6dba1188 100644 --- a/compiler/integration-tests/testData/ant/js/verbose/build.xml +++ b/compiler/integration-tests/testData/ant/js/verbose/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/integration-tests/testData/ant/js/version/build.xml b/compiler/integration-tests/testData/ant/js/version/build.xml index 09fa5329255..9313e6cb7ec 100644 --- a/compiler/integration-tests/testData/ant/js/version/build.xml +++ b/compiler/integration-tests/testData/ant/js/version/build.xml @@ -2,6 +2,6 @@ - + diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index 01fea73ad76..c655e68cf30 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -1,6 +1,7 @@ Usage: kotlinc-js where possible options include: -output Output file path + -no-stdlib Don't use bundled Kotlin stdlib -library-files Path to zipped library sources or kotlin files separated by commas -source-map Generate source map -target Generate JS files for specific ECMA version (only ECMA 5 is supported) diff --git a/compiler/testData/cli/js/outputPostfixFileNotFound.args b/compiler/testData/cli/js/outputPostfixFileNotFound.args index cab465cb577..0da693dc816 100644 --- a/compiler/testData/cli/js/outputPostfixFileNotFound.args +++ b/compiler/testData/cli/js/outputPostfixFileNotFound.args @@ -1,4 +1,5 @@ $TESTDATA_DIR$/simple2js.kt +-no-stdlib -output $TEMP_DIR$/out.js -output-postfix diff --git a/compiler/testData/cli/js/outputPrefixFileNotFound.args b/compiler/testData/cli/js/outputPrefixFileNotFound.args index 4e7e0c86d01..3042c1c5b18 100644 --- a/compiler/testData/cli/js/outputPrefixFileNotFound.args +++ b/compiler/testData/cli/js/outputPrefixFileNotFound.args @@ -1,4 +1,5 @@ $TESTDATA_DIR$/simple2js.kt +-no-stdlib -output $TEMP_DIR$/out.js -output-prefix diff --git a/compiler/testData/cli/js/simple2js.args b/compiler/testData/cli/js/simple2js.args index d99fe90b79c..0d7e52c32b5 100644 --- a/compiler/testData/cli/js/simple2js.args +++ b/compiler/testData/cli/js/simple2js.args @@ -1,3 +1,4 @@ $TESTDATA_DIR$/simple2js.kt +-no-stdlib -output $TEMP_DIR$/out.js diff --git a/compiler/testData/cli/js/suppressAllWarningsJS.args b/compiler/testData/cli/js/suppressAllWarningsJS.args index b8ca87aa49f..ccf1d4754d3 100644 --- a/compiler/testData/cli/js/suppressAllWarningsJS.args +++ b/compiler/testData/cli/js/suppressAllWarningsJS.args @@ -1,4 +1,5 @@ $TESTDATA_DIR$/../warnings.kt +-no-stdlib -nowarn -output $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 842288685e1..ec9eef259fa 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 @@ -143,6 +143,7 @@ public class KotlinCompilerRunner { List libraryFiles, K2JSCompilerArguments settings ) { + settings.noStdlib = true; settings.freeArgs = ContainerUtil.map(sourceFiles, new Function() { @Override public String fun(File file) { diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java index 373fa9ddfec..4fc1bec6f4e 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java @@ -155,6 +155,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase