Skip to content

Commit

Permalink
Merge branch 'main' into plugins-release
Browse files Browse the repository at this point in the history
plugins v0.5.0 release
  • Loading branch information
ShreckYe committed Jan 30, 2024
2 parents 9853a2a + 45fe205 commit 049aa82
Show file tree
Hide file tree
Showing 30 changed files with 593 additions and 68 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ configurations.all {
## Developer notices

1. IntelliJ IDEA doesn't work well with applying plugins to script plugins in project sources. If a script plugin's code does not resolve, try restarting IntelliJ IDEA.
1. `./gradlew build` (and tasks depending on it) somehow has to run twice to work. I haven't identified the cause yet.
21 changes: 14 additions & 7 deletions architecture-common-gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies {
/* This project depends on a specific version of the Maven dependency of "common-gradle-dependencies"
since now they are developed together in the same branch `main`,
enabling it to always depend on a release version. */
implementation("com.huanshankeji:common-gradle-dependencies:$pluginProjectDependentStableCommonGradleDependenciesVersion")

implementation(commonGradleClasspathDependencies.composeMultiplatform.gradlePlugin.pluginProject())
}
Expand Down Expand Up @@ -61,12 +60,20 @@ gradlePlugin {
"(not implemented yet) Default web frontend conventions for our projects with Compose for Web, kotlinx.html HTML generation, and Material Design"
)

val name = "generate-kotlin-js-browser-webroot-for-vertx-web"
create(name) {
id = "$`package`.$name"
implementationClass = "$`package`.GenerateKotlinJsBrowserWebrootForVertxWebPlugin"
displayName = "Generate Kotlin/JS browser webroot for Vert.x Web"
description = "Generate webroot from a Kotlin/JS subproject with browser target for Vert.x Web"
run {
val name = "generate-kotlin-js-browser-webroot-for-vertx-web"
create(name) {
id = "$`package`.$name"
implementationClass = "$`package`.GenerateKotlinJsBrowserWebrootForVertxWebPlugin"
displayName = "Generate Kotlin/JS browser webroot for Vert.x Web"
description = "Generate webroot from a Kotlin/JS subproject with browser target for Vert.x Web"
}
}

scriptConventionsPlugin(
"jvm.native.osandarch.register-default-supported-feature-variants",
"Register the OS and architecture feature variants",
"Registers feature variants for different operating systems (Linux, Windows, macOS) and CPU architectures."
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ plugins {
id("org.jetbrains.compose")
}

interface Extension {
val htmlGenerationProjectPath: Property<String>
}

val extension = extensions.create<Extension>("defaultWebFrontendConventions")

repositories {
google()
mavenCentral()
Expand All @@ -28,7 +34,7 @@ kotlin {
binaries.executable()
}
sourceSets {
val jsMain by getting {
jsMain {
dependencies {
implementation(compose.web.core)
implementation(compose.runtime)
Expand All @@ -41,7 +47,9 @@ kotlin {
val generatedResourcesFile = buildDir.resolve("generatedResources")

tasks.named("jsProcessResources") {
val htmlGenerationRun = tasks.getByPath(project.path + ":html-generation:run") as JavaExec
val htmlGenerationRun = tasks.getByPath(
extension.htmlGenerationProjectPath.getOrElse(project.path + ":html-generation") + ":run"
) as JavaExec
htmlGenerationRun.args(generatedResourcesFile.absolutePath)
dependsOn(htmlGenerationRun)
}
Expand Down
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)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.huanshankeji.jvm.native.osandarch

// not implemented yet
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
)
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)
}
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))
11 changes: 6 additions & 5 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`kotlin-dsl`
// Gradle 8.0.2's dependent Kotlin version is 1.8.10.
// Gradle 8.1.1's dependent Kotlin version is 1.8.10.
//kotlin("jvm") version "1.8.10"
}

Expand All @@ -24,13 +24,14 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-sam-with-receiver:1.8.0")
}
*/
//implementation(kotlin("gradle-plugin", "1.8.10")) // for Compose 1.3.1
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:4.0.6") // This version has to be used for Gradle 8.0.1.
// for `KotlinCompilationTask` and the version is for Compose 1.5.1
implementation(kotlin("gradle-plugin", "1.9.20"))
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:4.1.2") // This version has to be used for Gradle 8.4.

implementation("com.gradle.publish:plugin-publish-plugin:1.1.0")
implementation("com.gradle.publish:plugin-publish-plugin:1.2.1")

// This is a bootstrapping dependency (cross-version self-dependency). Try not to update its version unless necessary.
implementation("com.huanshankeji.team:gradle-plugins:0.3.0") { exclude("org.jetbrains.kotlin") }
// This is also a bootstrapping dependency.
implementation("com.huanshankeji:common-gradle-dependencies:0.5.0-20230310") { exclude("org.jetbrains.kotlin") }
implementation("com.huanshankeji:common-gradle-dependencies:0.7.1-20231111") { exclude("org.jetbrains.kotlin") }
}
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/VersionsAndDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import com.huanshankeji.CommonVersions
val commonVersions = CommonVersions()
val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions)

val kotlinVersion = "1.8.10" // for Compose 1.3.1
val kotlinVersion = "1.9.20" // for Compose 1.4.0 // TODO remove this comment

val alignedPluginVersion = "0.4.1"
val alignedPluginVersion = "0.5.0"

// "x.y.z" indicates the version of the way of organizing the code,
// and the date indicates the version when the dependency versions are updated.
val commonGradleDependenciesVersion = "0.5.0-20230310-SNAPSHOT"
val commonGradleDependenciesVersion = "0.7.1-20231111-SNAPSHOT"

// This is the source dependency version. There is another build source dependency in "buildSrc/build.gradle.kts".
val pluginProjectDependentStableCommonGradleDependenciesVersion = "0.5.0-20230310".apply {
val pluginProjectSourceDependentStableCommonGradleDependenciesVersion = "0.7.1-20231111".apply {
require(!endsWith("SNAPSHOT"))
}
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")
}
Loading

0 comments on commit 049aa82

Please sign in to comment.