Skip to content

Commit

Permalink
Add -Xvalue-classes to all targets, and unifies JS building to work w…
Browse files Browse the repository at this point in the history
…ith Kotlin 1.8.0 and 1.8.20 due to DSL (#1272)

* Add -Xvalue-classes to all targets, and unifies JS building to work with Kotlin 1.8.0 and 1.8.20 due to DSL

* Configure JS browser tests with karma.config.d to fix issues
  • Loading branch information
soywiz authored Feb 3, 2023
1 parent 1c2efd6 commit 7a31e30
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ open class KorgeGradlePlugin : Plugin<Project> {
//TODO PABLO changed to have the android tasks enabled again
KorgeGradleApply(project).apply(includeIndirectAndroid = true)

//for (res in project.getResourcesFolders()) println("- $res")
//for (res in project.getResourcesFolders()) println("- $res")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.soywiz.korge.gradle.targets.all

import com.soywiz.korlibs.*
import org.gradle.api.*
import org.jetbrains.kotlin.gradle.dsl.*

fun Project.rootEnableFeaturesOnAllTargets() {
rootProject.subprojectsThis {
enableFeaturesOnAllTargets()
}
}

fun Project.enableFeaturesOnAllTargets() {
if (extensions.findByType(KotlinMultiplatformExtension::class.java) != null) {
kotlin.targets.configureEach { target ->
target.compilations.configureEach { compilation ->
//println("initAllTargets: $target - $compilation")
compilation.compilerOptions.options.suppressWarnings.set(true)
compilation.compilerOptions.options.freeCompilerArgs.add("-Xvalue-classes")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import java.io.*

private object JavaScriptClass
Expand All @@ -31,11 +32,6 @@ fun Project.configureJavaScript() {
js(KotlinJsCompilerType.IR) {
browser {
binaries.executable()
testTask {
useKarma {
useChromeHeadless()
}
}
}

this.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
Expand All @@ -48,6 +44,7 @@ fun Project.configureJavaScript() {
suppressWarnings = korge.supressWarnings
}
}
configureJSTestsOnce()
}

sourceSets.maybeCreate("jsTest").apply {
Expand Down Expand Up @@ -84,6 +81,27 @@ fun Project.configureJavaScript() {
configureClosureCompiler()
}

fun KotlinJsTargetDsl.configureJSTestsOnce() {
browser {
//testTask { useKarma { useChromeHeadless() } }
testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure {
it.useKarma {
useChromeHeadless()
val karmaConfigDFile = File(project.rootProject.rootDir, "karma.config.d")
if (karmaConfigDFile.exists()) {
useConfigDirectory(karmaConfigDFile)
}
}
}
}
nodejs {
//testTask { useMocha() }
testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure {
it.useMocha()
}
}
}

abstract class JsCreateIndexTask : DefaultTask() {
@get:InputFiles lateinit var resourcesFolders: List<File>
//@get:OutputDirectory lateinit var targetDir: File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import com.android.build.gradle.*
import com.android.build.gradle.internal.tasks.*
import com.soywiz.korge.gradle.*
import com.soywiz.korge.gradle.targets.*
import com.soywiz.korge.gradle.targets.all.*
import com.soywiz.korge.gradle.targets.android.*
import com.soywiz.korge.gradle.targets.ios.*
import com.soywiz.korge.gradle.targets.js.*
import com.soywiz.korge.gradle.targets.jvm.*
import com.soywiz.korge.gradle.targets.native.*
import com.soywiz.korge.gradle.util.*
Expand All @@ -30,6 +32,7 @@ import org.jetbrains.kotlin.gradle.tasks.*
import java.io.*
import java.net.*
import java.nio.file.*
import kotlin.apply

object RootKorlibsPlugin {
@JvmStatic
Expand Down Expand Up @@ -61,6 +64,13 @@ object RootKorlibsPlugin {
initShortcuts()
initTests()
initCrossTests()
initAllTargets()
}

fun Project.initAllTargets() {
rootProject.afterEvaluate {
rootProject.rootEnableFeaturesOnAllTargets()
}
}

fun Project.initRootKotlinJvmTarget() {
Expand Down Expand Up @@ -670,8 +680,8 @@ object RootKorlibsPlugin {
jvm {
compilations.allThis {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.suppressWarnings = true
kotlinOptions.freeCompilerArgs = listOf("-Xno-param-assertions")
compilerOptions.options.freeCompilerArgs.add("-Xno-param-assertions")
//kotlinOptions.freeCompilerArgs.add("-Xno-param-assertions")
//kotlinOptions.

// @TODO:
Expand All @@ -685,21 +695,13 @@ object RootKorlibsPlugin {
browser {
compilations.allThis {
//kotlinOptions.sourceMap = true
kotlinOptions.suppressWarnings = true
}
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory(File(rootDir, "karma.config.d"))
}
}
}
nodejs {
testTask {
useMocha()
}
}
configureJSTestsOnce()
}
//configureJSTests()


if (hasAndroid) {
kotlin {
android {
Expand All @@ -708,8 +710,7 @@ object RootKorlibsPlugin {
//this.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
compilations.allThis {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.suppressWarnings = true
kotlinOptions.freeCompilerArgs = listOf("-Xno-param-assertions")
compilerOptions.options.freeCompilerArgs.add("-Xno-param-assertions")
}
}
}
Expand Down Expand Up @@ -1061,9 +1062,9 @@ object RootKorlibsPlugin {
dependsOn(compileDevelopmentExecutableKotlinJs)
//task.dependsOn(browserPrepareEsbuild)

val jsPath = project.tasks.getByName(compileDevelopmentExecutableKotlinJs).outputs.files.first {
val jsPath = project.tasks.getByName(compileDevelopmentExecutableKotlinJs).outputs.files.firstOrNull() {
it.extension.toLowerCase() == "js"
}
} ?: "unknown-js.js"

val output = File(wwwFolder, "${project.name}.js")
inputs.file(jsPath)
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/com/soywiz/korlibs/tools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ fun Project.doOnce(uniqueName: String, block: () -> Unit) {
}
}

fun Project.doOncePerProject(uniqueName: String, block: () -> Unit) {
val key = "doOnceProject-$uniqueName"
if (!project.extra.has(key)) {
project.extra.set(key, true)
block()
}
}

fun currentJavaVersion(): Int {
val versionElements = System.getProperty("java.version").split("\\.".toRegex()).toTypedArray() + arrayOf("-1", "-1")
val discard = versionElements[0].toInt()
Expand Down

0 comments on commit 7a31e30

Please sign in to comment.