Skip to content

Commit

Permalink
[JS] Removing usage of legacy JS compiler #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic authored and qodana-bot committed Nov 28, 2023
1 parent 662bff7 commit 093f51c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 45 deletions.
6 changes: 4 additions & 2 deletions compiler/testData/cli/js/nonExistingKotlinHome.args
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 093f51c

Please sign in to comment.