Update to Gradle 8.x

- Update to Loom 1.2 and FG 6.0. ForgeGradle has changed how it
   generates the runXyz tasks, which makes running our tests much
   harder. I've raised an issue upstream, but for now we do some nasty
   poking of internals.

 - Fix Sodium/Iris tests. Loom 1.1 changed how remapped configurations
   are generated - we create a dummy source set and associate the
   remapped configuration with that. All nasty stuff.

 - Publish the common library. I'm not a fan of this, but given how much
   internals I'm poking elsewhere, should probably get off my high
   horse.

 - Add renderdoc support to the client gametests, enabled with
   -Prenderdoc.
This commit is contained in:
Jonathan Coates 2023-06-29 20:10:17 +01:00
parent 7eb3b691da
commit f5b16261cc
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
12 changed files with 113 additions and 27 deletions

View File

@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
//
// SPDX-License-Identifier: MPL-2.0
package cc.tweaked.gradle
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.gradle.common.util.runs.setRunConfigInternal
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.JavaExec
import org.gradle.jvm.toolchain.JavaToolchainService
import java.nio.file.Files
/**
* Set [JavaExec] task to run a given [RunConfig].
*/
fun JavaExec.setRunConfig(config: RunConfig) {
dependsOn("prepareRuns")
setRunConfigInternal(project, this, config)
doFirst("Create working directory") { Files.createDirectories(workingDir.toPath().parent) }
javaLauncher.set(
project.extensions.getByType(JavaToolchainService::class.java)
.launcherFor(project.extensions.getByType(JavaPluginExtension::class.java).toolchain),
)
}

View File

@ -60,7 +60,7 @@ private fun setupDependency(project: Project, version: Provider<String>): Provid
/** Define a dependency for illuaminate from a version number and the current operating system. */ /** Define a dependency for illuaminate from a version number and the current operating system. */
private fun illuaminateArtifact(project: Project, version: String): Dependency { private fun illuaminateArtifact(project: Project, version: String): Dependency {
val osName = System.getProperty("os.name").toLowerCase() val osName = System.getProperty("os.name").lowercase()
val (os, suffix) = when { val (os, suffix) = when {
osName.contains("windows") -> Pair("windows", ".exe") osName.contains("windows") -> Pair("windows", ".exe")
osName.contains("mac os") || osName.contains("darwin") -> Pair("macos", "") osName.contains("mac os") || osName.contains("darwin") -> Pair("macos", "")
@ -68,7 +68,7 @@ private fun illuaminateArtifact(project: Project, version: String): Dependency {
else -> error("Unsupported OS $osName for illuaminate") else -> error("Unsupported OS $osName for illuaminate")
} }
val osArch = System.getProperty("os.arch").toLowerCase() val osArch = System.getProperty("os.arch").lowercase()
val arch = when { val arch = when {
// On macOS the x86_64 binary will work for both ARM and Intel Macs through Rosetta. // On macOS the x86_64 binary will work for both ARM and Intel Macs through Rosetta.
os == "macos" -> "x86_64" os == "macos" -> "x86_64"

View File

@ -32,11 +32,14 @@ abstract class ClientJavaExec : JavaExec() {
usesService(clientRunner) usesService(clientRunner)
} }
@get:Input
val renderdoc get() = project.hasProperty("renderdoc")
/** /**
* When [false], tests will not be run automatically, allowing the user to debug rendering. * When [false], tests will not be run automatically, allowing the user to debug rendering.
*/ */
@get:Input @get:Input
val clientDebug get() = project.hasProperty("clientDebug") val clientDebug get() = renderdoc || project.hasProperty("clientDebug")
/** /**
* When [false], tests will not run under a framebuffer. * When [false], tests will not run under a framebuffer.
@ -63,6 +66,7 @@ fun copyFrom(task: JavaExec) {
task.copyToFull(this) task.copyToFull(this)
if (!clientDebug) systemProperty("cctest.client", "") if (!clientDebug) systemProperty("cctest.client", "")
if (renderdoc) environment("LD_PRELOAD", "/usr/lib/librenderdoc.so")
systemProperty("cctest.gametest-report", testResults.get().asFile.absoluteFile) systemProperty("cctest.gametest-report", testResults.get().asFile.absoluteFile)
workingDir(project.buildDir.resolve("gametest").resolve(name)) workingDir(project.buildDir.resolve("gametest").resolve(name))
} }

View File

@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
//
// SPDX-License-Identifier: MPL-2.0
package net.minecraftforge.gradle.common.util.runs
import net.minecraftforge.gradle.common.util.RunConfig
import org.gradle.api.Project
import org.gradle.process.JavaExecSpec
import java.io.File
/**
* Set up a [JavaExecSpec] to execute a [RunConfig].
*
* [MinecraftRunTask] sets up all its properties when the task is executed, rather than when configured. As such, it's
* not possible to use [cc.tweaked.gradle.copyToFull] like we do for Fabric. Instead, we set up the task manually.
*
* Unfortunately most of the functionality we need is package-private, and so we have to put our code into the package.
*/
internal fun setRunConfigInternal(project: Project, spec: JavaExecSpec, config: RunConfig) {
val originalTask = project.tasks.named(config.taskName, MinecraftRunTask::class.java).get()
spec.workingDir = File(config.workingDirectory)
spec.mainClass.set(config.main)
for (source in config.allSources) spec.classpath(source.runtimeClasspath)
val lazyTokens = RunConfigGenerator.configureTokensLazy(
project, config,
RunConfigGenerator.mapModClassesToGradle(project, config),
originalTask.minecraftArtifacts.files,
originalTask.runtimeClasspathArtifacts.files,
)
spec.args(RunConfigGenerator.getArgsStream(config, lazyTokens, false).toList())
spec.jvmArgs(
(if (config.isClient) config.jvmArgs + originalTask.additionalClientArgs.get() else config.jvmArgs)
.map { config.replace(lazyTokens, it) },
)
for ((key, value) in config.environment) spec.environment(key, config.replace(lazyTokens, value))
for ((key, value) in config.properties) spec.systemProperty(key, config.replace(lazyTokens, value))
}

View File

@ -53,8 +53,8 @@ checkstyle = "10.3.4"
curseForgeGradle = "1.0.14" curseForgeGradle = "1.0.14"
errorProne-core = "2.18.0" errorProne-core = "2.18.0"
errorProne-plugin = "3.0.1" errorProne-plugin = "3.0.1"
fabric-loom = "1.1.10" fabric-loom = "1.2.7"
forgeGradle = "5.1.+" forgeGradle = "6.0.6"
githubRelease = "2.2.12" githubRelease = "2.2.12"
ideaExt = "1.1.6" ideaExt = "1.1.6"
illuaminate = "0.1.0-28-ga7efd71" illuaminate = "0.1.0-28-ga7efd71"

Binary file not shown.

View File

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

19
gradlew vendored
View File

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@ -80,13 +80,10 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command; # Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in # shell script including quotes and variable substitutions, so put them in

1
gradlew.bat vendored
View File

@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%

View File

@ -7,6 +7,7 @@ import cc.tweaked.gradle.clientClasses
import cc.tweaked.gradle.commonClasses import cc.tweaked.gradle.commonClasses
plugins { plugins {
id("cc-tweaked.publishing")
id("cc-tweaked.vanilla") id("cc-tweaked.vanilla")
id("cc-tweaked.gametest") id("cc-tweaked.gametest")
} }

View File

@ -21,15 +21,25 @@ cct {
} }
fun addRemappedConfiguration(name: String) { fun addRemappedConfiguration(name: String) {
// There was a regression in Loom 1.1 which means that targetConfigurationName doesn't do anything, and remap
// configurations just get added to the main source set (https://github.com/FabricMC/fabric-loom/issues/843).
// To get around that, we create our own source set and register a remap configuration with that. This does
// introduce a bit of noise, but it's not the end of the world.
val ourSourceSet = sourceSets.register(name) {
// Try to make this source set as much of a non-entity as possible.
listOf(allSource, java, resources, kotlin).forEach { it.setSrcDirs(emptyList<File>()) }
}
val capitalName = name.replaceFirstChar { it.titlecase(Locale.ROOT) }
loom.addRemapConfiguration("mod$capitalName") {
onCompileClasspath.set(false)
onRuntimeClasspath.set(true)
sourceSet.set(ourSourceSet)
targetConfigurationName.set(name)
}
configurations.create(name) { configurations.create(name) {
isCanBeConsumed = false isCanBeConsumed = false
isCanBeResolved = true isCanBeResolved = true
} extendsFrom(configurations["${name}RuntimeClasspath"])
val capitalName = name.capitalize(Locale.ROOT)
loom.addRemapConfiguration("mod$capitalName") {
onCompileClasspath.set(false)
onRuntimeClasspath.set(false)
targetConfigurationName.set(name)
} }
} }

View File

@ -35,8 +35,6 @@ minecraft {
property("forge.logging.markers", "REGISTRIES") property("forge.logging.markers", "REGISTRIES")
property("forge.logging.console.level", "debug") property("forge.logging.console.level", "debug")
forceExit = false
mods.register("computercraft") { mods.register("computercraft") {
cct.sourceDirectories.get().forEach { cct.sourceDirectories.get().forEach {
if (it.classes) sources(it.sourceSet) if (it.classes) sources(it.sourceSet)
@ -262,11 +260,7 @@ val runGametest by tasks.registering(JavaExec::class) {
dependsOn("cleanRunGametest") dependsOn("cleanRunGametest")
usesService(MinecraftRunnerService.get(gradle)) usesService(MinecraftRunnerService.get(gradle))
// Copy from runGameTestServer. We do it in this slightly odd way as runGameTestServer setRunConfig(minecraft.runs["gameTestServer"])
// isn't created until the task is configured (which is no good for us).
val exec = tasks.getByName<JavaExec>("runGameTestServer")
dependsOn(exec.dependsOn)
exec.copyToFull(this)
systemProperty("cctest.gametest-report", project.buildDir.resolve("test-results/$name.xml").absolutePath) systemProperty("cctest.gametest-report", project.buildDir.resolve("test-results/$name.xml").absolutePath)
} }
@ -275,7 +269,7 @@ tasks.check { dependsOn(runGametest) }
val runGametestClient by tasks.registering(ClientJavaExec::class) { val runGametestClient by tasks.registering(ClientJavaExec::class) {
description = "Runs client-side gametests with no mods" description = "Runs client-side gametests with no mods"
copyFrom("runTestClient") setRunConfig(minecraft.runs["testClient"])
tags("client") tags("client")
} }
cct.jacoco(runGametestClient) cct.jacoco(runGametestClient)