Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load automatically korge.yaml, create build.gradle.kts as required and initial code for Korge Kotlin Plugin #2245

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Detect and configure new directory schema
  • Loading branch information
soywiz committed Jun 20, 2024
commit 70eafcea5d1a5339d51356def95875d6c6f12b1f
Original file line number Diff line number Diff line change
@@ -172,6 +172,10 @@ open class KorgeExtension(
}
}

fun loadYaml(file: File) {
val korgeYamlString = file.takeIfExists()?.readText() ?: return
}

internal fun implicitCheckVersion() {
checkVersion(check = true, report = false)
}
Original file line number Diff line number Diff line change
@@ -40,13 +40,18 @@ fun Project.generateKorgeProcessedFromTask(task: ProcessResources) {
val compilation = target.compilations.findByName(compilationName)
val folders: MutableList<FileCollection> = when {
compilation != null -> compilation.allKotlinSourceSets.map { it.resources.sourceDirectories }.toMutableList()
else -> arrayListOf(project.files(file("src/commonMain/resources"), file("src/${targetNameRaw}${compilationName.capitalize()}/resources")))
else -> arrayListOf(project.files(
file("resources"),
file("src/commonMain/resources"),
file("src/${targetNameRaw}${compilationName.capitalize()}/resources")
))
}

//println("PROJECT: $project : ${this.project.allDependantProjects()}")

for (subproject in this.project.allDependantProjects()) {
val files = files(
file("resources"),
subproject.file("src/commonMain/resources"),
subproject.file("src/${targetNameRaw}${compilationName.capitalize()}/resources")
)
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.createPairSourceSet(

val newVariant = if (project?.projectDir != null) !File(project.projectDir, "src/commonMain").isDirectory else false

//println("!!!!!!!!!!! newVariant=$newVariant, project?.projectDir=${project?.projectDir} isDirectory=${project?.projectDir?.get("src/commonMain")?.isDirectory}")

if (newVariant) {
if (name == "common") {
main.kotlin.srcDirs(listOf("src"))
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import korlibs.korge.gradle.*
import korlibs.korge.gradle.kotlin
import korlibs.korge.gradle.targets.*
import korlibs.korge.gradle.targets.all.*
import korlibs.korge.gradle.targets.jvm.*
import korlibs.korge.gradle.util.*
import org.gradle.api.*
import org.gradle.api.tasks.*
@@ -43,6 +44,8 @@ fun Project.configureAndroidDirect(projectType: ProjectType, isKorge: Boolean) {
AddFreeCompilerArgs.addFreeCompilerArgs(project, this)
}

ensureSourceSetsConfigure("common", "android")

//if (isKorge) {
// project.afterEvaluate {
// //println("@TODO: Info is not generated")
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package korlibs.korge.gradle.targets.ios
import korlibs.korge.gradle.*
import korlibs.korge.gradle.targets.*
import korlibs.korge.gradle.targets.desktop.*
import korlibs.korge.gradle.targets.jvm.*
import korlibs.korge.gradle.targets.native.*
import korlibs.korge.gradle.util.*
import org.gradle.api.*
@@ -16,6 +17,7 @@ import java.io.*
fun Project.configureNativeIos(projectType: ProjectType) {
configureNativeIosTvos(projectType, "ios")
configureNativeIosTvos(projectType, "tvos")
ensureSourceSetsConfigure("common", "ios", "tvos")

val exKotlinSourceSetContainer = this.project.exKotlinSourceSetContainer
this.project.kotlin.apply {
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import korlibs.korge.gradle.targets.*
import korlibs.korge.gradle.targets.windows.*
import korlibs.korge.gradle.util.*
import korlibs.*
import korlibs.korge.gradle.targets.jvm.*
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*
@@ -90,6 +91,8 @@ fun Project.configureJavaScript(projectType: ProjectType) {
configureJavascriptRun()
}
configureWebpack()

ensureSourceSetsConfigure("common", "js")
}

fun KotlinJsTargetDsl.configureJsTargetOnce() {
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package korlibs.korge.gradle.targets.js
import korlibs.korge.gradle.gkotlin
import korlibs.korge.gradle.kotlin
import korlibs.korge.gradle.targets.*
import korlibs.korge.gradle.targets.jvm.*
import korlibs.korge.gradle.targets.wasm.*
import korlibs.korge.gradle.util.*
import org.gradle.api.*
@@ -12,6 +13,7 @@ import java.io.*

fun Project.configureWasm(projectType: ProjectType, binaryen: Boolean = false) {
if (gkotlin.targets.findByName("wasm") != null) return
ensureSourceSetsConfigure("common", "wasmJs")

configureWasmTarget(executable = true, binaryen = binaryen)

Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ import java.io.*
val KORGE_RELOAD_AGENT_CONFIGURATION_NAME = "KorgeReloadAgent"
val httpPort = 22011

fun Project.ensureSourceSetsConfigure(vararg names: String) {
val sourceSets = project.kotlin.sourceSets
for (name in names) {
sourceSets.createPairSourceSet(name, project = project)
}
}

fun Project.configureJvm(projectType: ProjectType) {
if (gkotlin.targets.findByName("jvm") != null) return

@@ -51,6 +58,8 @@ fun Project.configureJvm(projectType: ProjectType) {

val jvmProcessResources = tasks.findByName("jvmProcessResources") as? Copy?
jvmProcessResources?.duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE

ensureSourceSetsConfigure("common", "jvm")
}

fun Project.configureJvmRunJvm(isRootKorlibs: Boolean) {
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import com.soywiz.kproject.model.*
import org.gradle.api.initialization.*
import java.io.*
import kotlin.collections.LinkedHashMap
import kotlin.collections.contains
import kotlin.collections.firstOrNull
import kotlin.collections.listOf
import kotlin.collections.set

/**
* Example: "git::korge-dragonbones:korlibs/korge::/korge-dragonbones::v3.2.0"
@@ -33,6 +38,9 @@ fun Settings.kproject(path: String) {
val sourceDirectory = (result.projectDir as LocalFileRef).file
//println(":$rname -> $sourceDirectory")
settings.include(":${rname}")
settings.project(":${rname}").projectDir = sourceDirectory.relativeTo(rootDir)
val project = settings.project(":${rname}")
val projectDir = sourceDirectory.relativeTo(rootDir)
project.projectDir = projectDir
//project.buildFileName = buildFileKts.relativeTo(projectDir).path
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.soywiz.kproject

import com.soywiz.kproject.util.*
import kproject
import org.gradle.api.*
import org.gradle.api.initialization.*
@@ -12,5 +13,19 @@ class KProjectSettingsPlugin : Plugin<Settings> {
if (File(settings.rootDir, "deps.kproject.yml").exists()) {
settings.kproject("./deps")
}

val projectDir = settings.rootProject.projectDir
val buildFileKts = File(projectDir, "build.gradle.kts")
val buildFileGroovy = File(projectDir, "build.gradle")
if (!buildFileKts.exists() && !buildFileGroovy.exists()) {
buildFileKts.writeTextIfNew("""
import korlibs.korge.gradle.*
plugins { alias(libs.plugins.korge) }
korge { id = "org.korge.unknown.game"; loadYaml(file("korge.yaml")) }
dependencies { findProject(":deps")?.also { add("commonMainApi", it) } }
val baseFile = file("build.extra.gradle.kts").takeIf { it.exists() }?.also { apply(from = it) }
""".trimIndent())
}

}
}
Loading