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+
57apply plugin : ' kotlin-multiplatform'
68apply from : rootProject. file(" gradle/targets.gradle" )
79
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+
2026kotlin {
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-
287293task jvmTestAll (dependsOn : [
288- transformedTestFU_current,
289- transformedTestBOTH_current,
290- transformedTestVH,
291- testAtomicfuReferenceJs ])
294+ transformedTestFU_current,
295+ transformedTestBOTH_current,
296+ transformedTestVH
297+ ])
292298
293299tasks. withType(Test ) {
294300 testLogging {
0 commit comments