[K/JS] Add a secret system property to enable the old Kotlin/JS compiler only for tests until it will be removed from the sources

This commit is contained in:
Artem Kobzar
2022-12-29 13:32:01 +00:00
committed by Space Team
parent 47f32b715f
commit fbf06b5495
49 changed files with 109 additions and 16 deletions
@@ -55,7 +55,8 @@ enum class CompilerSystemProperties(val property: String, val alwaysDirectAccess
USER_HOME("user.home", alwaysDirectAccess = true),
JAVA_VERSION("java.specification.version", alwaysDirectAccess = true),
JAVA_HOME("java.home", alwaysDirectAccess = true),
JAVA_CLASS_PATH("java.class.path", alwaysDirectAccess = true)
JAVA_CLASS_PATH("java.class.path", alwaysDirectAccess = true),
KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED("kotlin.js.compiler.legacy.force_enabled", alwaysDirectAccess = true)
;
private fun <T> getProperFunction(custom: T?, default: T): T {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.cli.common.arguments
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -365,7 +366,7 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
collector.deprecationWarn(irBaseClassInMetadata, false, "-Xir-base-class-in-metadata")
collector.deprecationWarn(irNewIr2Js, true, "-Xir-new-ir2js")
if (languageVersion >= LanguageVersion.KOTLIN_1_9) {
if (languageVersion >= LanguageVersion.KOTLIN_1_9 && CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value != "true") {
collector.deprecationWarn(legacyDeprecatedNoWarn, false, "-Xlegacy-deprecated-no-warn")
collector.deprecationWarn(useDeprecatedLegacyCompiler, false, "-Xuse-deprecated-legacy-compiler")
}
@@ -184,7 +184,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(configuration);
if (languageVersionSettings.getLanguageVersion().compareTo(LanguageVersion.KOTLIN_1_9) >= 0) {
if (CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.getValue() != "true" && languageVersionSettings.getLanguageVersion().compareTo(LanguageVersion.KOTLIN_1_9) >= 0) {
messageCollector.report(ERROR, "Old Kotlin/JS compiler is no longer supported. Please migrate to the new JS IR backend", null);
return COMPILATION_ERROR;
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder
import org.jetbrains.kotlin.incremental.utils.TestCompilationResult
@@ -43,6 +44,8 @@ abstract class AbstractIncrementalJsCompilerRunnerTest : AbstractIncrementalComp
sourceMap = true
metaInfo = true
useDeprecatedLegacyCompiler = true
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
protected open val scopeExpansionMode = CompileScopeExpansionMode.NEVER
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.build.report.ICReporter
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistoryJs
@@ -29,6 +30,8 @@ abstract class AbstractIncrementalMultiModuleJsCompilerRunnerTest :
sourceMap = true
metaInfo = true
useDeprecatedLegacyCompiler = true
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
override fun makeForSingleModule(
@@ -286,13 +286,20 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
}
protected void doJsTest(@NotNull String fileName) {
setupOldJsCompiler(fileName);
doTest(fileName, new K2JSCompiler());
}
protected void doJsDceTest(@NotNull String fileName) {
setupOldJsCompiler(fileName);
doTest(fileName, new K2JSDce());
}
private void setupOldJsCompiler(String fileName) {
if (fileName == null) return;
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.setValue(Boolean.toString(!fileName.contains("_strict")));
}
protected void doMetadataTest(@NotNull String fileName) {
doTest(fileName, new K2MetadataCompiler());
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.util.io.ZipUtil
import org.jetbrains.kotlin.cli.AbstractCliTest
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
@@ -167,6 +168,8 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() {
args.add("-output")
args.add(output.path)
args.add("-meta-info")
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
} else if (compiler is K2JVMCompiler || compiler is K2MetadataCompiler) {
if (classpath.isNotEmpty()) {
args.add("-classpath")
@@ -1205,9 +1205,9 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/js/jsHelp.args");
}
@TestMetadata("jsOldBackend.args")
public void testJsOldBackend() throws Exception {
runTest("compiler/testData/cli/js/jsOldBackend.args");
@TestMetadata("jsOldBackend_strict.args")
public void testJsOldBackend_strict() throws Exception {
runTest("compiler/testData/cli/js/jsOldBackend_strict.args");
}
@TestMetadata("kotlinHomeWithoutStdlib.args")
@@ -11,6 +11,7 @@ import com.intellij.mock.MockProject
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.cli.common.CLITool
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
@@ -70,6 +71,12 @@ class AnalysisHandlerExtensionTest : TestCaseWithTmpdir() {
listOf("-Xuse-deprecated-legacy-compiler", "-output", tmpdir.resolve("out.js").absolutePath)
else
listOf("-d", tmpdir.resolve("out").absolutePath)
if (compiler is K2JSCompiler) {
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
val (output, exitCode) = CompilerTestUtil.executeCompiler(compiler, args + outputPath + extras)
assertEquals(expectedExitCode, exitCode, output)
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.cli
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.test.KotlinTestUtils
@@ -142,7 +143,12 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
runProcess(
"kotlinc-js",
"$testDataDirectory/emptyMain.kt",
"-Xlegacy-deprecated-no-warn", "-Xuse-deprecated-legacy-compiler", "-output", File(tmpdir, "out.js").path
"-nowarn",
"-Xlegacy-deprecated-no-warn",
"-Xuse-deprecated-legacy-compiler",
"-D${CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.property}=true",
"-output",
File(tmpdir, "out.js").path,
)
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.jvm.compiler
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
@@ -101,7 +102,13 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) {
val library = compileJsLibrary(libraryName, additionalOptions = listOf("-Xmetadata-version=42.0.0"))
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList())
compileKotlin(
"source.kt",
File(tmpdir, "usage.js"),
listOf(library),
K2JSCompiler(),
additionalOptions.toList()
)
}
private fun doTestPreReleaseKotlinLibrary(
@@ -130,6 +137,11 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
else -> throw UnsupportedOperationException(compiler.toString())
}
if (compiler is K2JSCompiler) {
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
compileKotlin(
"source.kt", usageDestination, listOf(result), compiler,
additionalOptions.toList() + listOf("-language-version", LanguageVersion.LATEST_STABLE.versionString)
@@ -590,7 +602,12 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
}
fun testInternalFromForeignModuleJs() {
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(compileJsLibrary("library")), K2JSCompiler())
compileKotlin(
"source.kt",
File(tmpdir, "usage.js"),
listOf(compileJsLibrary("library")),
K2JSCompiler(),
)
}
fun testInternalFromFriendModuleJs() {
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.multiplatform
import org.jetbrains.kotlin.cli.AbstractCliTest
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.js.K2JSCompiler
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler
@@ -65,6 +66,8 @@ abstract class AbstractMultiPlatformIntegrationTest : KtUsefulTestCase() {
if (jsSrc != null) {
appendLine()
appendLine("-- JS --")
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
appendLine(K2JSCompiler().compile(jsSrc, commonSrc, "-Xuse-deprecated-legacy-compiler", "-output", jsDest!!))
}
@@ -11,6 +11,7 @@ import com.intellij.util.ThrowableRunnable
import com.intellij.util.containers.Interner
import org.jetbrains.kotlin.TestWithWorkingDir
import org.jetbrains.kotlin.build.JvmSourceRoot
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
@@ -168,6 +169,8 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
reportOutputFiles = true
freeArgs = filesToCompile.map { it.canonicalPath }
useDeprecatedLegacyCompiler = true
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
configureAdditionalArgs(args)
return runJSCompiler(args, env)
@@ -27,6 +27,7 @@ import org.jetbrains.jps.model.library.JpsLibrary
import org.jetbrains.jps.model.library.JpsOrderRootType
import org.jetbrains.jps.model.library.sdk.JpsSdk
import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest
import org.jetbrains.kotlin.test.runTest
@@ -36,6 +37,7 @@ abstract class BaseKotlinJpsBuildTestCase : JpsBuildTestCase() {
override fun setUp() {
super.setUp()
System.setProperty("kotlin.jps.tests", "true")
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
override fun shouldRunTest(): Boolean {
@@ -11,6 +11,7 @@ import com.intellij.util.ThrowableRunnable
import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.config.CompilerSettings
import org.jetbrains.kotlin.config.KotlinFacetSettings
@@ -91,6 +92,8 @@ abstract class KotlinJpsBuildTestBase : AbstractKotlinJpsBuildTestCase() {
val facet = KotlinFacetSettings()
facet.compilerArguments = K2JSCompilerArguments().apply {
useDeprecatedLegacyCompiler = true
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
facet.targetPlatform = JsPlatforms.defaultJsPlatform
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.jps.incremental
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
@@ -51,6 +52,8 @@ abstract class AbstractJsProtoComparisonTest : AbstractProtoComparisonTest<Proto
main = K2JsArgumentConstants.NO_CALL
freeArgs = ktFiles
useDeprecatedLegacyCompiler = true
// TODO: It will be deleted after all of our internal vendors will use the new Kotlin/JS compiler
CompilerSystemProperties.KOTLIN_JS_COMPILER_LEGACY_FORCE_ENABLED.value = "true"
}
val env = createTestingCompilerEnvironment(messageCollector, outputItemsCollector, services)
@@ -1 +1,2 @@
kotlin.js.compiler=legacy
kotlin.js.compiler=legacy
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1 +1,2 @@
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1 +1,2 @@
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1 +1,2 @@
kotlin.js.compiler.nowarn=true
kotlin.js.compiler.nowarn=true
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1 +1,2 @@
kotlin.tests.individualTaskReports=true
kotlin.tests.individualTaskReports=true
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1,3 +1,4 @@
kotlin.tests.individualTaskReports=true
#because of dependency (kotlinx-html) which is not klib yet
kotlin.js.compiler=legacy
kotlin.js.compiler=legacy
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -1 +1,2 @@
kotlin.tests.individualTaskReports=true
kotlin.tests.individualTaskReports=true
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true
@@ -0,0 +1 @@
kotlin.daemon.jvmargs=-Dkotlin.js.compiler.legacy.force_enabled=true