From 7b860eab368103bc4fda52a0137bc30b1c90ba91 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Wed, 21 Mar 2018 14:11:08 +0300 Subject: [PATCH] Merge kotlin-experimental into kotlin standard library (KT-23055 fixed) * kotlin-experimental.js has been already merged into kotlin.js * change library name to kotlin in kotlin-experimental.meta.js in order to produce correct require calls * concatenate kotlin-experimental.meta.js with kotlin.meta.js * suppress multiple module declaration warning for such use case --- .../KotlinJavaScriptProject/expected-output.txt | 2 -- .../expected-output.txt | 2 -- .../expected-output.txt | 2 -- .../expected-output.txt | 2 -- .../expected-output.txt | 2 -- .../expected-output.txt | 4 ---- .../org/jetbrains/kotlin/js/config/JsConfig.java | 11 +++++++++-- libraries/stdlib/js/build.gradle | 13 +++++++++++-- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/jps-plugin/testData/general/KotlinJavaScriptProject/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProject/expected-output.txt index 8c9f16fe97e..541f661545e 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProject/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProject/expected-output.txt @@ -4,7 +4,5 @@ kotlinProject/ kotlinProject.js kotlinProject.meta.js lib/ - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js \ No newline at end of file diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/expected-output.txt index c7d9de318a3..b0ae98fc0c7 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsLibrary/expected-output.txt @@ -11,8 +11,6 @@ kotlinProject/ file0.js jslib-example.js jslib-example.meta.js - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js res0.js diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsStdlib/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsStdlib/expected-output.txt index 8c9f16fe97e..541f661545e 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsStdlib/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithDirectoryAsStdlib/expected-output.txt @@ -4,7 +4,5 @@ kotlinProject/ kotlinProject.js kotlinProject.meta.js lib/ - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js \ No newline at end of file diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibrary/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibrary/expected-output.txt index c7d9de318a3..b0ae98fc0c7 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibrary/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibrary/expected-output.txt @@ -11,8 +11,6 @@ kotlinProject/ file0.js jslib-example.js jslib-example.meta.js - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js res0.js diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibraryCustomOutputDir/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibraryCustomOutputDir/expected-output.txt index 9fad8b490fd..f1738e23acb 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibraryCustomOutputDir/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithLibraryCustomOutputDir/expected-output.txt @@ -7,8 +7,6 @@ kotlinProject/ file0.js jslib-example.js jslib-example.meta.js - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js res0.js diff --git a/jps-plugin/testData/general/KotlinJavaScriptProjectWithTwoModules/expected-output.txt b/jps-plugin/testData/general/KotlinJavaScriptProjectWithTwoModules/expected-output.txt index 132d5fc6e80..a48c2449988 100644 --- a/jps-plugin/testData/general/KotlinJavaScriptProjectWithTwoModules/expected-output.txt +++ b/jps-plugin/testData/general/KotlinJavaScriptProjectWithTwoModules/expected-output.txt @@ -4,14 +4,10 @@ kotlinProject/ kotlinProject.js kotlinProject.meta.js lib/ - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js module2/ lib/ - kotlin-experimental.js - kotlin-experimental.meta.js kotlin.js kotlin.meta.js module2/ diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java index db20061a502..423a3359881 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/config/JsConfig.java @@ -202,6 +202,8 @@ public class JsConfig { continue; } + Set moduleNames = new LinkedHashSet<>(); + for (KotlinJavascriptMetadata metadata : metadataList) { if (!metadata.getVersion().isCompatible() && !skipMetadataVersionCheck) { report.error("File '" + path + "' was compiled with an incompatible version of Kotlin. " + @@ -209,8 +211,13 @@ public class JsConfig { ", expected version is " + JsMetadataVersion.INSTANCE); return true; } - if (!modules.add(metadata.getModuleName())) { - report.warning("Module \"" + metadata.getModuleName() + "\" is defined in more than one file"); + + moduleNames.add(metadata.getModuleName()); + } + + for (String moduleName : moduleNames) { + if (!modules.add(moduleName)) { + report.warning("Module \"" + moduleName + "\" is defined in more than one file"); } } diff --git a/libraries/stdlib/js/build.gradle b/libraries/stdlib/js/build.gradle index 26faaba2fb2..a604c943fc7 100644 --- a/libraries/stdlib/js/build.gradle +++ b/libraries/stdlib/js/build.gradle @@ -17,11 +17,13 @@ def commonSrcDir = "${buildDir}/common-sources" def commonTestSrcDir = "${buildDir}/common-test-sources" def builtinsDir = "${rootDir}/core/builtins" def experimentalSrcDir = "${rootDir}/libraries/stdlib/experimental" +def experimentalJsModuleName = 'kotlin-experimental' def jsSrcGeneratedDir = "${rootDir}/js/js.libraries/src/core/generated" // to be removed soon def jsSrcDir = "src" def jsTestSrcDir = "test" def jsSrcJsDir = "${jsSrcDir}/js" def jsOutputFile = "${buildDir}/classes/kotlin.js" +def jsOutputMetaFile = "${buildDir}/classes/kotlin.meta.js" def kotlinTestJsOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/main/kotlin-test.js" @@ -147,7 +149,7 @@ compileExperimentalKotlin2Js { kotlinOptions { languageVersion = "1.3" apiVersion = "1.3" - outputFile = "${buildDir}/classes/main/kotlin-experimental.js" + outputFile = "${buildDir}/classes/experimental/${experimentalJsModuleName}.js" sourceMap = true sourceMapPrefix = "./" freeCompilerArgs += ["-source-map-base-dirs", [experimentalSrcDir].join(File.pathSeparator)] @@ -215,7 +217,7 @@ task compileJs(type: JavaExec) { if (prefixToRemove != null) sourcePath.substring(prefixToRemove.length()) else sourcePath } - def sourceMapSourcesBaseDirs = [jsSrcDir, jsSrcJsDir, jsSrcGeneratedDir, builtinsSrcDir, commonSrcDir, projectDir] + def sourceMapSourcesBaseDirs = [jsSrcDir, jsSrcJsDir, jsSrcGeneratedDir, builtinsSrcDir, commonSrcDir, projectDir, experimentalSrcDir] sourceMap.sourcesContent = sourceMap.sources.collect { sourceName -> def text = sourceMapSourcesBaseDirs.collect { file("$it/$sourceName") }.find { it.exists() }?.text @@ -224,6 +226,10 @@ task compileJs(type: JavaExec) { } sourceMapFile.text = groovy.json.JsonOutput.toJson(sourceMap) + + file(jsOutputMetaFile).text = file(compileKotlin2Js.outputFile.path.replaceAll('\\.js$', '.meta.js')).text + + file(compileExperimentalKotlin2Js.outputFile.path.replaceAll('\\.js$', '.meta.js')).text + .replaceFirst(experimentalJsModuleName, 'kotlin') } } @@ -248,8 +254,11 @@ task mergedJar(type: Jar, dependsOn: classes) { includeEmptyDirs false duplicatesStrategy DuplicatesStrategy.EXCLUDE from jsOutputFile + from jsOutputMetaFile from "${jsOutputFile}.map" from sourceSets.main.output + from sourceSets.experimental.output + exclude "${experimentalJsModuleName}.*" } task sourcesJar(type: Jar, dependsOn: classes) {