diff options
| author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-12-02 19:52:14 +0200 |
|---|---|---|
| committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-12-02 19:52:14 +0200 |
| commit | 028ae4a4ac5fe0a2ff5e866af276726f28cc684e (patch) | |
| tree | d6733582d437fd9fdd2a1f8d639baa3b7681455c /src/main | |
| parent | b8552d1137562f98bd0039479014f480e377b448 (diff) | |
| download | architectury-loom-028ae4a4ac5fe0a2ff5e866af276726f28cc684e.tar.gz architectury-loom-028ae4a4ac5fe0a2ff5e866af276726f28cc684e.tar.bz2 architectury-loom-028ae4a4ac5fe0a2ff5e866af276726f28cc684e.zip | |
Add experimental access transforming support
Diffstat (limited to 'src/main')
3 files changed, 61 insertions, 6 deletions
diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java index f328cce3..4c74b343 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java @@ -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(); } diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java index ab93c5b8..d2f5b22f 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java @@ -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 { diff --git a/src/main/java/net/fabricmc/loom/util/JarUtil.java b/src/main/java/net/fabricmc/loom/util/JarUtil.java new file mode 100644 index 00000000..e3690373 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/util/JarUtil.java @@ -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()); + } + } +} |
