Skip to content

Commit

Permalink
Make jdk docs and messages configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Oct 11, 2024
1 parent 032474e commit 5eaa442
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ We've restructured this project! Since its early days as a simple Gradle convent

### Misc

- **New**: Make JDK configuration docs and error messages configurable via `FoundryProperties`.
- **Fix**: Gracefully handle undefined kapt language versions when computing `progressive`.
- **Fix**: Track deleted build files when computing parent projects in Skippy.
- Update Clikt to `5.0.1`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,14 @@ internal constructor(
public val jvmVendorOptOut: Boolean
get() = booleanProperty("foundry.jvm.vendor.optOut", defaultValue = false)

/** Optional link to JDK configuration */
public val jdkDocsLink: String?
get() = optionalStringProperty("foundry.jdk.docsLink")

/** Optional error message to show when the JDK configuration is invalid. */
public val jdkErrorMessage: String?
get() = optionalStringProperty("foundry.jdk.errorMessage")

/**
* Option to force a specific kotlin language version. By default defers to the KGP default the
* build is running with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,6 @@ internal class FoundryRootPlugin @Inject constructor(private val buildFeatures:
require(project == project.rootProject) {
"Slack plugin should only be applied on the root project!"
}

AppleSiliconCompat.validate {
"""
Rosetta detected!
You are running on an Apple Silicon device but running an x86 JDK. This means your OS is
running your process in a translated mode (i.e. slower) via Rosetta.
Please download a native arm64 JDK and remove your existing x86 JDK.
See: https://github.com/tinyspeck/slack-android-ng/wiki/JDK-Installation-&-JAVA_HOME
"""
.trimIndent()
}

val startParameters = project.gradle.startParameter.projectProperties
val startParameterProperties =
project.providers.of(StartParameterProperties::class.java) {
Expand All @@ -104,6 +90,20 @@ internal class FoundryRootPlugin @Inject constructor(private val buildFeatures:
startParameterProperty = startParameterProperty,
globalLocalProperty = globalLocalProperty,
)

AppleSiliconCompat.validate {
"""
Rosetta detected!
You are running on an Apple Silicon device but running an x86 JDK. This means your OS is
running your process in a translated mode (i.e. slower) via Rosetta.
Please download a native arm64 JDK and remove your existing x86 JDK.
See: ${foundryProperties.jdkDocsLink ?: "No docs link provided"}
"""
.trimIndent()
}

val thermalsLogJsonFile =
project.layout.buildDirectory.file("outputs/logs/last-build-thermals.json")
val logThermals = foundryProperties.logThermals
Expand Down Expand Up @@ -149,8 +149,7 @@ internal class FoundryRootPlugin @Inject constructor(private val buildFeatures:
check(jdk == runtimeVersion) {
"""
Current Java version ($runtimeVersion) does not match the enforced version ($jdk).
Run ./slackw bootstrap to upgrade and be sure to set your JAVA_HOME to the JDK path it
prints out.
${foundryProperties.jdkErrorMessage.orEmpty()}
If you're seeing this error from Studio, ensure Studio is using JDK $jdk in
Preferences > Build, Execution, Deployment > Build tools > Gradle > Gradle JVM
Expand All @@ -169,6 +168,7 @@ internal class FoundryRootPlugin @Inject constructor(private val buildFeatures:
project.configureFoundryRootBuildscript(
foundryProperties.versions.jdk.asProvider(project.providers),
foundryProperties.jvmVendor.map(JvmVendorSpec::matching).orNull,
foundryProperties.jdkDocsLink,
)
LintTasks.configureRootProject(project)
DetektTasks.configureRootProject(project, foundryProperties)
Expand Down Expand Up @@ -472,10 +472,11 @@ internal class FoundryRootPlugin @Inject constructor(private val buildFeatures:
private fun Project.configureFoundryRootBuildscript(
jdkProvider: Provider<Int>,
jvmVendor: JvmVendorSpec?,
jdkDocsLink: String?,
) {
// Only register bootstrap if explicitly requested for now
if (CoreBootstrapTask.isBootstrapEnabled(this)) {
CoreBootstrapTask.register(this, jdkProvider, jvmVendor)
CoreBootstrapTask.register(this, jdkProvider, jvmVendor, jdkDocsLink)
}
InstallCommitHooksTask.register(this)
}
Expand Down Expand Up @@ -543,9 +544,7 @@ private fun Project.configureMisc(foundryProperties: FoundryProperties) {
failOnError.setDisallowChanges(provider { foundryProperties.strictJdk })

/** Link our wiki page in its messages to get developers up and running. */
extraMessage.setDisallowChanges(
"https://github.com/tinyspeck/slack-android-ng/wiki/JDK-Installation-&-JAVA_HOME"
)
extraMessage.setDisallowChanges(foundryProperties.jdkDocsLink)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : DefaultTask()
public val gradleMemoryPercentage: Property<String> =
objects.property<String>().convention(argsProvider.gradleMemoryPercentage)

@get:Optional @get:Input public abstract val jdkDocsLink: Property<String>

@get:OutputDirectory public abstract val cacheDir: DirectoryProperty

@get:OutputFile public abstract val diagnostics: RegularFileProperty
Expand All @@ -209,7 +211,6 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : DefaultTask()

if (launcher.isPresent) {
diagnosticsOutput.appendLine("Initializing JDK")
// TODO make this message configurable
diagnosticsOutput.appendLine(
"""
JDK config:
Expand All @@ -221,7 +222,7 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : DefaultTask()
Restart Android Studio once to ensure this is picked up in your Project Structure as well!
For advanced configuration see https://github.com/tinyspeck/slack-android-ng/wiki/JDK-Installation-&-JAVA_HOME
For advanced configuration see ${jdkDocsLink.orNull ?: "<no JDK docs link set>"}
"""
.trimIndent()
Expand Down Expand Up @@ -339,6 +340,7 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : DefaultTask()
project: Project,
jdkVersion: Provider<Int>,
jvmVendor: JvmVendorSpec?,
jdkDocsLink: String?,
): TaskProvider<CoreBootstrapTask> {
check(project.isRootProject) { "Bootstrap can only be applied to the root project" }
val bootstrap =
Expand All @@ -353,6 +355,7 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : DefaultTask()
}
this.launcher.convention(defaultLauncher)
this.jdkVersion.setDisallowChanges(jdkVersion)
this.jdkDocsLink.setDisallowChanges(jdkDocsLink)

val cacheDirProvider = project.layout.projectDirectory.dir(".cache")
val bootstrapVersionFileProvider = cacheDirProvider.file("bootstrap.txt")
Expand Down

0 comments on commit 5eaa442

Please sign in to comment.