[JS] Migrate tests onto IR compiler with outputDir API instead of outputFile

^KT-61117 fixed
This commit is contained in:
Ilya Goncharov
2023-11-29 11:21:56 +00:00
committed by Space Team
parent e50f6e6bca
commit 08e3cb300a
38 changed files with 208 additions and 201 deletions
@@ -181,10 +181,12 @@ private fun readV2AndLaterConfig(
}
productionOutputPath = element.getChild("productionOutputPath")?.let {
(it.content.firstOrNull() as? Text)?.textTrim?.let(FileUtilRt::toSystemDependentName)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputDir
?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
testOutputPath = element.getChild("testOutputPath")?.let {
(it.content.firstOrNull() as? Text)?.textTrim?.let(FileUtilRt::toSystemDependentName)
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
} ?: (compilerArguments as? K2JSCompilerArguments)?.outputDir
?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
}
}
@@ -239,7 +241,7 @@ fun CommonCompilerArguments.convertPathsToSystemIndependent() {
}
is K2JSCompilerArguments -> {
outputFile = outputFile?.let(FileUtilRt::toSystemIndependentName)
outputDir = (outputDir ?: outputFile)?.let(FileUtilRt::toSystemIndependentName)
libraries = libraries?.let(FileUtilRt::toSystemIndependentName)
}
@@ -354,14 +356,16 @@ private fun KotlinFacetSettings.writeConfig(element: Element) {
if (pureKotlinSourceFolders.isNotEmpty()) {
element.setAttribute("pureKotlinSourceFolders", pureKotlinSourceFolders.joinToString(";"))
}
productionOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
(compilerArguments as? K2JSCompilerArguments)?.let { compilerArguments ->
productionOutputPath?.let {
if (it != compilerArguments.outputDir && it != compilerArguments.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
}
}
}
testOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("testOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
testOutputPath?.let {
if (it != compilerArguments.outputDir && it != compilerArguments.outputFile) {
element.addContent(Element("testOutputPath").apply { addContent(FileUtilRt.toSystemIndependentName(it)) })
}
}
}
compilerSettings?.copyOf()?.let {
@@ -237,7 +237,8 @@ class CompilerArgumentsContentProspectorTest {
K2JSCompilerArguments::wasm
)
private val k2JSCompilerArgumentsStringProperties = commonCompilerArgumentsStringProperties + listOf(
K2JSCompilerArguments::outputFile,
K2JSCompilerArguments::outputDir,
K2JSCompilerArguments::moduleName,
K2JSCompilerArguments::libraries,
K2JSCompilerArguments::sourceMapPrefix,
K2JSCompilerArguments::sourceMapBaseDirs,
@@ -99,9 +99,6 @@ abstract class AbstractJvmLookupTrackerTest : AbstractLookupTrackerTest() {
}
abstract class AbstractJsKlibLookupTrackerTest : AbstractJsLookupTrackerTest() {
override val jsStdlibFile: File
get() = File(System.getProperty("jps.testData.js-ir-runtime") ?: "build/js-ir-runtime/full-runtime.klib")
override fun configureAdditionalArgs(args: K2JSCompilerArguments) {
args.irProduceKlibDir = true
args.irOnly = true
@@ -157,7 +154,6 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
get() = PathUtil.kotlinPathsForDistDirectoryForTests.jsStdLibKlibPath
protected open fun configureAdditionalArgs(args: K2JSCompilerArguments) {
args.outputFile = File(outDir, "out.js").canonicalPath
}
override fun runCompiler(filesToCompile: Iterable<File>, env: JpsCompilerEnvironment): Any? {
@@ -166,7 +162,6 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
libraries = libPaths.joinToString(File.pathSeparator)
reportOutputFiles = true
freeArgs = filesToCompile.map { it.canonicalPath }
forceDeprecatedLegacyCompilerUsage = true
useFirLT = false
}
configureAdditionalArgs(args)
@@ -90,9 +90,7 @@ abstract class KotlinJpsBuildTestBase : AbstractKotlinJpsBuildTestCase() {
protected fun setupKotlinJSFacet() {
myProject.modules.forEach {
val facet = KotlinFacetSettings()
facet.compilerArguments = K2JSCompilerArguments().apply {
forceDeprecatedLegacyCompilerUsage = true
}
facet.compilerArguments = K2JSCompilerArguments()
facet.targetPlatform = JsPlatforms.defaultJsPlatform
it.container.setChild(
@@ -264,7 +264,6 @@ class ModulesTxtBuilder {
"js" -> settings.compilerArguments =
K2JSCompilerArguments().also {
settings.targetPlatform = JsPlatforms.defaultJsPlatform
it.forceDeprecatedLegacyCompilerUsage = true
}
"native" -> settings.compilerArguments =
K2NativeCompilerArguments().also { settings.targetPlatform = NativePlatforms.unspecifiedNativePlatform }
@@ -16,7 +16,6 @@
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
@@ -27,10 +26,15 @@ import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
import org.jetbrains.kotlin.incremental.utils.TestMessageCollector
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests
import org.jetbrains.kotlin.utils.PathUtil
import org.junit.Assert
import java.io.File
abstract class AbstractJsProtoComparisonTest : AbstractProtoComparisonTest<ProtoData>() {
protected open val jsStdlibFile: File
get() = PathUtil.kotlinPathsForDistDirectoryForTests.jsStdLibKlibPath
override fun expectedOutputFile(testDir: File): File =
File(testDir, "result-js.out")
.takeIf { it.exists() }
@@ -47,11 +51,13 @@ abstract class AbstractJsProtoComparisonTest : AbstractProtoComparisonTest<Proto
val messageCollector = TestMessageCollector()
val outputItemsCollector = OutputItemsCollectorImpl()
val args = K2JSCompilerArguments().apply {
outputFile = File(outputDir, "out.js").canonicalPath
metaInfo = true
this.outputDir = outputDir.normalize().absolutePath
moduleName = "out"
libraries = jsStdlibFile.absolutePath
irProduceKlibDir = true
irOnly = true
main = K2JsArgumentConstants.NO_CALL
freeArgs = ktFiles
forceDeprecatedLegacyCompilerUsage = true
languageVersion = "1.9"
}
@@ -343,11 +343,12 @@ class JpsKotlinCompilerRunner {
settings: K2JSCompilerArguments,
) {
with(settings) {
noStdlib = true
freeArgs = allSourceFiles.map { it.path }.toMutableList()
irProduceKlibDir = true
irOnly = true
commonSources = _commonSources.map { it.path }.toTypedArray()
outputFile = _outputFile.path
metaInfo = true
outputDir = _outputFile.parent
moduleName = _outputFile.nameWithoutExtension
libraries = _libraries.joinToString(File.pathSeparator)
friendModules = _friendModules.joinToString(File.pathSeparator)
}
@@ -22,10 +22,9 @@ import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.jps.incremental.storage.BuildDataManager
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import org.jetbrains.kotlin.jps.build.KotlinBuilder
import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget
import org.jetbrains.kotlin.serialization.js.JsSerializerProtocol
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
import java.io.File
interface JpsIncrementalCache : IncrementalCacheCommon, StorageOwner {
@@ -52,7 +51,7 @@ class JpsIncrementalJsCache(
target: ModuleBuildTarget,
paths: BuildDataPaths,
icContext: IncrementalCompilationContext
) : IncrementalJsCache(paths.getTargetDataRoot(target), icContext, JsSerializerProtocol), JpsIncrementalCache {
) : IncrementalJsCache(paths.getTargetDataRoot(target), icContext, KlibMetadataSerializerProtocol), JpsIncrementalCache {
override fun addJpsDependentCache(cache: JpsIncrementalCache) {
if (cache is JpsIncrementalJsCache) {
addDependentCache(cache)
@@ -1,10 +1,10 @@
PROTO DIFFERENCE in test/AnnotationAdded: JS_EXT_CLASS_ANNOTATION_LIST
PROTO DIFFERENCE in test/AnnotationAdded: KLIB_EXT_CLASS_ANNOTATION_LIST
CHANGES in test/AnnotationAdded: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AnnotationListBecomeEmpty: FLAGS, JS_EXT_CLASS_ANNOTATION_LIST
PROTO DIFFERENCE in test/AnnotationListBecomeEmpty: FLAGS, KLIB_EXT_CLASS_ANNOTATION_LIST
CHANGES in test/AnnotationListBecomeEmpty: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AnnotationListBecomeNotEmpty: FLAGS, JS_EXT_CLASS_ANNOTATION_LIST
PROTO DIFFERENCE in test/AnnotationListBecomeNotEmpty: FLAGS, KLIB_EXT_CLASS_ANNOTATION_LIST
CHANGES in test/AnnotationListBecomeNotEmpty: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AnnotationRemoved: JS_EXT_CLASS_ANNOTATION_LIST
PROTO DIFFERENCE in test/AnnotationRemoved: KLIB_EXT_CLASS_ANNOTATION_LIST
CHANGES in test/AnnotationRemoved: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AnnotationReplaced: JS_EXT_CLASS_ANNOTATION_LIST
PROTO DIFFERENCE in test/AnnotationReplaced: KLIB_EXT_CLASS_ANNOTATION_LIST
CHANGES in test/AnnotationReplaced: CLASS_SIGNATURE
@@ -2,10 +2,10 @@ PROTO DIFFERENCE in test/AbstractFlagAdded: FLAGS
CHANGES in test/AbstractFlagAdded: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AbstractFlagRemoved: FLAGS
CHANGES in test/AbstractFlagRemoved: CLASS_SIGNATURE
PROTO DIFFERENCE in test/AnnotationFlagAdded: FLAGS, SUPERTYPE_LIST
PROTO DIFFERENCE in test/AnnotationFlagAdded: FLAGS, SUPERTYPE_ID_LIST
CHANGES in test/AnnotationFlagAdded: CLASS_SIGNATURE, PARENTS
[kotlin.Annotation, kotlin.Any]
PROTO DIFFERENCE in test/AnnotationFlagRemoved: FLAGS, SUPERTYPE_LIST
PROTO DIFFERENCE in test/AnnotationFlagRemoved: FLAGS, SUPERTYPE_ID_LIST
CHANGES in test/AnnotationFlagRemoved: CLASS_SIGNATURE, PARENTS
[kotlin.Annotation, kotlin.Any]
PROTO DIFFERENCE in test/DataFlagAdded: FLAGS, FUNCTION_LIST
@@ -14,10 +14,10 @@ CHANGES in test/DataFlagAdded: CLASS_SIGNATURE, MEMBERS
PROTO DIFFERENCE in test/DataFlagRemoved: FLAGS, FUNCTION_LIST
CHANGES in test/DataFlagRemoved: CLASS_SIGNATURE, MEMBERS
[component1, copy, equals, hashCode, toString]
PROTO DIFFERENCE in test/EnumFlagAdded: CONSTRUCTOR_LIST, FLAGS, SUPERTYPE_LIST
PROTO DIFFERENCE in test/EnumFlagAdded: CONSTRUCTOR_LIST, FLAGS, SUPERTYPE_ID_LIST
CHANGES in test/EnumFlagAdded: CLASS_SIGNATURE, PARENTS
[kotlin.Any, kotlin.Enum]
PROTO DIFFERENCE in test/EnumFlagRemoved: CONSTRUCTOR_LIST, FLAGS, SUPERTYPE_LIST
PROTO DIFFERENCE in test/EnumFlagRemoved: CONSTRUCTOR_LIST, FLAGS, SUPERTYPE_ID_LIST
CHANGES in test/EnumFlagRemoved: CLASS_SIGNATURE, PARENTS
[kotlin.Any, kotlin.Enum]
PROTO DIFFERENCE in test/InnerClassHolder.InnerFlagAdded: FLAGS
@@ -0,0 +1,3 @@
PROTO DIFFERENCE in test/ClassWithSuperTypeListChanged: SUPERTYPE_ID_LIST
CHANGES in test/ClassWithSuperTypeListChanged: CLASS_SIGNATURE, PARENTS
[kotlin.Any, kotlin.Throwable]
@@ -0,0 +1,3 @@
PROTO DIFFERENCE in test/Base.Nested1.Nested2: SUPERTYPE_ID_LIST
CHANGES in test/Base.Nested1.Nested2: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base]
@@ -0,0 +1,8 @@
ADDED test/Impl11
PROTO DIFFERENCE in test/Base1: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base1: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Base2: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base2: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Impl22: SUPERTYPE_ID_LIST
CHANGES in test/Impl22: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base2]
@@ -0,0 +1,8 @@
REMOVED test/Impl11
PROTO DIFFERENCE in test/Base1: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base1: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Base2: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base2: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Impl22: SUPERTYPE_ID_LIST
CHANGES in test/Impl22: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base2]
@@ -0,0 +1,9 @@
ADDED test/Base1.Nested2
PROTO DIFFERENCE in test/Base1: NESTED_CLASS_NAME_LIST, SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base1: CLASS_SIGNATURE, MEMBERS
[Nested2]
PROTO DIFFERENCE in test/Base2: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base2: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Base2.Nested2: SUPERTYPE_ID_LIST
CHANGES in test/Base2.Nested2: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base2]
@@ -0,0 +1,13 @@
ADDED test/Base1.Nested1.Nested2.Nested3
ADDED test/Base2.Nested1.Nested3
PROTO DIFFERENCE in test/Base1.Nested1.Nested2: NESTED_CLASS_NAME_LIST, SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base1.Nested1.Nested2: CLASS_SIGNATURE, MEMBERS
[Nested3]
PROTO DIFFERENCE in test/Base2.Nested1: NESTED_CLASS_NAME_LIST, SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base2.Nested1: CLASS_SIGNATURE, MEMBERS
[Nested3]
PROTO DIFFERENCE in test/Base3.Nested1: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base3.Nested1: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Base3.Nested1.Nested2: SUPERTYPE_ID_LIST
CHANGES in test/Base3.Nested1.Nested2: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base3.Nested1]
@@ -0,0 +1,9 @@
REMOVED test/Base1.Nested2
PROTO DIFFERENCE in test/Base1: NESTED_CLASS_NAME_LIST, SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base1: CLASS_SIGNATURE, MEMBERS
[Nested2]
PROTO DIFFERENCE in test/Base2: SEALED_SUBCLASS_FQ_NAME_LIST
CHANGES in test/Base2: CLASS_SIGNATURE
PROTO DIFFERENCE in test/Base2.Nested2: SUPERTYPE_ID_LIST
CHANGES in test/Base2.Nested2: CLASS_SIGNATURE, PARENTS
[kotlin.Any, test.Base2]
@@ -1,7 +1,4 @@
c [sourceSetHolder]
pJvm [compilationAndSourceSetHolder, jvm]
pJvm -> c [include]
pJs [compilationAndSourceSetHolder, js]
pJs -> c [include]
pJvm -> c [include]
@@ -1,34 +1,6 @@
================ Step #1 make compilation fail =================
Building c
Building pJs
Cleaning output files:
out/production/pJs/pJs.js
out/production/pJs/pJs.meta.js
out/production/pJs/pJs/root-package.kjsm
End of files
Complementary files. Marked as dirty by Kotlin:
pJs/src/fJs.kt
Compiling files:
c/src/f.kt
pJs/src/fJs.kt
End of files
Exit code: ABORT
------------------------------------------
COMPILATION FAILED
[pJs] Expecting a top level declaration
[pJs] Expecting a top level declaration
================ Step #2 fix error =================
Building c
Building pJs
Compiling files:
c/src/f.kt
pJs/src/fJs.kt
End of files
Exit code: OK
------------------------------------------
Building pJvm
Cleaning output files:
out/production/pJvm/META-INF/pJvm.kotlin_module
@@ -42,5 +14,17 @@ Compiling files:
c/src/f.kt
pJvm/src/fJvm.kt
End of files
Exit code: ABORT
------------------------------------------
COMPILATION FAILED
================ Step #2 fix error =================
Building c
Building pJvm
Compiling files:
c/src/f.kt
pJvm/src/fJvm.kt
End of files
Exit code: OK
------------------------------------------
@@ -1,7 +1,4 @@
c [sourceSetHolder]
pJvm [compilationAndSourceSetHolder, jvm]
pJvm -> c [include]
pJs [compilationAndSourceSetHolder, js]
pJs -> c [include]
pJvm -> c [include]
@@ -1,41 +1,6 @@
================ Step #1 make compilation fail =================
Building c
Building pJs
Cleaning output files:
out/production/pJs/pJs.js
out/production/pJs/pJs.meta.js
out/production/pJs/pJs/root-package.kjsm
End of files
Complementary files. Marked as dirty by Kotlin:
c/src/g.kt
pJs/src/fg.kt
Compiling files:
c/src/f.kt
c/src/g.kt
pJs/src/fg.kt
End of files
Exit code: ABORT
------------------------------------------
COMPILATION FAILED
[pJs] Expecting a top level declaration
[pJs] Expecting a top level declaration
================ Step #2 fix error =================
Building c
Building pJs
Complementary files. Marked as dirty by Kotlin:
c/src/g.kt
Compiling files:
c/src/f.kt
c/src/g.kt
pJs/src/fg.kt
End of files
Exit code: OK
------------------------------------------
ChunkBuildStarted. Marked as dirty by Kotlin:
c/src/g.kt
Building pJvm
Cleaning output files:
out/production/pJvm/META-INF/pJvm.kotlin_module
@@ -51,5 +16,20 @@ Compiling files:
c/src/g.kt
pJvm/src/fg.kt
End of files
Exit code: ABORT
------------------------------------------
COMPILATION FAILED
================ Step #2 fix error =================
Building c
Building pJvm
Complementary files. Marked as dirty by Kotlin:
c/src/g.kt
Compiling files:
c/src/f.kt
c/src/g.kt
pJvm/src/fg.kt
End of files
Exit code: OK
------------------------------------------