From cb2fb3f0a037916f7dbad5698b19c24530d589ad Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Fri, 15 Apr 2022 22:46:25 +0100 Subject: [PATCH 1/4] Quiltify, and add support for quilt's sided annotations (https://github.com/QuiltMC/quilt-loader/pull/63) --- build.gradle | 1 + .../fabricmc/stitch/merge/ClassMerger.java | 76 +++++++++++++++++-- .../net/fabricmc/stitch/merge/JarMerger.java | 15 +++- 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 5a9873f..69e6d0e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "java" id "java-library" id "maven-publish" + id "eclipse" id "net.minecrell.licenser" version "0.4.1" } diff --git a/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java b/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java index 738a195..9cbceef 100644 --- a/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java +++ b/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java @@ -23,10 +23,18 @@ import java.util.*; public class ClassMerger { + // Fabric private static final String SIDE_DESCRIPTOR = "Lnet/fabricmc/api/EnvType;"; private static final String ITF_DESCRIPTOR = "Lnet/fabricmc/api/EnvironmentInterface;"; private static final String ITF_LIST_DESCRIPTOR = "Lnet/fabricmc/api/EnvironmentInterfaces;"; private static final String SIDED_DESCRIPTOR = "Lnet/fabricmc/api/Environment;"; + // Quilt + private static final String QUILT_CLIENT_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnly;"; + private static final String QUILT_SERVER_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnly;"; + private static final String QUILT_CLIENT_ITF_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnlyInterface;"; + private static final String QUILT_CLIENT_ITF_LIST_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnlyInterfaces;"; + private static final String QUILT_SERVER_ITF_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnlyInterface;"; + private static final String QUILT_SERVER_ITF_LIST_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnlyInterfaces;"; private abstract class Merger { private final Map entriesClient, entriesServer; @@ -89,24 +97,41 @@ private static void visitItfAnnotation(AnnotationVisitor av, String side, List entriesClient, entriesServer; private final Set entriesAll; private boolean removeSnowmen = false; private boolean offsetSyntheticsParams = false; + private boolean useQuiltAnnotations = true; public JarMerger(File inputClient, File inputServer, File output) throws IOException { if (output.exists()) { @@ -79,6 +82,10 @@ public void enableSyntheticParamsOffset() { offsetSyntheticsParams = true; } + public void setUseQuiltAnnotations(boolean use) { + useQuiltAnnotations = use; + } + @Override public void close() throws IOException { inputClientFs.close(); @@ -170,7 +177,8 @@ public void merge() throws IOException { result = entry1; } else { if (isClass) { - result = new Entry(entry1.path, entry1.metadata, CLASS_MERGER.merge(entry1.data, entry2.data)); + ClassMerger classMerger = useQuiltAnnotations ? CLASS_MERGER_QUILT : CLASS_MERGER_FABRIC; + result = new Entry(entry1.path, entry1.metadata, classMerger.merge(entry1.data, entry2.data)); } else { // FIXME: More heuristics? result = entry1; @@ -195,7 +203,8 @@ public void merge() throws IOException { ClassVisitor visitor = writer; if (side != null) { - visitor = new ClassMerger.SidedClassVisitor(StitchUtil.ASM_VERSION, visitor, side); + visitor = new ClassMerger.SidedClassVisitor(StitchUtil.ASM_VERSION, visitor, side) + .setUseQuiltAnnotations(useQuiltAnnotations); } if (removeSnowmen) { From 1607c55546dbdd846e22acbcab54aabb7e4df275 Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Mon, 4 Jul 2022 01:27:59 +0100 Subject: [PATCH 2/4] Build test 1. --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 69e6d0e..d9b8475 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ repositories { url = "https://maven.fabricmc.net/" content { includeGroup("net.fabricmc") // I'd like to deprecate procyon, so we don't need to maintain it + includeGroup("cuchaz") } } } @@ -80,6 +81,7 @@ task allJar(type: Jar) { 'Main-Class': "net.fabricmc.stitch.Main" } archiveClassifier = 'all' + duplicatesStrategy = 'exclude' with jar } From e0463bf8e91e273a92563992fc507edb52c091e3 Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Mon, 4 Jul 2022 01:28:49 +0100 Subject: [PATCH 3/4] Build test 0. --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index d9b8475..ea0753c 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,6 @@ task allJar(type: Jar) { 'Main-Class': "net.fabricmc.stitch.Main" } archiveClassifier = 'all' - duplicatesStrategy = 'exclude' with jar } From 138009fed15d7fbdb4adbfa9a06743caaf9b5a73 Mon Sep 17 00:00:00 2001 From: AlexIIL Date: Mon, 24 Oct 2022 23:36:18 +0100 Subject: [PATCH 4/4] Change to type interface generation. --- .../fabricmc/stitch/merge/ClassMerger.java | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java b/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java index 9cbceef..a92aa63 100644 --- a/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java +++ b/src/main/java/net/fabricmc/stitch/merge/ClassMerger.java @@ -31,10 +31,6 @@ public class ClassMerger { // Quilt private static final String QUILT_CLIENT_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnly;"; private static final String QUILT_SERVER_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnly;"; - private static final String QUILT_CLIENT_ITF_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnlyInterface;"; - private static final String QUILT_CLIENT_ITF_LIST_DESC = "Lorg/quiltmc/loader/api/minecraft/ClientOnlyInterfaces;"; - private static final String QUILT_SERVER_ITF_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnlyInterface;"; - private static final String QUILT_SERVER_ITF_LIST_DESC = "Lorg/quiltmc/loader/api/minecraft/DedicatedServerOnlyInterfaces;"; private abstract class Merger { private final Map entriesClient, entriesServer; @@ -195,31 +191,17 @@ public byte[] merge(byte[] classClient, byte[] classServer) { if (useQuilt) { if (!clientItfs.isEmpty()) { - if (clientItfs.size() == 1) { - AnnotationVisitor envItf = nodeOut.visitAnnotation(QUILT_CLIENT_ITF_DESC, false); - envItf.visit("value", Type.getType("L" + clientItfs.get(0) + ";")); - } else { - AnnotationVisitor envInterfaces = nodeOut.visitAnnotation(QUILT_CLIENT_ITF_LIST_DESC, false); - AnnotationVisitor eiArray = envInterfaces.visitArray("value"); - for (String itf : clientItfs) { - AnnotationVisitor envItf = eiArray.visitAnnotation(null, QUILT_CLIENT_ITF_DESC); - envItf.visit("value", Type.getType("L" + itf + ";")); - } - } + for (String itf : clientItfs) { + int ref = TypeReference.CLASS_EXTENDS | nodeOut.interfaces.indexOf(itf) << 8; + nodeOut.visitTypeAnnotation(ref, null, QUILT_CLIENT_DESC, false); + } } if (!serverItfs.isEmpty()) { - if (serverItfs.size() == 1) { - AnnotationVisitor envItf = nodeOut.visitAnnotation(QUILT_SERVER_ITF_DESC, false); - envItf.visit("value", Type.getType("L" + serverItfs.get(0) + ";")); - } else { - AnnotationVisitor envInterfaces = nodeOut.visitAnnotation(QUILT_SERVER_ITF_LIST_DESC, false); - AnnotationVisitor eiArray = envInterfaces.visitArray("value"); - for (String itf : serverItfs) { - AnnotationVisitor envItf = eiArray.visitAnnotation(null, QUILT_SERVER_ITF_DESC); - envItf.visit("value", Type.getType("L" + itf + ";")); - } - } + for (String itf : serverItfs) { + int ref = TypeReference.CLASS_EXTENDS | nodeOut.interfaces.indexOf(itf) << 8; + nodeOut.visitTypeAnnotation(ref, null, QUILT_SERVER_DESC, false); + } } } else if (!clientItfs.isEmpty() || !serverItfs.isEmpty()) {