Skip to content

Commit 4dd0a6c

Browse files
Remove JS Legacy configurations (updated) (#296)
* JS Legacy build configurations as well as JS Legacy test projects were conditionally removed for KGP version >= 1.9.0 Co-authored-by: Stanislav Ruban <[email protected]>
1 parent 0f801b3 commit 4dd0a6c

File tree

5 files changed

+97
-71
lines changed

5 files changed

+97
-71
lines changed

atomicfu-gradle-plugin/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import static KotlinVersion.*
6+
57
apply plugin: 'kotlin'
68
apply plugin: 'java-gradle-plugin'
79

@@ -89,3 +91,10 @@ task createClasspathManifest {
8991
dependencies {
9092
testRuntime files(createClasspathManifest)
9193
}
94+
95+
// Skip these tests if Kotlin version >= 1.9.0, as JS Legacy is no longer supported there
96+
if (isKotlinVersionAtLeast(ext.kotlin_version, 1, 9)) {
97+
test {
98+
exclude "**/JsLegacyTransformationTest*", "**/MppLegacyTransformationTest*"
99+
}
100+
}

atomicfu-transformer/src/main/kotlin/kotlinx/atomicfu/transformer/MetadataTransformer.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class MetadataTransformer(
2424
fun transformMetadata(metadataAnnotation: AnnotationNode): Boolean {
2525
val map = metadataAnnotation.asMap()
2626
val hdr = KotlinClassHeader(
27-
kind = map["k"] as Int?,
28-
metadataVersion = (map["mv"] as? List<Int>)?.toIntArray(),
29-
data1 = (map["d1"] as? List<String>)?.toTypedArray(),
30-
data2 = (map["d2"] as? List<String>)?.toTypedArray(),
31-
extraString = map["xs"] as String?,
32-
packageName = map["pn"] as String?,
33-
extraInt = map["xi"] as Int?
27+
map["k"] as Int?,
28+
(map["mv"] as? List<Int>)?.toIntArray(),
29+
(map["d1"] as? List<String>)?.toTypedArray(),
30+
(map["d2"] as? List<String>)?.toTypedArray(),
31+
map["xs"] as String?,
32+
map["pn"] as String?,
33+
map["xi"] as Int?
3434
)
3535
val result = when (val metadata = KotlinClassMetadata.read(hdr)) {
3636
is KotlinClassMetadata.Class -> {
@@ -54,8 +54,8 @@ class MetadataTransformer(
5454
result.apply {
5555
with (metadataAnnotation) {
5656
// read resulting header & update annotation data
57-
setKey("d1", header.data1.toList())
58-
setKey("d2", header.data2.toList())
57+
setKey("d1", annotationData.data1.toList())
58+
setKey("d2", annotationData.data2.toList())
5959
}
6060
}
6161
return true // transformed

atomicfu/build.gradle

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import static KotlinVersion.*
6+
57
apply plugin: 'kotlin-multiplatform'
68
apply from: rootProject.file("gradle/targets.gradle")
79

@@ -17,6 +19,10 @@ ext {
1719
}
1820
}
1921

22+
// TODO: this block should be removed when Kotlin version is updated to 1.9.0
23+
// (right now it implements a toggle between IR and BOTH JS compiler types for testing of Kotlin dev builds)
24+
def isJsLegacyCompilerEnabled = !isKotlinVersionAtLeast(ext.kotlin_version, 1, 9)
25+
2026
kotlin {
2127
targets {
2228
delegate.metaClass.addTarget = { preset ->
@@ -25,7 +31,10 @@ kotlin {
2531
}
2632

2733
// JS -- always
28-
js {
34+
// TODO: JS compiler should be switched to IR-only when Kotlin version is updated to 1.9.0
35+
// (right now compiler type is chosen conditionally for testing of Kotlin dev builds)
36+
def jsCompiler = isJsLegacyCompilerEnabled ? BOTH : IR
37+
js(jsCompiler) {
2938
moduleName = "kotlinx-atomicfu"
3039
// TODO: Commented out because browser tests do not work on TeamCity
3140
// browser()
@@ -153,63 +162,68 @@ dependencies {
153162
transformer project(":atomicfu-transformer")
154163
}
155164

156-
// ==== CONFIGURE JS =====
157-
158-
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
159-
? compileKotlinJsLegacy
160-
: compileKotlinJs
165+
// TODO: This JS Legacy configuration should be removed when Kotlin version is updated to 1.9.0,
166+
// (right now configurations are removed conditionally for testing of Kotlin 1.9.0-dev builds)
167+
if (isJsLegacyCompilerEnabled) {
161168

162-
tasks.withType(compileJsLegacy.getClass()) {
163-
kotlinOptions {
164-
moduleKind = "umd"
165-
sourceMap = true
166-
metaInfo = true
167-
}
168-
}
169+
// ==== CONFIGURE JS =====
169170

170-
apply from: file("$rootProject.projectDir/gradle/node-js.gradle")
171-
apply from: file("$rootProject.projectDir/gradle/publish-npm-js.gradle")
171+
def compileJsLegacy = tasks.hasProperty("compileKotlinJsLegacy")
172+
? compileKotlinJsLegacy.getClass()
173+
: compileKotlinJs.getClass()
172174

173-
// Workaround the problem with Node downloading
174-
repositories.whenObjectAdded {
175-
if (it instanceof IvyArtifactRepository) {
176-
metadataSources {
177-
artifact()
175+
tasks.withType(compileJsLegacy).configureEach {
176+
kotlinOptions {
177+
moduleKind = "umd"
178+
sourceMap = true
179+
metaInfo = true
178180
}
179181
}
180-
}
181182

182-
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
183-
? compileTestKotlinJsLegacy
184-
: compileTestKotlinJs
183+
apply from: file("$rootProject.projectDir/gradle/node-js.gradle")
184+
apply from: file("$rootProject.projectDir/gradle/publish-npm-js.gradle")
185185

186-
def transformedJsFile = compileTestJsLegacy.kotlinOptions.outputFile
187-
compileTestJsLegacy.configure {
188-
kotlinOptions {
189-
// NOTE: Module base-name must be equal to the package name declared in package.json
190-
def baseName = "kotlinx-atomicfu"
191-
outputFile = new File(new File(outputFile).parent, baseName + ".js")
186+
// Workaround the problem with Node downloading
187+
repositories.whenObjectAdded {
188+
if (it instanceof IvyArtifactRepository) {
189+
metadataSources {
190+
artifact()
191+
}
192+
}
192193
}
193-
}
194-
def originalJsFile = compileTestJsLegacy.kotlinOptions.outputFile
195194

196-
task transformJS(type: JavaExec, dependsOn: [compileTestJsLegacy]) {
197-
main = "kotlinx.atomicfu.transformer.AtomicFUTransformerJSKt"
198-
args = [originalJsFile, transformedJsFile]
199-
classpath = configurations.transformer
200-
inputs.file(originalJsFile)
201-
outputs.file(transformedJsFile)
202-
}
195+
def compileTestJsLegacy = tasks.hasProperty("compileTestKotlinJsLegacy")
196+
? compileTestKotlinJsLegacy
197+
: compileTestKotlinJs
203198

204-
if (project.tasks.findByName('jsLegacyNodeTest')) {
205-
jsLegacyNodeTest.dependsOn transformJS
206-
jsLegacyNodeTest.configure {
207-
inputFileProperty.set(new File(transformedJsFile))
199+
def transformedJsFile = compileTestJsLegacy.kotlinOptions.outputFile
200+
compileTestJsLegacy.configure {
201+
kotlinOptions {
202+
// NOTE: Module base-name must be equal to the package name declared in package.json
203+
def baseName = "kotlinx-atomicfu"
204+
outputFile = new File(new File(outputFile).parent, baseName + ".js")
205+
}
208206
}
209-
} else {
210-
jsNodeTest.dependsOn transformJS
211-
jsNodeTest.configure {
212-
inputFileProperty.set(new File(transformedJsFile))
207+
def originalJsFile = compileTestJsLegacy.kotlinOptions.outputFile
208+
209+
task transformJS(type: JavaExec, dependsOn: [compileTestJsLegacy]) {
210+
main = "kotlinx.atomicfu.transformer.AtomicFUTransformerJSKt"
211+
args = [originalJsFile, transformedJsFile]
212+
classpath = configurations.transformer
213+
inputs.file(originalJsFile)
214+
outputs.file(transformedJsFile)
215+
}
216+
217+
if (project.tasks.findByName('jsLegacyNodeTest')) {
218+
jsLegacyNodeTest.dependsOn transformJS
219+
jsLegacyNodeTest.configure {
220+
inputFileProperty.set(new File(transformedJsFile))
221+
}
222+
} else {
223+
jsNodeTest.dependsOn transformJS
224+
jsNodeTest.configure {
225+
inputFileProperty.set(new File(transformedJsFile))
226+
}
213227
}
214228
}
215229

@@ -276,19 +290,11 @@ transformedTestVH.onlyIf {
276290
JavaVersion.current().ordinal() >= JavaVersion.VERSION_1_9.ordinal()
277291
}
278292

279-
task testAtomicfuReferenceJs(type: Test, dependsOn: [compileTestKotlinJvm, transformJS]) {
280-
environment "transformedJsFile", transformedJsFile
281-
classpath = files(configurations.jvmTestRuntimeClasspath, classesPreAtomicFuDir)
282-
testClassesDirs = project.files(classesPreAtomicFuDir)
283-
include '**/AtomicfuReferenceJsTest.*'
284-
filter { setFailOnNoMatchingTests(false) }
285-
}
286-
287293
task jvmTestAll(dependsOn: [
288-
transformedTestFU_current,
289-
transformedTestBOTH_current,
290-
transformedTestVH,
291-
testAtomicfuReferenceJs])
294+
transformedTestFU_current,
295+
transformedTestBOTH_current,
296+
transformedTestVH
297+
])
292298

293299
tasks.withType(Test) {
294300
testLogging {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@file:JvmName("KotlinVersion")
2+
3+
fun isKotlinVersionAtLeast(kotlinVersion: String, atLeastMajor: Int, atLeastMinor: Int): Boolean {
4+
val (major, minor) = kotlinVersion
5+
.split('.')
6+
.take(2)
7+
.map { it.toInt() }
8+
return when {
9+
major > atLeastMajor -> true
10+
major < atLeastMajor -> false
11+
else -> minor >= atLeastMinor
12+
}
13+
}

gradle.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ kotlin_version=1.8.10
1010
asm_version=9.3
1111
slf4j_version=1.8.0-alpha2
1212
junit_version=4.12
13-
kotlinx_metadata_version=0.5.0
13+
kotlinx_metadata_version=0.6.0
1414

1515
maven_version=3.5.3
1616

@@ -25,8 +25,6 @@ source_map_support_version=0.5.3
2525
kotlin.incremental.multiplatform=true
2626
kotlin.native.ignoreDisabledTargets=true
2727

28-
kotlin.js.compiler=both
29-
3028
kotlin.mpp.enableCompatibilityMetadataVariant=true
3129
kotlin.mpp.enableCInteropCommonization=true
3230

0 commit comments

Comments
 (0)