-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced compiler-specific modules with version-specific source sets (#…
…84)
- Loading branch information
Showing
42 changed files
with
175 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ pluginManagement { | |
|
||
plugins { | ||
id("settings-conventions") | ||
id("compiler-specific-modules") | ||
} | ||
|
||
includeRootAsPublic() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
gradle-conventions/compiler-specific-module/src/main/kotlin/dependency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | ||
|
||
/** | ||
* Use this to add a specific dependency to a source set, depending on a Kotlin version | ||
*/ | ||
fun KotlinSourceSet.vsDependencies( | ||
vsSourceSetDir: String, | ||
configure: KotlinDependencyHandler.() -> Unit, | ||
) { | ||
kotlin.srcDirs.find { it.name == vsSourceSetDir }?.apply { | ||
dependencies(configure) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
gradle-conventions/compiler-specific-module/src/main/kotlin/util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import java.nio.file.Path | ||
|
||
object Const { | ||
const val KOTLIN_MULTIPLATFORM_PLUGIN_ID = "org.jetbrains.kotlin.multiplatform" | ||
const val KOTLIN_JVM_PLUGIN_ID = "org.jetbrains.kotlin.jvm" | ||
|
||
const val CORE_SOURCE_SET = "core" | ||
const val LATEST_SOURCE_SET = "latest" | ||
|
||
const val RESOURCES = "resources" | ||
} | ||
|
||
fun capitalize(string: String): String { | ||
if (string.isEmpty()) { | ||
return "" | ||
} | ||
val firstChar = string[0] | ||
return string.replaceFirst(firstChar, Character.toTitleCase(firstChar)) | ||
} | ||
|
||
fun Path.name() = fileName?.toString().orEmpty() |
44 changes: 44 additions & 0 deletions
44
gradle-conventions/compiler-specific-module/src/main/kotlin/version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
import java.io.File | ||
|
||
// Versioning is used to sort version-specific source sets in the 'first comes more specific' order | ||
// By 'more specific' we mean that '1.7.10' is more specific than '1.7'. | ||
// So [1.7, 1.7.10, 1.9.10, 1.7.22, 1.9, 1, 1.7.0, latest, 1.8] | ||
// will be sorted as [1.7.0, 1.7.10, 1.7.22, 1.7, 1.8, 1.9.10, 1.9, 1, latest] | ||
// It's ok to have version '1'. | ||
// For example, we may have '1.7' and '1' specific source sets. | ||
// That would mean that all 1.7.* versions we compile with the '1.7' source set, | ||
// and 1.8.+ up to 1.9.24 will be with the '1' source set | ||
class CompilerModuleVersion(fullName: String, prefix: String) : Comparable<CompilerModuleVersion> { | ||
// For example, "v_1_7_10" -> "1.7.10" | ||
val version = fullName | ||
.removePrefix(prefix) | ||
.replace('_', '.') | ||
|
||
override fun compareTo(other: CompilerModuleVersion): Int { | ||
return when { | ||
version.length == other.version.length -> version.compareTo(other.version) | ||
version.length < other.version.length -> 1 | ||
else -> -1 | ||
} | ||
} | ||
} | ||
|
||
fun Collection<File>.mostSpecificByVersionOrNull(kotlinVersion: String): File? { | ||
return map { it to CompilerModuleVersion(it.name, "v_") } | ||
.sortedBy { (_, semVer) -> semVer } | ||
.firstOrNull { (_, semVer) -> | ||
kotlinVersion.startsWith(semVer.version) | ||
}?.first | ||
} | ||
|
||
// matches: | ||
// - latest | ||
// - v_1 | ||
// - v_1_9 | ||
// - v_1_9_2 | ||
// - v_1_9_24 | ||
val directoryNameRegex = "^(latest|v(_\\d){1,3}\\d?)$".toRegex() |
Oops, something went wrong.