diff options
Diffstat (limited to 'atomicfu/build.gradle')
-rw-r--r-- | atomicfu/build.gradle | 125 |
1 files changed, 85 insertions, 40 deletions
diff --git a/atomicfu/build.gradle b/atomicfu/build.gradle index 66cfcb8..063c9a3 100644 --- a/atomicfu/build.gradle +++ b/atomicfu/build.gradle @@ -18,12 +18,15 @@ ext { } kotlin { - targets.metaClass.addTarget = { preset -> - addNative(delegate.fromPreset(preset, preset.name)) + targets { + delegate.metaClass.addTarget = { preset -> + addNative(delegate.fromPreset(preset, preset.name)) + } } // JS -- always js { + moduleName = "kotlinx-atomicfu" // TODO: Commented out because browser tests do not work on TeamCity // browser() nodejs() @@ -89,6 +92,11 @@ if (rootProject.ext.native_targets_enabled) { addTarget(presets.watchosArm64) addTarget(presets.watchosX86) addTarget(presets.watchosX64) + + addTarget(presets.iosSimulatorArm64) + addTarget(presets.watchosSimulatorArm64) + addTarget(presets.tvosSimulatorArm64) + addTarget(presets.macosArm64) } } @@ -159,14 +167,6 @@ tasks.withType(compileJsLegacy.getClass()) { } } -compileJsLegacy.configure { - kotlinOptions { - // NOTE: Module base-name must be equal to the package name declared in package.json - def baseName = "kotlinx-atomicfu" - outputFile = new File(outputFile.parent, baseName + ".js") - } -} - apply from: file("$rootProject.projectDir/gradle/node-js.gradle") apply from: file("$rootProject.projectDir/gradle/publish-npm-js.gradle") @@ -188,7 +188,7 @@ compileTestJsLegacy.configure { kotlinOptions { // NOTE: Module base-name must be equal to the package name declared in package.json def baseName = "kotlinx-atomicfu" - outputFile = new File(outputFile.parent, baseName + ".js") + outputFile = new File(new File(outputFile).parent, baseName + ".js") } } def originalJsFile = compileTestJsLegacy.kotlinOptions.outputFile @@ -203,8 +203,14 @@ task transformJS(type: JavaExec, dependsOn: [compileTestJsLegacy]) { if (project.tasks.findByName('jsLegacyNodeTest')) { jsLegacyNodeTest.dependsOn transformJS + jsLegacyNodeTest.configure { + inputFileProperty.set(new File(transformedJsFile)) + } } else { jsNodeTest.dependsOn transformJS + jsNodeTest.configure { + inputFileProperty.set(new File(transformedJsFile)) + } } // ==== CONFIGURE JVM ===== @@ -216,7 +222,7 @@ def classesPostTransformBOTH = file("$buildDir/classes/kotlin/jvm/postTransforme tasks.withType(compileTestKotlinJvm.getClass()) { kotlinOptions { - jvmTarget = "1.6" + jvmTarget = "1.8" } } @@ -244,24 +250,6 @@ task transformVH(type: JavaExec, dependsOn: compileTestKotlinJvm) { outputs.dir(classesPostTransformVH) } -task checkJdk16() { - doLast { - if (!System.env.JDK_16) { - throw new GradleException("JDK_16 environment variable is not defined. " + - "Can't build against JDK 1.6 runtime and run JDK 1.6 compatibility tests. " + - "Please ensure JDK 1.6 is installed and that JDK_16 points to it.") - } - } -} - -task transformedTestFU_6(type: Test, dependsOn: [checkJdk16, transformFU]) { - executable = "$System.env.JDK_16/bin/java" - classpath = configurations.jvmTestRuntimeClasspath + project.files(classesPostTransformFU) - testClassesDirs = project.files(classesPostTransformFU) - exclude '**/*LFTest.*', '**/TraceToStringTest.*', '**/AtomicfuReferenceJsTest.*' - filter { setFailOnNoMatchingTests(false) } // to run excluded tests in Idea -} - task transformedTestFU_current(type: Test, dependsOn: transformFU) { classpath = files(configurations.jvmTestRuntimeClasspath, classesPostTransformFU) testClassesDirs = project.files(classesPostTransformFU) @@ -269,14 +257,6 @@ task transformedTestFU_current(type: Test, dependsOn: transformFU) { filter { setFailOnNoMatchingTests(false) } } -task transformedTestBOTH_6(type: Test, dependsOn: [checkJdk16, transformBOTH]) { - executable = "$System.env.JDK_16/bin/java" - classpath = files(configurations.jvmTestRuntimeClasspath, classesPostTransformBOTH) - testClassesDirs = project.files(classesPostTransformBOTH) - exclude '**/*LFTest.*', '**/TraceToStringTest.*', '**/TopLevelGeneratedDeclarationsReflectionTest.*', '**/SyntheticFUFieldsTest.*', '**/AtomicfuReferenceJsTest.*' - filter { setFailOnNoMatchingTests(false) } -} - task transformedTestBOTH_current(type: Test, dependsOn: transformBOTH) { classpath = files(configurations.jvmTestRuntimeClasspath, classesPostTransformBOTH) testClassesDirs = project.files(classesPostTransformBOTH) @@ -305,9 +285,7 @@ task testAtomicfuReferenceJs(type: Test, dependsOn: [compileTestKotlinJvm, trans } task jvmTestAll(dependsOn: [ - transformedTestFU_6, transformedTestFU_current, - transformedTestBOTH_6, transformedTestBOTH_current, transformedTestVH, testAtomicfuReferenceJs]) @@ -319,6 +297,72 @@ tasks.withType(Test) { } } +task compileJavaModuleInfo(type: JavaCompile) { + def moduleName = "kotlinx.atomicfu" // this module's name + def compileKotlinJvm = kotlin.targets["jvm"].compilations["main"].compileKotlinTask + def sourceDir = file("src/jvmMain/java9/") + def targetDir = compileKotlinJvm.destinationDirectory.map { it.dir("../java9/") } + + // Use a Java 11 compiler for the module info. + javaCompiler.set(project.javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(11)) }) + + // Always compile kotlin classes before the module descriptor. + dependsOn(compileKotlinJvm) + + // Add the module-info source file. + source(sourceDir) + + // Also add the module-info.java source file to the Kotlin compile task. + // The Kotlin compiler will parse and check module dependencies, + // but it currently won't compile to a module-info.class file. + // Note that module checking only works on JDK 9+, + // because the JDK built-in base modules are not available in earlier versions. + def javaVersion = compileKotlinJvm.kotlinJavaToolchain.javaVersion.getOrNull() + if (javaVersion?.isJava9Compatible() == true) { + logger.info("Module-info checking is enabled; $compileKotlinJvm is compiled using Java $javaVersion") + compileKotlinJvm.source(sourceDir) + } else { + logger.info("Module-info checking is disabled") + } + + // Set the task outputs and destination dir + outputs.dir(targetDir) + destinationDirectory.set(targetDir) + + // Configure JVM compatibility + sourceCompatibility = JavaVersion.VERSION_1_9.toString() + targetCompatibility = JavaVersion.VERSION_1_9.toString() + + // Set the Java release version. + options.release.set(9) + + // Ignore warnings about using 'requires transitive' on automatic modules. + // not needed when compiling with recent JDKs, e.g. 17 + options.compilerArgs.add("-Xlint:-requires-transitive-automatic") + + // Patch the compileKotlinJvm output classes into the compilation so exporting packages works correctly. + options.compilerArgs.addAll(["--patch-module", "$moduleName=${compileKotlinJvm.destinationDirectory.get().getAsFile()}"]) + + // Use the classpath of the compileKotlinJvm task. + // Also ensure that the module path is used instead of classpath. + classpath = compileKotlinJvm.classpath + modularity.inferModulePath.set(true) + + doFirst { + logger.warn("Task destination directory: ${destinationDirectory.get().getAsFile()}") + } +} + +// Configure the JAR task so that it will include the compiled module-info class file. +tasks.named("jvmJar") { + manifest { + attributes(["Multi-Release": true]) + } + from(compileJavaModuleInfo) { + into("META-INF/versions/9/") + } +} + jvmTest { exclude "**/AtomicfuBytecodeTest*", "**/AtomicfuReferenceJsTest*", '**/TopLevelGeneratedDeclarationsReflectionTest.*', '**/SyntheticFUFieldsTest.*' // run them only for transformed code } @@ -337,3 +381,4 @@ afterEvaluate { tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach { dependsOn(tasks["generatePomFileForJvmPublication"]) } + |