Merge remote-tracking branch 'architectury/dev/0.10.0' into dev/0.10.0

This commit is contained in:
shedaniel
2021-09-18 13:59:34 +08:00
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;
@@ -101,6 +103,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.TinyRemapperHelper;
import net.fabricmc.loom.util.ZipReprocessorUtil;
@@ -496,8 +499,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);
@@ -505,10 +508,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;
}