Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fabric-Loom-Mixin-Remap-Type manifest entry #980

Merged
merged 12 commits into from
Nov 20, 2023
Prev Previous commit
Next Next commit
Improve fabric API test
  • Loading branch information
modmuss50 committed Nov 9, 2023
commit 057eda721b99d495c62f87a193123866b0f1c655
2 changes: 1 addition & 1 deletion gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ java-debug = "0.48.0"
mixin = "0.11.4+mixin.0.8.5"

gradle-nightly = "8.5-20230908221250+0000"
fabric-loader = "0.14.22"
fabric-loader = "0.14.24"
fabric-installer = "0.11.1"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,59 @@ import spock.lang.Unroll

import net.fabricmc.loom.test.util.GradleProjectTestTrait
import net.fabricmc.loom.test.util.ServerRunner
import net.fabricmc.loom.util.ZipUtils

import static net.fabricmc.loom.test.LoomTestConstants.*
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

@Timeout(value = 30, unit = TimeUnit.MINUTES)
class FabricAPITest extends Specification implements GradleProjectTestTrait {
private static final String API_VERSION = "0.0.0+loom"

@Unroll
def "build and run (gradle #version, mixin ap disabled: #disableMixinAp)"() {
setup:
def gradle = gradleProject(
repo: "https://github.com/FabricMC/fabric.git",
commit: "f091af96c53963fadf9dbc391c67bb40e5678a96",
commit: "23e8616e7457d7d4a65119b93952d134607ffc5c",
version: version,
patch: "fabric_api"
)

gradle.enableMultiProjectOptimisation()

// Disable the mixin ap if needed. Fabric API is a large enough test project to see if something breaks.
def mixinApPatch = ""

if (disableMixinAp) {
mixinApPatch = """

gradle.buildGradle << """
allprojects {
loom.mixin.useLegacyMixinAp = false
}
""".stripIndent()
}

// Set the version to something constant
gradle.buildGradle.text = gradle.buildGradle.text.replace('project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()', "\"$API_VERSION\"") + mixinApPatch
def minecraftVersion = "23w45a"
def server = ServerRunner.create(gradle.projectDir, minecraftVersion)
.withMod(gradle.getOutputFile("fabric-api-999.0.0.jar"))

// Test that the dependent mod can be built against the previously built fabric-api
def dependentMod = gradleProject(project: "minimalBase", version: version)
dependentMod.buildGradle << """
repositories {
mavenLocal()
}

loom {
loom.mixin.useLegacyMixinAp = ${!disableMixinAp}
}

dependencies {
minecraft "com.mojang:minecraft:${minecraftVersion}"
mappings "net.fabricmc:yarn:${minecraftVersion}+build.1:v2"

def server = ServerRunner.create(gradle.projectDir, "23w33a")
.withMod(gradle.getOutputFile("fabric-api-${API_VERSION}.jar"))
modImplementation "net.fabricmc.fabric-api:fabric-api:999.0.0"
}
"""
when:
def result = gradle.run(tasks: [
"clean",
"build",
"publishToMavenLocal"
], args: [
Expand All @@ -85,19 +99,31 @@ class FabricAPITest extends Specification implements GradleProjectTestTrait {
gradle.printOutputFiles()

def serverResult = server.run()
def dependentModResult = dependentMod.run(task: "build")

then:
result.task(":build").outcome == SUCCESS
result.task(":prepareRemapJar").outcome == SUCCESS

new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/13.0.11/fabric-biome-api-v1-13.0.11.jar").exists()
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/13.0.11/fabric-biome-api-v1-13.0.11-sources.jar").exists()
def biomeApiJar = new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/999.0.0/fabric-biome-api-v1-999.0.0.jar")
def manifest = ZipUtils.unpack(biomeApiJar.toPath(), "META-INF/MANIFEST.MF").toString()
new File(gradle.mavenLocalDir, "net/fabricmc/fabric-api/fabric-biome-api-v1/999.0.0/fabric-biome-api-v1-999.0.0-sources.jar").exists()

if (disableMixinAp) {
manifest.contains("Fabric-Loom-Mixin-Remap-Type=static")
} else {
manifest.contains("Fabric-Loom-Mixin-Remap-Type=mixin")
}

serverResult.successful()
serverResult.output.contains("- fabric-api $API_VERSION")
serverResult.output.contains("- fabric-api 999.0.0")

dependentModResult.task(":build").outcome == SUCCESS

where:
[version, disableMixinAp] << [
[DEFAULT_GRADLE],
[false, true]
[PRE_RELEASE_GRADLE],
[false, true].shuffled()
].combinations()
}
}
30 changes: 23 additions & 7 deletions src/test/resources/patches/fabric_api.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
diff --git a/build.gradle b/build.gradle
--- a/build.gradle (revision 14d319c0729baf781e171e3c9f845fda55670f1b)
+++ b/build.gradle (date 1688330748664)
@@ -37,17 +37,7 @@
throw new NullPointerException("Could not find version for " + project.name)
}

--- a/build.gradle (revision 23e8616e7457d7d4a65119b93952d134607ffc5c)
+++ b/build.gradle (date 1699535194191)
@@ -13,7 +13,7 @@

def ENV = System.getenv()

-version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
+version = "999.0.0"
logger.lifecycle("Building Fabric: " + version)


@@ -22,24 +22,7 @@
import org.apache.commons.codec.digest.DigestUtils

def getSubprojectVersion(project) {
- // Get the version from the gradle.properties file
- def version = project.properties["${project.name}-version"]
-
- if (!version) {
- throw new NullPointerException("Could not find version for " + project.name)
- }
-
- if (grgit == null) {
- return version + "+nogit"
- }
Expand All @@ -16,7 +32,7 @@ diff --git a/build.gradle b/build.gradle
- }
-
- return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
+ return version
+ return "999.0.0"
}

def getBranch() {