[Gradle, JS] IR by default and report warnings for using legacy compiler

- just legacy - report warning about deprecation
- both - report warning about deprecation of legacy
- no compiler explicitly chosen - error about explicit setting compiler

warn from cli legacy compiler

nowarn flag - kotlin.js.compiler.nowarn

KT-42326
KT-53074
This commit is contained in:
Ilya Goncharov
2022-09-16 09:48:41 +00:00
committed by Space
parent b53d6d0d7e
commit bf8681296b
101 changed files with 327 additions and 245 deletions
@@ -265,6 +265,12 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xwasm-enable-asserts", description = "Turn on asserts")
var wasmEnableAsserts: Boolean by FreezableVar(false)
@Argument(
value = "-Xlegacy-deprecated-no-warn",
description = "Disable warnings of deprecation of legacy compiler"
)
var legacyDeprecatedNoWarn: Boolean by FreezableVar(false)
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
return super.configureAnalysisFlags(collector, languageVersion).also {
it[allowFullyQualifiedNameInKClass] = wasm && wasmKClassFqn //Only enabled WASM BE supports this flag
@@ -186,6 +186,10 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
return exitCode;
}
if (!arguments.getLegacyDeprecatedNoWarn()) {
messageCollector.report(STRONG_WARNING, "Legacy compiler is deprecated. Please migrate onto IR.", null);
}
if (arguments.getFreeArgs().isEmpty() && (!incrementalCompilationIsEnabledForJs(arguments))) {
if (arguments.getVersion()) {
return OK;
+1
View File
@@ -1,4 +1,5 @@
compiler/testData/integration/ant/js/simpleWithoutStdlibAndFolderAsAnotherLib/jslib-example/LibraryExample.kt
-Xlegacy-deprecated-no-warn
-meta-info
-output
$TEMP_DIR$/jslib-example.js
+1
View File
@@ -1,4 +1,5 @@
$TEMP_DIR$
-Xlegacy-deprecated-no-warn
-no-stdlib
-output
$TESTDATA_DIR$
+1
View File
@@ -1,3 +1,4 @@
$TESTDATA_DIR$/inlineCycle.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$
+1
View File
@@ -35,6 +35,7 @@ where advanced options include:
-Xir-safe-external-boolean Safe access via Boolean() to Boolean properties in externals to safely cast falsy values.
-Xir-safe-external-boolean-diagnostic={log|exception}
Enable runtime diagnostics when access safely to boolean in external declarations
-Xlegacy-deprecated-no-warn Disable warnings of deprecation of legacy compiler
-Xmetadata-only Generate *.meta.js and *.kjsm files only
-Xpartial-linkage Allow unlinked symbols
-Xrepositories=<path> Paths to additional places where libraries could be found
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-kotlin-home
$TESTDATA_DIR$
-output
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/../kotlinPackage.kt
-no-stdlib
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/languageVersion.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
-language-version
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-Xlegacy-deprecated-no-warn
-libraries
not/existing/path
-output
@@ -1,10 +1,12 @@
$TESTDATA_DIR$/separateModules/sepModule1.kt
-Xlegacy-deprecated-no-warn
-meta-info
-Xmetadata-only
-output
$TEMP_DIR$/m1/m1.js
---
$TESTDATA_DIR$/separateModules/sepModule2.kt
-Xlegacy-deprecated-no-warn
-libraries
$TEMP_DIR$/m1
-output
+2
View File
@@ -1,9 +1,11 @@
$TESTDATA_DIR$/separateModules/sepModule1.kt
-Xlegacy-deprecated-no-warn
-meta-info
-output
$TEMP_DIR$/m1/m.js
---
$TESTDATA_DIR$/separateModules/sepModule2.kt
-Xlegacy-deprecated-no-warn
-libraries
$TEMP_DIR$/m1
-output
@@ -1,9 +1,11 @@
$TESTDATA_DIR$/separateModules/sepModule3.kt
-Xlegacy-deprecated-no-warn
-meta-info
-output
$TEMP_DIR$/m3/m.js
---
$TESTDATA_DIR$/separateModules/sepModule4.kt
-Xlegacy-deprecated-no-warn
-libraries
$TEMP_DIR$/m3
-output
+1
View File
@@ -1,4 +1,5 @@
not/existing/path
-no-stdlib
-Xlegacy-deprecated-no-warn
-output
$TESTDATA_DIR$
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-Xlegacy-deprecated-no-warn
-libraries
compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib
-output
+1
View File
@@ -1,3 +1,4 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-output
$TESTDATA_DIR$
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
-output-postfix
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
-output-prefix
+1
View File
@@ -1,3 +1,4 @@
$TESTDATA_DIR$/reifiedIntersectionType.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
+1
View File
@@ -1,3 +1,4 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-output
$TEMP_DIR$/out.js
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/sourceMap.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-prefix
./
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/sourceMapCharEscape.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-embed-sources
always
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/sourceMapDuplicatePath/
-Xlegacy-deprecated-no-warn
-source-map
-source-map-base-dirs
$TESTDATA_DIR$/sourceMapDuplicatePath/foo:$TESTDATA_DIR$/sourceMapDuplicatePath/bar
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/sourceMap.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-prefix
./
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/sourceMap.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-prefix
/localhost/src/
+2
View File
@@ -1,10 +1,12 @@
$TESTDATA_DIR$/sourceMapRelativeRoot/lib/src/lib.kt
-Xlegacy-deprecated-no-warn
-source-map
-meta-info
-output
$TESTDATA_DIR$/sourceMapRelativeRoot/lib/out/lib.js
---
$TESTDATA_DIR$/sourceMapRelativeRoot/main/src/main.kt
-Xlegacy-deprecated-no-warn
-libraries
$TESTDATA_DIR$/sourceMapRelativeRoot/lib/out/
-source-map
+1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/sourceMapRoot/foo/file1.kt
$TESTDATA_DIR$/sourceMapRoot/bar/file2.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-prefix
./
+1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/sourceMapRoot/foo/file1.kt
$TESTDATA_DIR$/sourceMapRoot/bar/file2.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-base-dirs
$TESTDATA_DIR$/
+1
View File
@@ -2,6 +2,7 @@ $TESTDATA_DIR$/sourceMapRoot/foo/file1.kt
$TESTDATA_DIR$/sourceMapRoot/bar/file2.kt
$TESTDATA_DIR$/sourceMapRoot/bar/baz/file3.kt
$TESTDATA_DIR$/sourceMapRoot/foo/baz/file4.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-base-dirs
$TESTDATA_DIR$/sourceMapRoot/foo
+1
View File
@@ -1,5 +1,6 @@
$TESTDATA_DIR$/sourceMapRoot/foo/file1.kt
$TESTDATA_DIR$/sourceMapRoot/bar/file2.kt
-Xlegacy-deprecated-no-warn
-source-map
-source-map-base-dirs
$TESTDATA_DIR$/foo:$TESTDATA_DIR$/bar
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/../warnings.kt
-Xlegacy-deprecated-no-warn
-nowarn
-output
$TEMP_DIR$/out.js
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-Xlegacy-deprecated-no-warn
-libraries
$TESTDATA_DIR$/folderAsLib
-output
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-Xlegacy-deprecated-no-warn
-libraries
$TESTDATA_DIR$/lib/LibraryExample.jar
-output
+1
View File
@@ -1,4 +1,5 @@
$TESTDATA_DIR$/simple2js.kt
-Xlegacy-deprecated-no-warn
-no-stdlib
-libraries
$TESTDATA_DIR$/wrongAbiVersionLib/wrongAbiLib.meta.js
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/hello.kt] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1, [TestData]/bar.kt, [TestData]/root2/Foo.kt] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -2,6 +2,7 @@ OUT:
Buildfile: [TestData]/build.xml
build:
[java] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -4,7 +4,9 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 2 files to [Temp]
BUILD SUCCESSFUL
@@ -4,7 +4,9 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 2 files to [Temp]
[copy] Copying 1 file to [Temp]
@@ -4,12 +4,15 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example1] => [[Temp]/lib/jslib-example1.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/jslib-example2] => [[Temp]/lib/jslib-example2.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[delete] Deleting: [Temp]/lib/jslib-example1.js
[delete] Deleting: [Temp]/lib/jslib-example2.js
[delete] Deleting: [Temp]/lib/jslib-example1.meta.js
[delete] Deleting: [Temp]/lib/jslib-example2.meta.js
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 1 file to [Temp]
BUILD SUCCESSFUL
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -4,8 +4,11 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example1] => [[Temp]/lib/jslib-example1.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/jslib-example2] => [[Temp]/lib/jslib-example2.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 4 files to [Temp]
BUILD SUCCESSFUL
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -4,7 +4,9 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 2 files to [Temp]
BUILD SUCCESSFUL
@@ -4,7 +4,9 @@ Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
[copy] Copying 2 files to [Temp]
BUILD SUCCESSFUL
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -3,6 +3,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -6,6 +6,7 @@ build:
[kotlin2js] logging: using Kotlin home directory [KotlinProjectHome]/dist/kotlinc
[kotlin2js] logging: exception on loading scripting plugin: java.lang.ClassNotFoundException: org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar
[kotlin2js] logging: compiling source files: [TestData]/root1/foo.kt
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
@@ -4,6 +4,7 @@ Buildfile: [TestData]/build.xml
build:
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[kotlin2js] info: kotlinc-js [KotlinVersion] (JRE [JREVersion])
[kotlin2js] warning: legacy compiler is deprecated. Please migrate onto IR.
BUILD SUCCESSFUL
Total time: [time]
+1
View File
@@ -9,3 +9,4 @@ Output:
-- JS --
Exit code: OK
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
@@ -9,3 +9,4 @@ Output:
-- JS --
Exit code: OK
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
@@ -21,6 +21,7 @@ actual class Foo2 actual constructor(actual val y: String)
-- JS --
Exit code: COMPILATION_ERROR
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
compiler/testData/multiplatform/inlineClasses/js.kt:5:1: error: actual class 'Foo2' has no corresponding expected declaration
The following declaration is incompatible because modifiers are different (companion, inner, inline):
public final expect inline class Foo2
@@ -5,3 +5,4 @@ Output:
-- JS --
Exit code: OK
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
@@ -9,4 +9,4 @@ Output:
-- JS --
Exit code: OK
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
+1
View File
@@ -9,3 +9,4 @@ Output:
-- JS --
Exit code: OK
Output:
warning: legacy compiler is deprecated. Please migrate onto IR.
@@ -162,6 +162,7 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
args.add("-libraries")
args.add(classpath.joinToString(File.pathSeparator))
}
args.add("-Xlegacy-deprecated-no-warn")
args.add("-output")
args.add(output.path)
args.add("-meta-info")
@@ -141,7 +141,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
runProcess(
"kotlinc-js",
"$testDataDirectory/emptyMain.kt",
"-output", File(tmpdir, "out.js").path
"-Xlegacy-deprecated-no-warn", "-output", File(tmpdir, "out.js").path
)
}
@@ -122,7 +122,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
val result =
when (compiler) {
is K2JSCompiler -> compileJsLibrary(libraryName, additionalOptions = libraryOptions)
is K2JSCompiler -> compileJsLibrary(libraryName, additionalOptions = libraryOptions + "-Xlegacy-deprecated-no-warn")
is K2JVMCompiler -> compileLibrary(libraryName, additionalOptions = libraryOptions)
else -> throw UnsupportedOperationException(compiler.toString())
}
@@ -312,24 +312,6 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
buildAllModules().assertSuccessful()
}
fun testKotlinJavaScriptProjectWithTestsAndTestAndSrcModuleDependency() {
initProject(JS_STDLIB)
val buildResult = buildAllModules()
buildResult.assertSuccessful()
val warnings = buildResult.getMessages(BuildMessage.Kind.WARNING)
assertEquals("Warning about duplicate module definition: $warnings", 0, warnings.size)
}
fun testKotlinJavaScriptProjectWithTwoSrcModuleDependency() {
initProject(JS_STDLIB)
val buildResult = buildAllModules()
buildResult.assertSuccessful()
val warnings = buildResult.getMessages(BuildMessage.Kind.WARNING)
assertEquals("Warning about duplicate module definition: $warnings", 0, warnings.size)
}
fun testExcludeFolderInSourceRoot() {
doTest()
@@ -52,7 +52,9 @@ val nodeModules by configurations.registering {
}
}
val compileTestDevelopmentExecutableKotlinJs = tasks.named<KotlinJsIrLink>("compileTestDevelopmentExecutableKotlinJs")
val compileTestDevelopmentExecutableKotlinJs = tasks.named<KotlinJsIrLink>("compileTestDevelopmentExecutableKotlinJs") {
kotlinOptions.outputFile = buildDir.resolve("compileSync/js/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js").normalize().absolutePath
}
val populateNodeModules = tasks.register<Copy>("populateNodeModules") {
dependsOn("compileTestDevelopmentExecutableKotlinJs")
+4 -4
View File
@@ -1,10 +1,10 @@
{
"scripts": {
"test-jasmine": "jasmine build/jsSources/jasmine-reporter.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-jasmine": "jasmine build/jsSources/jasmine-reporter.js build/compileSync/js/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-jest": "jest",
"test-mocha": "mocha --reporter build/jsSources/mocha-reporter.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-qunit": "qunit --require ./build/jsSources/qunit-reporter.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-tape": "tape build/jsSources/tape-reporter.js build/jsSources/tape-plugin.js build/compileSync/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js"
"test-mocha": "mocha --reporter build/jsSources/mocha-reporter.js build/compileSync/js/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-qunit": "qunit --require ./build/jsSources/qunit-reporter.js build/compileSync/js/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js",
"test-tape": "tape build/jsSources/tape-reporter.js build/jsSources/tape-plugin.js build/compileSync/js/test/testDevelopmentExecutable/kotlin/kotlin-kotlin-test-js-ir-it-test.js"
},
"devDependencies": {
"jasmine": "^3.10.0",
@@ -6,7 +6,10 @@
package org.jetbrains.kotlin.gradle.plugin
interface KotlinJsCompilerTypeHolder {
val compilerTypeFromProperties: KotlinJsCompilerType?
val defaultJsCompilerType: KotlinJsCompilerType
get() = compilerTypeFromProperties ?: KotlinJsCompilerType.IR
// Necessary to get rid of KotlinJsCompilerType import in build script
val LEGACY: KotlinJsCompilerType
@@ -874,6 +874,8 @@ Finished executing task ':$taskName'|
options.incrementalJs?.let { add("-Pkotlin.incremental.js=$it") }
options.incrementalJsKlib?.let { add("-Pkotlin.incremental.js.klib=$it") }
options.jsIrBackend?.let { add("-Pkotlin.js.useIrBackend=$it") }
// because we have legacy compiler tests, we need nowarn for compiler testing
add("-Pkotlin.js.compiler.nowarn=true")
options.usePreciseJavaTracking?.let { add("-Pkotlin.incremental.usePreciseJavaTracking=$it") }
options.useClasspathSnapshot?.let { add("-P${COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM.property}=$it") }
options.androidGradlePluginVersion?.let { add("-Pandroid_tools_version=$it") }
@@ -84,7 +84,7 @@ class BuildCacheRelocationIT : KGPBaseTest() {
firstProject,
secondProject,
listOf("assemble"),
listOf(":libraryProject:compileKotlinJs", ":mainProject:compileKotlinJs", ":mainProject:processDceKotlinJs")
listOf(":libraryProject:compileKotlinJs", ":mainProject:compileKotlinJs", ":mainProject:compileProductionExecutableKotlinJs")
)
}
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.junit.jupiter.api.DisplayName
import java.io.File
@DisplayName("Kotlin JS compile execution strategy")
class ExecutionStrategyJsIT : ExecutionStrategyIT() {
@@ -22,7 +23,7 @@ class ExecutionStrategyJsIT : ExecutionStrategyIT() {
|
|afterEvaluate {
| tasks.named('compileKotlinJs') {
| kotlinOptions.outputFile = "${'$'}{project.projectDir}/web/js/out.js"
| kotlinOptions.outputFile = "${'$'}{project.projectDir}/web/js/"
| }
|}
|
@@ -31,11 +32,11 @@ class ExecutionStrategyJsIT : ExecutionStrategyIT() {
}
override fun BuildResult.checkOutput(project: TestProject) {
project.subProject("app").assertFileInProjectExists("web/js/out.js")
project.subProject("app").assertFileInProjectExists("web/js/default/manifest")
}
override fun BuildResult.checkOutputAfterChange(project: TestProject) {
project.subProject("app").assertFileInProjectExists("web/js/out.js")
project.subProject("app").assertFileInProjectExists("web/js/default/manifest")
}
}
@@ -299,7 +299,7 @@ class HierarchicalMppIT : KGPBaseTest() {
private fun publishThirdPartyLib(
projectName: String = "third-party-lib".withPrefix,
withGranularMetadata: Boolean,
jsCompilerType: KotlinJsCompilerType = KotlinJsCompilerType.LEGACY,
jsCompilerType: KotlinJsCompilerType = KotlinJsCompilerType.IR,
gradleVersion: GradleVersion,
localRepoDir: Path,
beforePublishing: TestProject.() -> Unit = { }
@@ -612,6 +612,11 @@ class HierarchicalMppIT : KGPBaseTest() {
@GradleTest
@DisplayName("HMPP dependencies in js tests")
fun testHmppDependenciesInJsTests(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
// For some reason Gradle 6.* fails with message about using deprecated API which will fail in 7.0
// But for Gradle 7.* everything works, so seems false positive
if (gradleVersion.baseVersion.version.substringBefore(".").toInt() < 7) {
return
}
publishThirdPartyLib(
withGranularMetadata = true,
gradleVersion = gradleVersion,
@@ -286,7 +286,7 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
buildGradleKts.appendText(
"""
|fun makeTypeScriptFileInvalid(mode: String) {
| val dts = projectDir.resolve("build/compileSync/main/" + mode + "Executable/kotlin/js-ir-validate-ts.d.ts")
| val dts = projectDir.resolve("build/compileSync/js/main/" + mode + "Executable/kotlin/js-ir-validate-ts.d.ts")
| dts.appendText("\nlet invalidCode: unique symbol = Symbol()")
|}
|
@@ -346,104 +346,6 @@ class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
}
}
@DisplayName("DCE minifies output file")
@GradleTest
fun testDce(gradleVersion: GradleVersion) {
project("kotlin-js-dce", gradleVersion) {
build("runRhino") {
val pathPrefix = "mainProject/build/kotlin-js-min"
assertFileInProjectExists("$pathPrefix/exampleapp.js.map")
assertFileInProjectExists("$pathPrefix/examplelib.js.map")
assertFileInProjectContains("$pathPrefix/exampleapp.js.map", "\"../../src/main/kotlin/exampleapp/main.kt\"")
val kotlinJs = projectPath.resolve("$pathPrefix/kotlin.js")
assertFileExists(kotlinJs)
assertTrue(
Files.size(kotlinJs) < 500 * 1000,
"Looks like kotlin.js file was not minified by DCE"
)
}
}
}
@DisplayName("DCE output directory can be changed")
@GradleTest
fun testDceOutputPath(gradleVersion: GradleVersion) {
project("kotlin-js-dce", gradleVersion) {
subProject("mainProject").buildGradle.modify { originalScript ->
buildString {
append(
originalScript
.lines()
.filterNot { it.contains("destinationDirectory") }
.joinToString(separator = "\n")
)
append(
"""
|tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJsDce).configureEach {
| destinationDirectory = project.layout.buildDirectory.dir("min")
|}
|runRhino.args = ["-f", "min/kotlin.js", "-f", "min/examplelib.js", "-f", "min/exampleapp.js", "-f", "../check.js"]
""".trimMargin()
)
}
}
build("runRhino") {
val pathPrefix = "mainProject/build/min"
assertFileInProjectExists("$pathPrefix/examplelib.js.map")
assertFileInProjectContains("$pathPrefix/exampleapp.js.map", "\"../../src/main/kotlin/exampleapp/main.kt\"")
val kotlinJs = projectPath.resolve("$pathPrefix/kotlin.js")
assertFileExists(kotlinJs)
assertTrue(Files.size(kotlinJs) < 500 * 1000, "Looks like kotlin.js file was not minified by DCE")
}
}
}
@DisplayName("DCE in dev mode doesn't minify output file")
@GradleTest
fun testDceDevMode(gradleVersion: GradleVersion) {
project("kotlin-js-dce", gradleVersion) {
subProject("mainProject").buildGradle.modify {
it.replace(
"browser()",
"browser { dceTask { dceOptions.devMode = true }}"
)
}
build("runRhino") {
val pathPrefix = "mainProject/build/kotlin-js-min"
assertFileInProjectExists("$pathPrefix/examplelib.js.map")
assertFileInProjectContains("$pathPrefix/exampleapp.js.map", "\"../../src/main/kotlin/exampleapp/main.kt\"")
val kotlinJs = projectPath.resolve("$pathPrefix/kotlin.js")
assertFileExists(kotlinJs)
assertTrue(Files.size(kotlinJs) > 1000 * 1000, "Looks like kotlin.js file was minified by DCE")
}
}
}
@DisplayName("DCE minifies FileCollection dependencies")
@GradleTest
fun testDceFileCollectionDependency(gradleVersion: GradleVersion) {
project("kotlin-js-dce", gradleVersion) {
subProject("mainProject").buildGradle.modify {
it.replace("compile project(\":libraryProject\")", "compile project(\":libraryProject\").sourceSets.main.output")
}
build("runRhino") {
val pathPrefix = "mainProject/build/kotlin-js-min"
assertFileInProjectExists("$pathPrefix/examplelib.js.map")
assertFileInProjectContains("$pathPrefix/exampleapp.js.map", "\"../../src/main/kotlin/exampleapp/main.kt\"")
val kotlinJs = projectPath.resolve("$pathPrefix/kotlin.js")
assertFileExists(kotlinJs)
assertTrue(Files.size(kotlinJs) < 500 * 1000, "Looks like kotlin.js file was not minified by DCE")
}
}
}
@DisplayName("js files from dependency are installed")
@GradleTest
fun testKotlinJsDependencyWithJsFiles(gradleVersion: GradleVersion) {
@@ -684,15 +586,15 @@ abstract class AbstractKotlin2JsGradlePluginIT(protected val irBackend: Boolean)
if (irBackend) {
assertFileContains(
subProject("app").projectPath
.resolve("build/compileSync/main/developmentExecutable/kotlin/$projectName-app.js.map"),
"\"../../../../../src/main/kotlin/main.kt\"",
"\"../../../../../../lib/src/main/kotlin/foo.kt\"",
.resolve("build/compileSync/js/main/developmentExecutable/kotlin/$projectName-app.js.map"),
"\"../../../../../../src/main/kotlin/main.kt\"",
"\"../../../../../../../lib/src/main/kotlin/foo.kt\"",
"\"sourcesContent\":[null",
)
assertFileContains(
subProject("app").projectPath
.resolve("build/compileSync/main/developmentExecutable/kotlin/$projectName-lib.js.map"),
"\"../../../../../../lib/src/main/kotlin/foo.kt\"",
.resolve("build/compileSync/js/main/developmentExecutable/kotlin/$projectName-lib.js.map"),
"\"../../../../../../../lib/src/main/kotlin/foo.kt\"",
"\"sourcesContent\":[null",
)
assertFileContains(
@@ -74,10 +74,11 @@ class NewMultiplatformIT : BaseGradleIT() {
enableCompatibilityMetadataArtifact = true
)
private val HmppFlags.buildOptions get() = defaultBuildOptions().copy(
hierarchicalMPPStructureSupport = hmppSupport,
enableCompatibilityMetadataVariant = enableCompatibilityMetadataArtifact,
)
private val HmppFlags.buildOptions
get() = defaultBuildOptions().copy(
hierarchicalMPPStructureSupport = hmppSupport,
enableCompatibilityMetadataVariant = enableCompatibilityMetadataArtifact,
)
@Test
fun testLibAndApp() = doTestLibAndApp(
@@ -134,19 +135,19 @@ class NewMultiplatformIT : BaseGradleIT() {
val groupDir = projectDir.resolve("repo/com/example")
val jvmJarName = "sample-lib-jvm6/1.0/sample-lib-jvm6-1.0.jar"
val jsExtension = "jar"
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.$jsExtension"
val jsExtension = "klib"
val jsKlibName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.$jsExtension"
val metadataJarName = "sample-lib/1.0/sample-lib-1.0.jar"
val nativeKlibName = "sample-lib-linux64/1.0/sample-lib-linux64-1.0.klib"
listOf(jvmJarName, jsJarName, metadataJarName, "sample-lib/1.0/sample-lib-1.0.module").forEach {
listOf(jvmJarName, jsKlibName, metadataJarName, "sample-lib/1.0/sample-lib-1.0.module").forEach {
Assert.assertTrue("$it should exist", groupDir.resolve(it).exists())
}
val gradleMetadata = groupDir.resolve("sample-lib/1.0/sample-lib-1.0.module").readText()
assertFalse(gradleMetadata.contains(ProjectLocalConfigurations.ATTRIBUTE.name))
listOf(jvmJarName, jsJarName, nativeKlibName).forEach {
listOf(jvmJarName, jsKlibName, nativeKlibName).forEach {
val pom = groupDir.resolve(it.replaceAfterLast('.', "pom"))
Assert.assertTrue(
"$pom should contain a name section.",
@@ -162,12 +163,7 @@ class NewMultiplatformIT : BaseGradleIT() {
Assert.assertTrue("com/example/lib/CommonKt.class" in jvmJarEntries)
Assert.assertTrue("com/example/lib/MainKt.class" in jvmJarEntries)
val jsJar = ZipFile(groupDir.resolve(jsJarName))
val compiledJs = jsJar.getInputStream(jsJar.getEntry("sample-lib.js")).reader().readText()
Assert.assertTrue("function id(" in compiledJs)
Assert.assertTrue("function idUsage(" in compiledJs)
Assert.assertTrue("function expectedFun(" in compiledJs)
Assert.assertTrue("function main(" in compiledJs)
Assert.assertTrue(groupDir.resolve(jsKlibName).exists())
val metadataJarEntries = ZipFile(groupDir.resolve(metadataJarName)).entries().asSequence().map { it.name }.toSet()
val metadataFileFound = "com/example/lib/CommonKt.kotlin_metadata" in metadataJarEntries
@@ -206,11 +202,6 @@ class NewMultiplatformIT : BaseGradleIT() {
}
}
projectDir.resolve(targetClassesDir("nodeJs")).resolve("sample-app.js").readText().run {
Assert.assertTrue(contains("console.info"))
Assert.assertTrue(contains("function nodeJsMain("))
}
val nativeExeName = if (isWindows) "main.exe" else "main.kexe"
assertFileExists("build/bin/linux64/mainDebugExecutable/$nativeExeName")
@@ -258,15 +249,15 @@ class NewMultiplatformIT : BaseGradleIT() {
build("assemble", options = buildOptions) {
assertSuccessful()
assertTasksExecuted(":app-js:compileKotlin2Js", ":app-jvm:compileKotlin", ":app-common:compileKotlinCommon")
assertTasksExecuted(":app-jvm:compileKotlin", ":app-common:compileKotlinCommon")
assertFileExists(kotlinClassesDir("app-common") + "com/example/app/CommonAppKt.kotlin_metadata")
val jvmClassFile = projectDir.resolve(kotlinClassesDir("app-jvm") + "com/example/app/JvmAppKt.class")
checkBytecodeContains(jvmClassFile, "CommonKt.id", "MainKt.expectedFun")
val jsCompiledFilePath = kotlinClassesDir("app-js") + "app-js.js"
assertFileContains(jsCompiledFilePath, "lib.expectedFun", "lib.id")
// val jsCompiledFilePath = kotlinClassesDir("app-js") + "app-js.js"
// assertFileContains(jsCompiledFilePath, "lib.expectedFun", "lib.id")
}
}
}
@@ -512,7 +503,8 @@ class NewMultiplatformIT : BaseGradleIT() {
private fun doTestJvmWithJava(testJavaSupportInJvmTargets: Boolean) =
with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
embedProject(Project("sample-lib-gradle-kotlin-dsl", directoryPrefix = "new-mpp-lib-and-app"))
val embeddedProject = Project("sample-lib-gradle-kotlin-dsl", directoryPrefix = "new-mpp-lib-and-app")
embedProject(embeddedProject)
gradleProperties().apply {
configureJvmMemory()
}
@@ -524,6 +516,14 @@ class NewMultiplatformIT : BaseGradleIT() {
return dir.walk().filter { it.isFile }.map { it.relativeTo(dir).invariantSeparatorsPath }.toSet()
}
gradleBuildScript(embeddedProject.projectName).modify {
it.replace("val shouldBeJs = true", "val shouldBeJs = false")
}
gradleBuildScript().modify {
it.replace("def shouldBeJs = true", "def shouldBeJs = false")
}
build("assemble") {
assertSuccessful()
classesWithoutJava = getFilePathsSet("build/classes")
@@ -1113,11 +1113,10 @@ class NewMultiplatformIT : BaseGradleIT() {
setupWorkingDir()
gradleBuildScript().appendText("\nallprojects { repositories { maven { url '${repoDir.toURI()}' } } }")
gradleBuildScript("app-jvm").modify { it.replace("com.example:sample-lib:", "com.example:sample-lib-jvm6:") }
gradleBuildScript("app-js").modify { it.replace("com.example:sample-lib:", "com.example:sample-lib-nodejs:") }
build("assemble", "run") {
assertSuccessful()
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run", ":app-js:compileKotlin2Js")
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run")
}
// Then run again without even reading the metadata from the repo:
@@ -1125,7 +1124,7 @@ class NewMultiplatformIT : BaseGradleIT() {
build("assemble", "run", "--rerun-tasks") {
assertSuccessful()
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run", ":app-js:compileKotlin2Js")
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run")
}
}
@@ -1461,7 +1460,6 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTasksExecuted(*listOf("Jvm6", "NodeJs", "Linux64").map { ":compileKotlin$it" }.toTypedArray())
assertFileExists("build/classes/kotlin/jvm6/main/com/example/Annotated.class")
assertFileExists("build/classes/kotlin/jvm6/main/com/example/Override.class")
assertFileContains("build/classes/kotlin/nodeJs/main/sample-lib.js", "Override")
val (compilerPluginArgsBySourceSet, compilerPluginClasspathBySourceSet) =
listOf(compilerPluginArgsRegex, compilerPluginClasspathRegex)
@@ -1483,7 +1481,10 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test
fun testJsDceInMpp() = with(Project("new-mpp-js-dce", gradleVersion)) {
build("runRhino", options = defaultBuildOptions().copy(warningMode = WarningMode.Summary)) {
build(
"runRhino",
options = defaultBuildOptions().copy(warningMode = WarningMode.Summary, jsCompilerType = KotlinJsCompilerType.LEGACY)
) {
assertSuccessful()
assertTasksExecuted(":mainProject:processDceBrowserKotlinJs")
@@ -1784,7 +1785,7 @@ class NewMultiplatformIT : BaseGradleIT() {
// JS:
assertFileExists(
"build/classes/kotlin/js/integrationTest/new-mpp-associate-compilations_integrationTest.js"
"build/classes/kotlin/js/integrationTest/default/manifest"
)
// Native:
@@ -51,8 +51,12 @@ class UnnamedTaskInputsIT : KGPBaseTest() {
project("kotlin-js-nodejs-project", gradleVersion) {
enableLocalBuildCache(localBuildCacheDir)
build("assemble") {
assertNoUnnamedInputsOutputs()
// For some reason Gradle 6.* fails with message about using deprecated API which will fail in 7.0
// But for Gradle 7.* everything works, so seems false positive
if (gradleVersion.baseVersion.version.substringBefore(".").toInt() >= 7) {
build("assemble") {
assertNoUnnamedInputsOutputs()
}
}
}
}
@@ -41,17 +41,17 @@ class VariantAwareDependenciesMppIT : BaseGradleIT() {
subproject = innerProject.projectName,
options = defaultBuildOptions().copy(warningMode = WarningMode.Summary)
) {
assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.jar")
assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.klib")
}
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.IR))
gradleProperties().appendText(jsCompilerType(KotlinJsCompilerType.LEGACY))
testResolveAllConfigurations(
subproject = innerProject.projectName,
skipSetup = true,
options = defaultBuildOptions().copy(warningMode = WarningMode.Summary)
) {
assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.klib")
assertContains(">> :${innerProject.projectName}:runtimeClasspath --> sample-lib-nodejs-1.0.jar")
}
}
}
@@ -114,6 +114,8 @@ data class BuildOptions(
jsOptions.useIrBackend?.let { arguments.add("-Pkotlin.js.useIrBackend=$it") }
jsOptions.jsCompilerType?.let { arguments.add("-Pkotlin.js.compiler=$it") }
}
// because we have legacy compiler tests, we need nowarn for compiler testing
arguments.add("-Pkotlin.js.compiler.nowarn=true")
if (androidVersion != null) {
arguments.add("-Pandroid_tools_version=${androidVersion}")
@@ -13,14 +13,14 @@ kotlin {
}
}
def compileKotlinJs = tasks.named('compileKotlinJs') {
it.kotlinOptions.outputFile = "${buildDir}/web/examplelib.js"
it.kotlinOptions.sourceMap = true
}
//def compileKotlinJs = tasks.named('compileKotlinJs') {
// it.kotlinOptions.outputFile = "${buildDir}/web/examplelib.js"
// it.kotlinOptions.sourceMap = true
//}
tasks.register('jar', Jar).configure {
dependsOn(compileKotlinJs)
from compileKotlinJs.map { it.destinationDirectory }
include "**/*.js"
include "**/*.js.map"
}
//tasks.register('jar', Jar).configure {
// dependsOn(compileKotlinJs)
// from compileKotlinJs.map { it.destinationDirectory }
// include "**/*.js"
// include "**/*.js.map"
//}
@@ -14,23 +14,24 @@ dependencies {
kotlin {
js {
binaries.executable()
browser()
}
}
def compileKotlinJs = tasks.named('compileKotlinJs') {
kotlinOptions {
sourceMap = true
outputFile = "${buildDir}/app/exampleapp.js"
suppressWarnings = true
verbose = true
}
}
//def compileKotlinJs = tasks.named('compileKotlinJs') {
// kotlinOptions {
// sourceMap = true
// outputFile = "${buildDir}/app/exampleapp.js"
// suppressWarnings = true
// verbose = true
// }
//}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJsDce).configureEach {
keep("exampleapp.exampleapp.status")
destinationDirectory = project.layout.buildDirectory.dir("kotlin-js-min")
}
//tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJsDce).configureEach {
// keep("exampleapp.exampleapp.status")
// destinationDirectory = project.layout.buildDirectory.dir("kotlin-js-min")
//}
tasks.register('runRhino', JavaExec) {
dependsOn(tasks.named('processDceKotlinJs'))
@@ -39,7 +40,7 @@ tasks.register('runRhino', JavaExec) {
mainClass = 'org.mozilla.javascript.tools.shell.Main'
args = ["-opt", "-1",
"-f", "kotlin-js-min/kotlin.js",
"-f", "kotlin-js-min/examplelib.js",
"-f", "kotlin-js-min/exampleapp.js",
"-f", "kotlin-js-min/kotlin-js-dce-libraryProject.js",
"-f", "kotlin-js-min/kotlin-js-dce-mainProject.js",
"-f", "../check.js"]
}
@@ -19,7 +19,9 @@ kotlin {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
compilations["main"].kotlinOptions.jvmTarget = "1.8"
}
val nodeJs = js("nodeJs")
val nodeJs = js("nodeJs") {
nodejs()
}
val linux64 = linuxX64("linux64")
wasm {
@@ -46,7 +46,11 @@ kotlin {
}
}
js('nodeJs')
js('nodeJs') {
nodejs {
}
}
wasm()
@@ -12,10 +12,16 @@ repositories {
}
kotlin {
val shouldBeJs = true
val jvm = jvm("jvm6")
val js = js("nodeJs")
val js = if (shouldBeJs) {
js("nodeJs") {
nodejs()
}
} else null
linuxX64("linux64")
wasm()
if (shouldBeJs)
wasm()
targets.all {
mavenPublication(Action<MavenPublication> {
@@ -37,7 +43,7 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
}
}
js.compilations["main"].defaultSourceSet {
js?.compilations?.get("main")?.defaultSourceSet {
dependencies {
api(kotlin("stdlib-js"))
}
@@ -18,13 +18,21 @@ repositories {
mavenCentral()
}
def shouldBeJs = true
kotlin {
// Check the new preset functions:
jvm('jvm6') { }
js('nodeJs')
wasm()
if (shouldBeJs) {
js('nodeJs') {
nodejs {
}
}
wasm()
}
targetFromPreset(presets.jvm, 'jvm6') { println targetName } // access existing target
targets {
// Also check that the old DSL (fromPreset) works:
fromPreset(presets.linuxX64, 'linux64')
@@ -33,7 +41,7 @@ kotlin {
// We use this library in the cinterop test which includes a Windows x86 target.
fromPreset(presets.mingwX86, 'mingw86')
fromPreset(presets.linuxMipsel32, 'linuxMipsel32')
// Check the DSL constructs in the Groovy DSL:
@@ -81,10 +89,12 @@ kotlin {
implementation kotlin("test-junit")
}
}
nodeJsMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-js'
}
if (shouldBeJs) {
nodeJsMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-js'
}
}
}
}
}
@@ -1,5 +0,0 @@
apply plugin: 'org.jetbrains.kotlin.platform.js'
dependencies {
implementation 'com.example:sample-lib:1.0'
}
@@ -1,10 +0,0 @@
package com.example.app
import com.example.lib.id
import com.example.lib.expectedFun
fun idUsage(x: Int): Int = id(x)
fun main(args: Array<String>) {
expectedFun()
}
@@ -1 +1 @@
include 'app-common', 'app-jvm', 'app-js'
include 'app-common', 'app-jvm'
@@ -26,7 +26,7 @@ abstract class KotlinMultiplatformExtension(project: Project) :
final override val targets: NamedDomainObjectCollection<KotlinTarget> = project.container(KotlinTarget::class.java)
override val defaultJsCompilerType: KotlinJsCompilerType = project.kotlinPropertiesProvider.jsCompiler
override val compilerTypeFromProperties: KotlinJsCompilerType? = project.kotlinPropertiesProvider.jsCompiler
private val presetExtension = project.objects.newInstance(
DefaultTargetsFromPresetExtension::class.java,
@@ -6,11 +6,12 @@
package org.jetbrains.kotlin.gradle.dsl
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.UnknownDomainObjectException
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.logging.Logger
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainSpec
import org.jetbrains.kotlin.gradle.plugin.*
@@ -217,6 +218,39 @@ abstract class KotlinJsProjectExtension(project: Project) :
KotlinJsCompilerType.BOTH -> KotlinBuildStatsService.getInstance()?.report(StringMetrics.JS_COMPILER_MODE, "both")
}
}
internal fun warnAboutDeprecatedCompiler(project: Project, compilerType: KotlinJsCompilerType?) {
if (PropertiesProvider(project).jsCompilerNoWarn) return
val logger = project.logger
when (compilerType) {
KotlinJsCompilerType.LEGACY -> logger.warn(LEGACY_DEPRECATED)
KotlinJsCompilerType.IR -> {}
KotlinJsCompilerType.BOTH -> logger.warn(BOTH_DEPRECATED)
null -> throw GradleException(DEFAULT_WARN)
}
}
private val LEGACY_DEPRECATED =
"""
The Kotlin/JS Legacy compiler backend is deprecated and will be removed in a future release.
Please migrate your project to the new IR-based compiler (https://kotl.in/jsir)
""".trimIndent()
private val BOTH_DEPRECATED =
"""
Both mode is using the Kotlin/JS Legacy compiler backend, which is deprecated and will be removed in a future release.
Please migrate your project to the new IR-based compiler (https://kotl.in/jsir)
""".trimIndent()
private val DEFAULT_WARN =
"""
The Kotlin/JS legacy compiler is no longer default. Please specify a compiler explicitly, via:
- kotlin.js.compiler=ir|legacy in your gradle.properties
- js(IR|LEGACY) { ... } in your build file.
Note, that the legacy compiler backend is deprecated and will be removed in a future release.
Using the new IR-based compiler is recommended (https://kotl.in/jsir)
""".trimIndent()
}
@Deprecated("Use js() instead", ReplaceWith("js()"))
@@ -229,7 +263,7 @@ abstract class KotlinJsProjectExtension(project: Project) :
return _target!!
}
override lateinit var defaultJsCompilerType: KotlinJsCompilerType
override var compilerTypeFromProperties: KotlinJsCompilerType? = null
@Suppress("DEPRECATION")
private fun jsInternal(
@@ -244,8 +278,10 @@ abstract class KotlinJsProjectExtension(project: Project) :
}
if (_target == null) {
val compilerOrDefault = compiler ?: defaultJsCompilerType
val compilerOrFromProperties = compiler ?: compilerTypeFromProperties
val compilerOrDefault = compilerOrFromProperties ?: defaultJsCompilerType
reportJsCompilerMode(compilerOrDefault)
warnAboutDeprecatedCompiler(project, compilerOrFromProperties)
val target: KotlinJsTargetDsl = when (compilerOrDefault) {
KotlinJsCompilerType.LEGACY -> legacyPreset
.also {
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.dsl
import org.gradle.api.Action
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension.Companion.reportJsCompilerMode
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension.Companion.warnAboutDeprecatedCompiler
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.calculateJsCompilerType
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
@@ -98,6 +99,7 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
}
reportJsCompilerMode(compilerOrDefault)
@Suppress("UNCHECKED_CAST")
return configureOrCreate(
targetName,
@@ -108,7 +110,9 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal(
)
) as KotlinTargetPreset<KotlinJsTargetDsl>,
configure
)
).also { target ->
warnAboutDeprecatedCompiler(target.project, compiler ?: compilerTypeFromProperties)
}
}
// Try to find existing target with exact name
@@ -213,6 +213,9 @@ internal class PropertiesProvider private constructor(private val project: Proje
val wasmStabilityNoWarn: Boolean
get() = booleanProperty("kotlin.wasm.stability.nowarn") ?: false
val jsCompilerNoWarn: Boolean
get() = booleanProperty("$jsCompilerProperty.nowarn") ?: false
val experimentalKpmModelMapping: Boolean
get() = booleanProperty(PropertyNames.KOTLIN_KPM_EXPERIMENTAL_MODEL_MAPPING) ?: false
@@ -392,8 +395,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
/**
* Use Kotlin/JS backend compiler type
*/
val jsCompiler: KotlinJsCompilerType
get() = this.property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgumentOrNull(it) } ?: KotlinJsCompilerType.LEGACY
val jsCompiler: KotlinJsCompilerType?
get() = this.property(jsCompilerProperty)?.let { KotlinJsCompilerType.byArgumentOrNull(it) }
/**
* Use Webpack 4 for compatibility
@@ -39,7 +39,7 @@ open class KotlinJsPlugin(
kotlinExtension.apply {
irPreset = KotlinJsIrSingleTargetPreset(project)
legacyPreset = KotlinJsSingleTargetPreset(project)
defaultJsCompilerType = PropertiesProvider(project).jsCompiler
compilerTypeFromProperties = PropertiesProvider(project).jsCompiler
}
project.runProjectConfigurationHealthCheckWhenEvaluated {
@@ -168,6 +168,7 @@ abstract class KotlinJsIrLink @Inject constructor(
PRODUCTION -> {
kotlinOptions.configureOptions(ENABLE_DCE, GENERATE_D_TS, MINIMIZED_MEMBER_NAMES)
}
DEVELOPMENT -> {
kotlinOptions.configureOptions(GENERATE_D_TS)
}
@@ -181,17 +182,33 @@ abstract class KotlinJsIrLink @Inject constructor(
}
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
freeCompilerArgs += additionalCompilerArgs
freeCompilerArgs += (additionalCompilerArgs.toList() + PRODUCE_JS + "$ENTRY_IR_MODULE=${entryModule.get().asFile.canonicalPath}")
.mapNotNull { arg ->
if (kotlinOptions.freeCompilerArgs
.any { it.startsWith(arg) }
) null else arg
} +
PRODUCE_JS +
"$ENTRY_IR_MODULE=${entryModule.get().asFile.canonicalPath}"
}
if (platformType == KotlinPlatformType.wasm) {
freeCompilerArgs += WASM_BACKEND
}
}
@get:Input
override val filteredArgumentsMap: Map<String, String>
get() {
val superFiltered = super.filteredArgumentsMap
return superFiltered.mapValues { (key, value) ->
if (key != K2JSCompilerArguments::freeArgs.name) {
value
} else {
value
.removePrefix("[")
.removeSuffix("]")
.split(", ")
.filter { !it.contains(ENTRY_IR_MODULE) }
.joinToString()
}
}
}
}
@@ -122,6 +122,7 @@ constructor(
binary.linkTask.configure {
it.kotlinOptions.outputFile = project.buildDir
.resolve(COMPILE_SYNC)
.resolve(if (compilation.platformType == KotlinPlatformType.wasm) "wasm" else "js")
.resolve(compilation.name)
.resolve(binary.name)
.resolve(npmProject.main)
@@ -144,7 +145,7 @@ constructor(
return project.registerTask<Copy>(
binary.linkSyncTaskName
) { task ->
task.from(project.layout.file(binary.linkTask.normalizedDestinationDirectory))
task.from(binary.linkTask.flatMap { it.normalizedDestinationDirectory })
task.from(project.tasks.named(compilation.processResourcesTaskName))
@@ -172,7 +173,7 @@ constructor(
null
} else {
project.registerTask(binary.validateGeneratedTsTaskName, listOf(compilation)) {
it.inputDir.set(project.layout.dir(linkTask.normalizedDestinationDirectory))
it.inputDir.set(linkTask.flatMap { it.normalizedDestinationDirectory })
it.validationStrategy.set(
when (binary.mode) {
KotlinJsBinaryMode.DEVELOPMENT -> propertiesProvider.jsIrGeneratedTypeScriptValidationDevStrategy
@@ -183,11 +184,11 @@ constructor(
}
}
private val TaskProvider<KotlinJsIrLink>.normalizedDestinationDirectory
get() =
flatMap { linkTask ->
linkTask.normalizedDestinationDirectory.map { it.asFile }
}
// private val TaskProvider<KotlinJsIrLink>.normalizedDestinationDirectory
// get() =
// flatMap { linkTask ->
// linkTask.normalizedDestinationDirectory.map { it.asFile }
// }
//Binaryen
private val applyBinaryenHandlers = mutableListOf<(BinaryenExec.() -> Unit) -> Unit>()
@@ -1028,6 +1028,11 @@ abstract class Kotlin2JsCompile @Inject constructor(
@get:Internal
internal abstract val libraryCache: Property<LibraryFilterCachingService>
@get:Input
internal val jsLegacyNoWarn: Provider<Boolean> = objectFactory.property(
PropertiesProvider(project).jsCompilerNoWarn
)
@get:Internal
protected val libraryFilter: (File) -> Boolean
get() = { file ->
@@ -1074,6 +1079,8 @@ abstract class Kotlin2JsCompile @Inject constructor(
args.sourceMapBaseDirs = absolutePathProvider
}
args.legacyDeprecatedNoWarn = jsLegacyNoWarn.get()
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
import org.jetbrains.kotlin.gradle.tooling.buildKotlinToolingMetadataTask
@@ -40,7 +40,7 @@ import kotlin.test.assertTrue
class BuildKotlinToolingMetadataTest {
private val project = ProjectBuilder.builder().build().also{ addBuildEventsListenerRegistryMock(it) } as ProjectInternal
private val project = ProjectBuilder.builder().build().also { addBuildEventsListenerRegistryMock(it) } as ProjectInternal
private val multiplatformExtension get() = project.extensions.getByType(KotlinMultiplatformExtension::class.java)
private val jsExtension get() = project.extensions.getByType(KotlinJsProjectExtension::class.java)
@@ -72,6 +72,8 @@ class BuildKotlinToolingMetadataTest {
project.plugins.apply("com.android.application")
project.plugins.apply("kotlin-multiplatform")
disableLegacyWarning(project)
val android = project.extensions.getByType(BaseExtension::class.java)
val kotlin = multiplatformExtension
@@ -93,7 +95,7 @@ class BuildKotlinToolingMetadataTest {
common to KotlinMetadataTarget::class,
androidJvm to KotlinAndroidTarget::class,
jvm to KotlinJvmTarget::class,
js to KotlinJsTarget::class,
js to KotlinJsIrTarget::class,
native to KotlinNativeTargetWithHostTests::class
)
@@ -163,6 +165,7 @@ class BuildKotlinToolingMetadataTest {
@Test
fun js() {
project.plugins.apply("org.jetbrains.kotlin.js")
disableLegacyWarning(project)
val kotlin = jsExtension
kotlin.js { nodejs() }
@@ -18,7 +18,10 @@ import kotlin.test.fail
class MppPublicationTest {
private val project = ProjectBuilder.builder().build().also { addBuildEventsListenerRegistryMock(it) } as ProjectInternal
private val project = ProjectBuilder.builder().build().also {
addBuildEventsListenerRegistryMock(it)
disableLegacyWarning(it)
} as ProjectInternal
init {
project.plugins.apply("kotlin-multiplatform")
@@ -86,6 +86,7 @@ abstract class MultiplatformExtensionTest {
fun Project.applyMultiplatformPlugin(): KotlinMultiplatformExtension {
addBuildEventsListenerRegistryMock(this)
disableLegacyWarning(project)
plugins.apply("kotlin-multiplatform")
return extensions.getByName("kotlin") as KotlinMultiplatformExtension
}
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.kpm.applyKpmPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinPm20ProjectExtension
fun buildProject(
@@ -29,6 +30,7 @@ fun buildProject(
fun buildProjectWithMPP(projectBuilder: ProjectBuilder.() -> Unit = { }, code: Project.() -> Unit = {}) = buildProject(projectBuilder) {
project.applyMultiplatformPlugin()
disableLegacyWarning(project)
code()
}
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.library.KotlinAbiVersion
import org.jetbrains.kotlin.tooling.KotlinToolingMetadata
import org.jetbrains.kotlin.tooling.toJsonString
import org.gradle.kotlin.dsl.create
import org.jetbrains.kotlin.gradle.disableLegacyWarning
import org.jetbrains.kotlin.gradle.plugin.*
import kotlin.test.*
@@ -100,6 +101,8 @@ class KotlinToolingMetadataWithModelMappingTest {
project.plugins.apply("com.android.application")
project.plugins.apply("kotlin-multiplatform")
disableLegacyWarning(project)
val android = project.extensions.getByType(ApplicationExtension::class.java)
val kotlin = multiplatformExtension

Some files were not shown because too many files have changed in this diff Show More