From 093f51c89a8795560205680acf64eb1aa652b00c Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Tue, 28 Nov 2023 13:44:37 +0000 Subject: [PATCH] [JS] Removing usage of legacy JS compiler #1 --- .../cli/js/nonExistingKotlinHome.args | 6 +++-- .../js/simpleWithJsFileAsAnotherLib/build.xml | 2 -- .../build.xml | 1 - .../AbstractIrCompileKotlinAgainstKlibTest.kt | 9 ++++--- .../jetbrains/kotlin/test/MockLibraryUtil.kt | 15 ----------- .../cli/AnalysisHandlerExtensionTest.kt | 25 +++---------------- ...tCompileKotlinAgainstCustomBinariesTest.kt | 2 +- 7 files changed, 15 insertions(+), 45 deletions(-) diff --git a/compiler/testData/cli/js/nonExistingKotlinHome.args b/compiler/testData/cli/js/nonExistingKotlinHome.args index c880d12065655..22b935b6b8502 100644 --- a/compiler/testData/cli/js/nonExistingKotlinHome.args +++ b/compiler/testData/cli/js/nonExistingKotlinHome.args @@ -1,5 +1,7 @@ $TESTDATA_DIR$/simple2js.kt -kotlin-home non-existing-path --output -$TEMP_DIR$/out.js +-ir-output-dir +$TEMP_DIR$ +-ir-output-name +out diff --git a/compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib/build.xml b/compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib/build.xml index cfceaf684594b..db6b29890ff54 100644 --- a/compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib/build.xml +++ b/compiler/testData/integration/ant/js/simpleWithJsFileAsAnotherLib/build.xml @@ -6,14 +6,12 @@ - - diff --git a/compiler/testData/integration/ant/js/simpleWithoutStdlibAndFolderAsAnotherLib/build.xml b/compiler/testData/integration/ant/js/simpleWithoutStdlibAndFolderAsAnotherLib/build.xml index 9007f6d0d2b59..2e034578eb510 100644 --- a/compiler/testData/integration/ant/js/simpleWithoutStdlibAndFolderAsAnotherLib/build.xml +++ b/compiler/testData/integration/ant/js/simpleWithoutStdlibAndFolderAsAnotherLib/build.xml @@ -13,7 +13,6 @@ - diff --git a/compiler/tests-against-klib/tests/org/jetbrains/kotlin/codegen/ir/AbstractIrCompileKotlinAgainstKlibTest.kt b/compiler/tests-against-klib/tests/org/jetbrains/kotlin/codegen/ir/AbstractIrCompileKotlinAgainstKlibTest.kt index 21144e06614c3..d8e1f3edd04f1 100644 --- a/compiler/tests-against-klib/tests/org/jetbrains/kotlin/codegen/ir/AbstractIrCompileKotlinAgainstKlibTest.kt +++ b/compiler/tests-against-klib/tests/org/jetbrains/kotlin/codegen/ir/AbstractIrCompileKotlinAgainstKlibTest.kt @@ -24,12 +24,14 @@ import java.util.* abstract class AbstractCompileKotlinAgainstKlibTest : AbstractBlackBoxCodegenTest() { lateinit var klibName: String lateinit var outputDir: File + lateinit var klibPath: String override val backend = TargetBackend.JVM_IR override fun doMultiFileTest(wholeFile: File, files: List) { outputDir = javaSourcesOutputDirectory - klibName = Paths.get(outputDir.toString(), wholeFile.name.toString().replace(".kt", ".klib")).toString() + klibName = wholeFile.nameWithoutExtension + klibPath = Paths.get(outputDir.toString(), klibName + ".klib").toString() val classpath: MutableList = ArrayList() classpath.add(KtTestUtil.getAnnotationsJar()) @@ -55,7 +57,7 @@ abstract class AbstractCompileKotlinAgainstKlibTest : AbstractBlackBoxCodegenTes override fun updateConfiguration(configuration: CompilerConfiguration) { super.updateConfiguration(configuration) - configuration.put(JVMConfigurationKeys.KLIB_PATHS, listOf(klibName + ".klib")) + configuration.put(JVMConfigurationKeys.KLIB_PATHS, listOf(klibName)) } // We need real (as opposed to virtual) files in order to produce a Klib. @@ -76,7 +78,8 @@ abstract class AbstractCompileKotlinAgainstKlibTest : AbstractBlackBoxCodegenTes val (output, exitCode) = AbstractCliTest.executeCompilerGrabOutput( K2JSCompiler(), listOf( - "-output", klibName, + "-ir-output-dir", outputDir.normalize().absolutePath, + "-ir-output-name", klibName, "-Xir-produce-klib-file", "-libraries", "libraries/stdlib/build/classes/kotlin/js/main/" ) + sourceFiles diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt index 8edae31536603..04447be224d85 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/test/MockLibraryUtil.kt @@ -145,17 +145,6 @@ object MockLibraryUtil { return createJarFile(contentDir, classesDir, jarName, sourcesPath.takeIf { addSources }) } - @JvmStatic - fun compileJsLibraryToJar(sourcesPath: String, jarName: String, addSources: Boolean, extraOptions: List = emptyList()): File { - val contentDir = KtTestUtil.tmpDirForReusableFolder("testLibrary-$jarName") - - val outDir = File(contentDir, "out") - val outputFile = File(outDir, "$jarName.js") - compileKotlin2JS(sourcesPath, outputFile, extraOptions) - - return createJarFile(contentDir, outDir, jarName, sourcesPath.takeIf { addSources }) - } - @JvmStatic fun createJarFile(contentDir: File, dirToAdd: File, jarName: String, sourcesPath: String? = null): File { val jarFile = File(contentDir, "$jarName.jar") @@ -214,10 +203,6 @@ object MockLibraryUtil { runJvmCompiler(args) } - private fun compileKotlin2JS(sourcesPath: String, outputFile: File, extraOptions: List) { - runJsCompiler(listOf("-meta-info", "-output", outputFile.absolutePath, sourcesPath, *extraOptions.toTypedArray())) - } - fun compileKotlinModule(buildFilePath: String) { runJvmCompiler(listOf("-no-stdlib", "-Xbuild-file", buildFilePath)) } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/AnalysisHandlerExtensionTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/AnalysisHandlerExtensionTest.kt index 9d9c54ffd5450..17d50449c5c44 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/AnalysisHandlerExtensionTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/AnalysisHandlerExtensionTest.kt @@ -11,9 +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 import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar @@ -67,17 +65,10 @@ class AnalysisHandlerExtensionTest : TestCaseWithTmpdir() { } val plugin = writePlugin(klass) val args = listOf("-Xplugin=$plugin", mainKt.absolutePath) - val outputPath = if (compiler is K2JSCompiler) - listOf( - "-Xforce-deprecated-legacy-compiler-usage", - "-language-version", "1.9", - "-output", tmpdir.resolve("out.js").absolutePath - ) - else - listOf( - "-language-version", "1.9", - "-d", tmpdir.resolve("out").absolutePath - ) + val outputPath = listOf( + "-language-version", "1.9", + "-d", tmpdir.resolve("out").absolutePath + ) val (output, exitCode) = CompilerTestUtil.executeCompiler(compiler, args + outputPath + extras) assertEquals(expectedExitCode, exitCode, output) @@ -87,10 +78,6 @@ class AnalysisHandlerExtensionTest : TestCaseWithTmpdir() { runTest(K2JVMCompiler(), classNotFound, CustomComponentRegistrar::class) } - fun testShouldNotGenerateCodeJS() { - runTest(K2JSCompiler(), classNotFound, CustomComponentRegistrar::class) - } - fun testShouldNotGenerateCodeMetadata() { runTest(K2MetadataCompiler(), classNotFound, CustomComponentRegistrar::class) } @@ -99,10 +86,6 @@ class AnalysisHandlerExtensionTest : TestCaseWithTmpdir() { runTest(K2JVMCompiler(), repeatedAnalysis, CustomComponentRegistrar::class) } - fun testRepeatedAnalysisJS() { - runTest(K2JSCompiler(), repeatedAnalysis, CustomComponentRegistrar::class) - } - fun testRepeatedAnalysisMetadata() { runTest(K2MetadataCompiler(), repeatedAnalysis, CustomComponentRegistrar::class) } diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt index a80f085d29087..7a15bc42e0cf2 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt @@ -121,7 +121,7 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo when (compiler) { is K2JSCompiler -> compileJsLibrary( libraryName, - additionalOptions = libraryOptions + "-Xforce-deprecated-legacy-compiler-usage" + additionalOptions = libraryOptions ) is K2JVMCompiler -> compileLibrary(libraryName, additionalOptions = libraryOptions) else -> throw UnsupportedOperationException(compiler.toString())