-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into plugins-release
plugins v0.5.0 release
- Loading branch information
Showing
30 changed files
with
593 additions
and
68 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 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
4 changes: 0 additions & 4 deletions
4
...tecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/VersionsAndDependencies.kt
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
26 changes: 26 additions & 0 deletions
26
...-gradle-plugins/src/main/kotlin/com/huanshankeji/jvm/native/osandarch/DefaultSupported.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,26 @@ | ||
package com.huanshankeji.jvm.native.osandarch | ||
|
||
|
||
object DefaultSupported { | ||
object ArchsByOs { | ||
val linux = listOf(CpuArchitecture.X8664, CpuArchitecture.Aarch64) | ||
val windows = listOf(CpuArchitecture.X8664) | ||
val macos = listOf(CpuArchitecture.X8664, CpuArchitecture.Aarch64) | ||
} | ||
|
||
object OsAndArchs { | ||
val linux = ArchsByOs.linux.map { OsAndArch(Os.Linux, it) } | ||
val windows = ArchsByOs.windows.map { OsAndArch(Os.Windows, it) } | ||
val macos = ArchsByOs.macos.map { OsAndArch(Os.Macos, it) } | ||
|
||
val all = listOf(linux, windows, macos).flatten() | ||
val allFeatureVariantNames = all.map { it.featureVariantName } | ||
|
||
// TODO use `entries` when the language version is bumped to 1.9 | ||
val futureAll = Os.values().flatMap { os -> | ||
CpuArchitecture.values().map { arch -> | ||
OsAndArch(os, arch) | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...mon-gradle-plugins/src/main/kotlin/com/huanshankeji/jvm/native/osandarch/Distributions.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,3 @@ | ||
package com.huanshankeji.jvm.native.osandarch | ||
|
||
// not implemented yet |
150 changes: 150 additions & 0 deletions
150
...s/src/main/kotlin/com/huanshankeji/jvm/native/osandarch/FeatureVariantsAndDependencies.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,150 @@ | ||
package com.huanshankeji.jvm.native.osandarch | ||
|
||
import com.huanshankeji.* | ||
import com.huanshankeji.SourceSetType.Main | ||
import com.huanshankeji.SourceSetType.RegisterSeparate | ||
import org.gradle.api.plugins.JavaPluginExtension | ||
import org.gradle.kotlin.dsl.DependencyHandlerScope | ||
import org.gradle.kotlin.dsl.accessors.runtime.addExternalModuleDependencyTo | ||
import org.gradle.kotlin.dsl.get | ||
|
||
val OsAndArch.featureVariantName get() = camelCaseIdentifier | ||
|
||
|
||
fun JavaPluginExtension.registerDefaultSupportedFeatureVariants(sourceSetType: SourceSetType) { | ||
when (sourceSetType) { | ||
Main -> { | ||
val mainSourceSet = sourceSets["main"] | ||
for (osAndArch in DefaultSupported.OsAndArchs.all) | ||
registerFeatureVariantWithSourceSet(osAndArch.featureVariantName, mainSourceSet) | ||
} | ||
|
||
RegisterSeparate -> | ||
for (osAndArch in DefaultSupported.OsAndArchs.all) | ||
registerFeatureVariantWithNewSourceSet(osAndArch.featureVariantName) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @param identifier usually in kebab case (sometimes mixed with snake case, for example "X86_64") | ||
*/ | ||
data class FeatureVariantDependencyConfig(val osAndArch: OsAndArch, val identifier: String) | ||
|
||
fun DependencyHandlerScope.addDependencyToFeatureVariants( | ||
osAndArchs: List<OsAndArch>, targetConfigurationType: String, dependencyNotation: Any | ||
) = | ||
addDependencyToFeatureVariants( | ||
osAndArchs.map { it.featureVariantName }, targetConfigurationType, dependencyNotation | ||
) | ||
|
||
|
||
// TODO some functions related to feature variants can be extracted to a separate feature variant package | ||
|
||
/** | ||
* @param osAndArchs use a predefined one in [DefaultSupported.OsAndArchs] or make your own with [FeatureVariantDependencyConfig] | ||
* @param targetConfigurationType the type of the dependency configuration | ||
* (see https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:what-are-dependency-configurations | ||
* and https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph) | ||
*/ | ||
fun DependencyHandlerScope.addDependenciesToFeatureVariantsWithIdentifiersInNameSuffixes( | ||
osAndArchs: List<FeatureVariantDependencyConfig>, | ||
targetConfigurationType: String, | ||
group: String, namePrefix: String, version: String? = null | ||
) { | ||
for ((osAndArch, dependencyIdentifier) in osAndArchs) | ||
addExternalModuleDependencyTo( | ||
this, | ||
osAndArch.featureVariantName camelCaseConcat targetConfigurationType, | ||
group, "$namePrefix-$dependencyIdentifier", version, | ||
null, null, null, null | ||
) | ||
} | ||
|
||
/** @see addDependenciesToFeatureVariantsWithIdentifiersInNameSuffixes */ | ||
fun DependencyHandlerScope.addDependenciesToFeatureVariantsWithIdentifiersInNameSuffixes( | ||
osAndArchs: List<OsAndArch>, getIdentifier: (OsAndArch) -> String, | ||
targetConfigurationType: String, | ||
group: String, namePrefix: String, version: String? = null | ||
) = | ||
addDependenciesToFeatureVariantsWithIdentifiersInNameSuffixes(osAndArchs.map { | ||
FeatureVariantDependencyConfig(it, getIdentifier(it)) | ||
}, targetConfigurationType, group, namePrefix, version) | ||
|
||
/** | ||
* @param configs use a predefined one in [DefaultSupported.OsAndArchs] or make your own with [FeatureVariantDependencyConfig] | ||
* @param targetConfigurationType the type of the dependency configuration | ||
* (see https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:what-are-dependency-configurations | ||
* and https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph) | ||
*/ | ||
fun DependencyHandlerScope.addDependenciesToFeatureVariantsWithIdentifiersInClassifiers( | ||
configs: List<FeatureVariantDependencyConfig>, | ||
targetConfigurationType: String, | ||
group: String, name: String, version: String? = null | ||
) { | ||
for ((osAndArch, dependencyIdentifier) in configs) | ||
addExternalModuleDependencyTo( | ||
this, | ||
osAndArch.featureVariantName camelCaseConcat targetConfigurationType, | ||
group, name, version, | ||
null, dependencyIdentifier, null, null | ||
) | ||
} | ||
|
||
/** @see addDependenciesToFeatureVariantsWithIdentifiersInClassifiers */ | ||
fun DependencyHandlerScope.addDependenciesToFeatureVariantsWithIdentifiersInClassifiers( | ||
osAndArchs: List<OsAndArch>, getIdentifier: (OsAndArch) -> String, | ||
targetConfigurationType: String, | ||
group: String, name: String, version: String? = null | ||
) = | ||
addDependenciesToFeatureVariantsWithIdentifiersInClassifiers(osAndArchs.map { | ||
FeatureVariantDependencyConfig(it, getIdentifier(it)) | ||
}, targetConfigurationType, group, name, version) | ||
|
||
|
||
fun getCapabilityNotation(group: String, name: String, featureVariantName: String) = | ||
"$group:$name-${featureVariantName.camelCaseToKebabCase()}" | ||
|
||
private inline fun DependencyHandlerScope.addDependencyWithFeatureVariantCapabilityDependencies( | ||
featureVariantNames: List<String>, targetConfiguration: (featureVariantName: String?) -> String, | ||
group: String, name: String, version: String? = null | ||
) { | ||
addExternalModuleDependencyTo(this, targetConfiguration(null), group, name, version, null, null, null, null) | ||
for (featureVariantName in featureVariantNames) | ||
addExternalModuleDependencyTo( | ||
this, | ||
targetConfiguration(featureVariantName), | ||
group, name, version, | ||
null, null, null | ||
) { | ||
capabilities { | ||
requireCapability(getCapabilityNotation(group, name, featureVariantName)) | ||
} | ||
} | ||
} | ||
|
||
fun DependencyHandlerScope.addDependencyWithFeatureVariantTransitiveCapabilityDependencies( | ||
featureVariantNames: List<String>, targetConfigurationType: String, | ||
group: String, name: String, version: String? = null | ||
) = | ||
addDependencyWithFeatureVariantCapabilityDependencies( | ||
featureVariantNames, | ||
{ featureVariantName -> | ||
featureVariantName?.camelCaseConcat(targetConfigurationType) ?: targetConfigurationType | ||
}, | ||
group, name, version | ||
) | ||
|
||
/** | ||
* Adds all the feature variant dependencies to the main variant. | ||
* Use this function without the `register-feature-variants` plugin. | ||
*/ | ||
fun DependencyHandlerScope.addDependencyWithFeatureVariantCapabilityDependenciesToOneConfiguration( | ||
featureVariantNames: List<String>, targetConfiguration: String, | ||
group: String, name: String, version: String? = null | ||
) = | ||
addDependencyWithFeatureVariantCapabilityDependencies( | ||
featureVariantNames, | ||
{ _ -> targetConfiguration }, | ||
group, name, version | ||
) |
39 changes: 39 additions & 0 deletions
39
...-common-gradle-plugins/src/main/kotlin/com/huanshankeji/jvm/native/osandarch/OsAndArch.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,39 @@ | ||
package com.huanshankeji.jvm.native.osandarch | ||
|
||
import com.huanshankeji.camelCaseConcat | ||
import com.huanshankeji.jvm.native.osandarch.CpuArchitecture.Aarch64 | ||
import com.huanshankeji.jvm.native.osandarch.CpuArchitecture.X8664 | ||
import com.huanshankeji.jvm.native.osandarch.Os.* | ||
import com.huanshankeji.kebabCaseConcat | ||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | ||
|
||
// TODO possibly use feature variant name | ||
enum class Os(val identifier: String) { | ||
Linux("linux"), Windows("windows"), Macos("osx") | ||
} | ||
|
||
enum class CpuArchitecture(val identifier: String) { | ||
X8664("x8664"), Aarch64("aarch64") | ||
} | ||
|
||
data class OsAndArch(val os: Os, val arch: CpuArchitecture) { | ||
val kebabCaseIdentifier = os.identifier kebabCaseConcat arch.identifier | ||
val camelCaseIdentifier = os.identifier camelCaseConcat arch.identifier | ||
} | ||
|
||
fun getCurrentOsAndArch(): OsAndArch { | ||
val currentOperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem() | ||
val os = when { | ||
currentOperatingSystem.isLinux -> Linux | ||
currentOperatingSystem.isWindows -> Windows | ||
currentOperatingSystem.isMacOsX -> Macos | ||
else -> throw IllegalArgumentException("Huanshankeji architecture common unsupported operating system: $currentOperatingSystem") | ||
} | ||
val currentArchitecture = DefaultNativePlatform.getCurrentArchitecture() | ||
val arch = when { | ||
currentArchitecture.isAmd64 -> X8664 | ||
currentArchitecture.isArm64 -> Aarch64 | ||
else -> throw IllegalArgumentException("Huanshankeji architecture common unsupported CPU architecture: $currentOperatingSystem") | ||
} | ||
return OsAndArch(os, arch) | ||
} |
17 changes: 17 additions & 0 deletions
17
.../huanshankeji/jvm/native/osandarch/register-default-supported-feature-variants.gradle.kts
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,17 @@ | ||
package com.huanshankeji.jvm.native.osandarch | ||
|
||
import com.huanshankeji.SourceSetType | ||
|
||
plugins { | ||
java | ||
} | ||
|
||
interface Extension { | ||
val sourceSetType: Property<SourceSetType> | ||
} | ||
|
||
// TODO put in `afterEvaluate`? | ||
|
||
val extension = extensions.create<Extension>("registerOsAndArchFeatureVariants") | ||
|
||
java.registerDefaultSupportedFeatureVariants(extension.sourceSetType.getOrElse(SourceSetType.Main)) |
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 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
10 changes: 10 additions & 0 deletions
10
buildSrc/src/main/kotlin/aligned-version-plugin-conventions.gradle.kts
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask | ||
|
||
plugins { | ||
id("conventions") | ||
} | ||
|
||
version = alignedPluginVersion | ||
|
||
dependencies { | ||
implementation("com.huanshankeji:common-gradle-dependencies:$pluginProjectSourceDependentStableCommonGradleDependenciesVersion") | ||
} | ||
|
||
tasks.named<KotlinCompilationTask<*>>("compileKotlin").configure { | ||
compilerOptions.freeCompilerArgs.add("-opt-in=com.huanshankeji.InternalApi") | ||
} |
Oops, something went wrong.