mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-03 05:57:42 -05:00
Add experimental access transforming support
This commit is contained in:
@@ -42,7 +42,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
@@ -159,7 +158,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
}
|
||||
|
||||
TinyTree yarnWithSrg = getExtension().getMappingsProvider().getMappingsWithSrg();
|
||||
AtRemapper.remap(output, yarnWithSrg);
|
||||
CoreModClassRemapper.remapJar(output, yarnWithSrg, getProject().getLogger());
|
||||
}
|
||||
}
|
||||
@@ -171,10 +169,6 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
.withMappings(out -> JSR_TO_JETBRAINS.forEach(out::acceptClass))
|
||||
.renameInvalidLocals(true)
|
||||
.rebuildSourceFilenames(true)
|
||||
/* FORGE: Required for classes like aej$OptionalNamedTag (1.16.4) which are added by Forge patches.
|
||||
* They won't get remapped to their proper packages, so IllegalAccessErrors will happen without ._.
|
||||
*/
|
||||
.fixPackageAccess(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.minecraftforge.accesstransformer.TransformerProcessor;
|
||||
import net.minecraftforge.binarypatcher.ConsoleTool;
|
||||
import net.minecraftforge.gradle.mcp.util.MCPRuntime;
|
||||
import net.minecraftforge.gradle.mcp.util.MCPWrapper;
|
||||
@@ -66,6 +67,7 @@ import org.gradle.api.logging.Logger;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
import net.fabricmc.loom.util.DownloadUtil;
|
||||
import net.fabricmc.loom.util.JarUtil;
|
||||
import net.fabricmc.loom.util.function.FsPathConsumer;
|
||||
import net.fabricmc.loom.util.function.IoConsumer;
|
||||
import net.fabricmc.loom.util.ManifestVersion;
|
||||
@@ -292,6 +294,18 @@ public class MinecraftProvider extends DependencyProvider {
|
||||
|
||||
walkFileSystems(injection, minecraftClientPatchedSrgJar, it -> !it.getFileName().toString().equals("MANIFEST.MF"), this::copyReplacing);
|
||||
walkFileSystems(injection, minecraftServerPatchedSrgJar, it -> !it.getFileName().toString().equals("MANIFEST.MF"), this::copyReplacing);
|
||||
|
||||
logger.lifecycle(":access transforming");
|
||||
File clientAtJar = File.createTempFile("atclient", ".jar");
|
||||
File serverAtJar = File.createTempFile("atserver", ".jar");
|
||||
File clientAt = File.createTempFile("atclient", ".cfg");
|
||||
File serverAt = File.createTempFile("atserver", ".cfg");
|
||||
Files.copy(minecraftClientPatchedSrgJar, clientAtJar);
|
||||
Files.copy(minecraftServerPatchedSrgJar, serverAtJar);
|
||||
JarUtil.extractFile(clientAtJar, "META-INF/accesstransformer.cfg", clientAt);
|
||||
JarUtil.extractFile(serverAtJar, "META-INF/accesstransformer.cfg", serverAt);
|
||||
TransformerProcessor.main("--inJar", clientAtJar.getAbsolutePath(), "--outJar", minecraftClientPatchedSrgJar.getAbsolutePath(), "--atFile", clientAt.getAbsolutePath());
|
||||
TransformerProcessor.main("--inJar", serverAtJar.getAbsolutePath(), "--outJar", minecraftServerPatchedSrgJar.getAbsolutePath(), "--atFile", serverAt.getAbsolutePath());
|
||||
}
|
||||
|
||||
private void remapPatchedJars(Logger logger) throws IOException {
|
||||
|
||||
47
src/main/java/net/fabricmc/loom/util/JarUtil.java
Normal file
47
src/main/java/net/fabricmc/loom/util/JarUtil.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 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.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Working with jars.
|
||||
*
|
||||
* @author Juuz
|
||||
*/
|
||||
public final class JarUtil {
|
||||
public static void extractFile(File jar, String filePath, File target) throws IOException {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + jar.toURI()), ImmutableMap.of("create", false))) {
|
||||
Files.copy(fs.getPath(filePath), target.toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user