[JS] Removing usage of legacy JS compiler #1

This commit is contained in:
Ilya Goncharov
2023-11-28 13:44:37 +00:00
committed by Space Team
parent 662bff7351
commit 093f51c89a
7 changed files with 15 additions and 45 deletions
+4 -2
View File
@@ -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
@@ -6,14 +6,12 @@
<mkdir dir="${temp.library.path}"/>
<kotlin2js src="${library.path}" output="${temp.library.path}/jslib-example.js" metaInfo="true">
<compilerarg value="-Xforce-deprecated-legacy-compiler-usage"/>
</kotlin2js>
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
<libraries>
<pathelement path="${temp.library.path}/jslib-example.meta.js"/>
</libraries>
<compilerarg value="-Xforce-deprecated-legacy-compiler-usage"/>
</kotlin2js>
<copy todir="${temp}">
<fileset dir="${temp.library.path}">
@@ -13,7 +13,6 @@
<libraries>
<pathelement path="${temp.library.path}"/>
</libraries>
<compilerarg value="-Xforce-deprecated-legacy-compiler-usage"/>
</kotlin2js>
<copy todir="${temp}">
<fileset dir="${temp.library.path}">
@@ -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<TestFile>) {
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<File> = 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
@@ -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<String> = 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<String>) {
runJsCompiler(listOf("-meta-info", "-output", outputFile.absolutePath, sourcesPath, *extraOptions.toTypedArray()))
}
fun compileKotlinModule(buildFilePath: String) {
runJvmCompiler(listOf("-no-stdlib", "-Xbuild-file", buildFilePath))
}
@@ -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)
}
@@ -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())