Fix aw2at tests, add Yarn 1.16 test (#45)

* Fix aw2at tests

* Clean up the code anyway because it was messy

* Normalise everything to LF

* ...really, another typo?

* Import ordering

* Add Yarn aw2at test

* wow bad os
This commit is contained in:
Juuxel
2021-09-12 16:41:53 +03:00
committed by GitHub
parent 848a6a548f
commit b7d1cf3a45
15 changed files with 203 additions and 33 deletions

View File

@@ -24,6 +24,7 @@
package net.fabricmc.loom.task;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -67,6 +68,7 @@ import dev.architectury.tinyremapper.TinyUtils;
import dev.architectury.tinyremapper.extension.mixin.MixinExtension;
import org.cadixdev.at.AccessTransformSet;
import org.cadixdev.at.io.AccessTransformFormats;
import org.cadixdev.lorenz.MappingSet;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
@@ -99,6 +101,7 @@ import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.LfWriter;
import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
import net.fabricmc.loom.util.ZipReprocessorUtil;
@@ -494,8 +497,8 @@ public class RemapJarTask extends Jar {
throw new NoSuchFileException("Could not find AW '" + aw + "' to convert into AT!");
}
try (InputStream in = Files.newInputStream(awPath)) {
at.merge(Aw2At.toAccessTransformSet(in));
try (BufferedReader reader = Files.newBufferedReader(awPath, StandardCharsets.UTF_8)) {
at.merge(Aw2At.toAccessTransformSet(reader));
}
Files.delete(awPath);
@@ -503,10 +506,13 @@ public class RemapJarTask extends Jar {
LoomGradleExtension extension = LoomGradleExtension.get(getProject());
TinyTree mappings = extension.shouldGenerateSrgTiny() ? extension.getMappingsProvider().getMappingsWithSrg() : extension.getMappingsProvider().getMappings();
TinyMappingsReader reader = new TinyMappingsReader(mappings, fromM.get(), toM.get());
at = at.remap(reader.read());
try (Writer writer = Files.newBufferedWriter(atPath)) {
try (TinyMappingsReader reader = new TinyMappingsReader(mappings, fromM.get(), toM.get())) {
MappingSet mappingSet = reader.read();
at = at.remap(mappingSet);
}
try (Writer writer = new LfWriter(Files.newBufferedWriter(atPath))) {
AccessTransformFormats.FML.write(writer, at);
}
}

View File

@@ -0,0 +1,43 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.util;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
/**
* A {@link BufferedWriter} that writes {@code \n} (LF) instead of {@link System#lineSeparator()}.
*/
public class LfWriter extends BufferedWriter {
public LfWriter(Writer out) {
super(out);
}
@Override
public void newLine() throws IOException {
write('\n');
}
}

View File

@@ -27,9 +27,6 @@ package net.fabricmc.loom.util.aw2at;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import org.cadixdev.at.AccessChange;
@@ -82,27 +79,25 @@ public final class Aw2At {
remapJar.getAtAccessWideners().addAll(extension.getForge().getExtraAccessWideners());
}
public static AccessTransformSet toAccessTransformSet(InputStream in) throws IOException {
public static AccessTransformSet toAccessTransformSet(BufferedReader reader) throws IOException {
AccessTransformSet atSet = AccessTransformSet.create();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
new AccessWidenerReader(new AccessWidenerReader.Visitor() {
@Override
public void visitClass(String name, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(name).merge(toAt(access));
}
new AccessWidenerReader(new AccessWidenerReader.Visitor() {
@Override
public void visitClass(String name, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(name).merge(toAt(access));
}
@Override
public void visitMethod(String owner, String name, String descriptor, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(owner).mergeMethod(MethodSignature.of(name, descriptor), toAt(access));
}
@Override
public void visitMethod(String owner, String name, String descriptor, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(owner).mergeMethod(MethodSignature.of(name, descriptor), toAt(access));
}
@Override
public void visitField(String owner, String name, String descriptor, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(owner).mergeField(name, toAt(access));
}
}).read(reader);
}
@Override
public void visitField(String owner, String name, String descriptor, AccessWidenerReader.AccessType access) {
atSet.getOrCreateClass(owner).mergeField(name, toAt(access));
}
}).read(reader);
return atSet;
}

View File

@@ -31,7 +31,7 @@ import static net.fabricmc.loom.test.LoomTestConstants.*
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
class Aw2AtTest extends Specification implements GradleProjectTestTrait {
def "build"() {
def "build"() { // 1.17+ uses a new srg naming pattern
setup:
def gradle = gradleProject(project: "forge/aw2At", version: DEFAULT_GRADLE)
@@ -43,9 +43,9 @@ class Aw2AtTest extends Specification implements GradleProjectTestTrait {
gradle.getOutputZipEntry("fabric-example-mod-1.0.0.jar", "META-INF/accesstransformer.cfg") == expected(gradle).replaceAll('\r', '')
}
def "legacy build"() {
def "legacy build (mojmap)"() { // old 1.16 srg names
setup:
def gradle = gradleProject(project: "forge/legacyAw2At", version: DEFAULT_GRADLE)
def gradle = gradleProject(project: "forge/legacyAw2AtMojmap", version: DEFAULT_GRADLE)
when:
def result = gradle.run(task: "build")
@@ -55,7 +55,19 @@ class Aw2AtTest extends Specification implements GradleProjectTestTrait {
gradle.getOutputZipEntry("fabric-example-mod-1.0.0.jar", "META-INF/accesstransformer.cfg") == expected(gradle).replaceAll('\r', '')
}
String expected(GradleProject gradle) {
def "legacy build (yarn)"() { // old 1.16 srg names
setup:
def gradle = gradleProject(project: "forge/legacyAw2AtYarn", version: DEFAULT_GRADLE)
when:
def result = gradle.run(task: "build")
then:
result.task(":build").outcome == SUCCESS
gradle.getOutputZipEntry("fabric-example-mod-1.0.0.jar", "META-INF/accesstransformer.cfg") == expected(gradle).replaceAll('\r', '')
}
private static String expected(GradleProject gradle) {
return new File(gradle.projectDir, "expected.accesstransformer.cfg").text
}
}

View File

@@ -1,3 +1,3 @@
accessWidener v1 named
accessible method net/minecraft/world/level/GameRules$BooleanValue create (Z)Lnet/minecraft/world/GameRules$Type;
extendable method net/minecraft/world/level/block/IronBarsBlock attchsTo (Lnet/minecraft/world/level/block/state/BlockState;Z)Z
accessible method net/minecraft/world/level/GameRules$BooleanValue create (Z)Lnet/minecraft/world/level/GameRules$Type;
extendable method net/minecraft/world/level/block/IronBarsBlock attachsTo (Lnet/minecraft/world/level/block/state/BlockState;Z)Z

View File

@@ -1,3 +1,3 @@
accessWidener v1 named
accessible method net/minecraft/world/level/GameRules$BooleanValue create (Z)Lnet/minecraft/world/GameRules$Type;
extendable method net/minecraft/world/level/block/IronBarsBlock attchsTo (Lnet/minecraft/world/level/block/state/BlockState;Z)Z
accessible method net/minecraft/world/level/GameRules$BooleanValue create (Z)Lnet/minecraft/world/level/GameRules$Type;
extendable method net/minecraft/world/level/block/IronBarsBlock attachsTo (Lnet/minecraft/world/level/block/state/BlockState;Z)Z

View File

@@ -0,0 +1,89 @@
plugins {
id 'dev.architectury.loom'
id 'maven-publish'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
def mcVersion = '1.16.5'
def forgeVersion = '36.2.2'
loom {
accessWidenerPath = file('src/main/resources/my.accesswidener')
forge {
convertAccessWideners = true
}
}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:$mcVersion"
mappings "net.fabricmc:yarn:$project.yarn_mappings:v2"
forge "net.minecraftforge:forge:$mcVersion-$forgeVersion"
}
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}

View File

@@ -0,0 +1,2 @@
public net.minecraft.world.GameRules$BooleanValue func_223568_b(Z)Lnet/minecraft/world/GameRules$RuleType;
public-f net.minecraft.block.PaneBlock func_220112_a(Lnet/minecraft/block/BlockState;Z)Z

View File

@@ -0,0 +1,18 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
loader_version=0.11.2
yarn_mappings=1.16.5+build.5
# Mod Properties
mod_version = 1.0.0
maven_group = com.example
archives_base_name = fabric-example-mod
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.31.0+1.16
loom.platform=forge

View File

@@ -0,0 +1,2 @@
rootProject.name = "fabric-example-mod"

View File

@@ -0,0 +1,3 @@
accessWidener v1 named
accessible method net/minecraft/world/GameRules$BooleanRule create (Z)Lnet/minecraft/world/GameRules$Type;
extendable method net/minecraft/block/PaneBlock connectsTo (Lnet/minecraft/block/BlockState;Z)Z