Skip to content

Commit

Permalink
fix: make JarNester deterministic
Browse files Browse the repository at this point in the history
Sorts the list of jars to nest before adding them to fabric.mod.json to ensure the ordering is deterministic.
  • Loading branch information
ashhhleyyy committed Oct 20, 2024
1 parent 6b18a7b commit 29c2166
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/net/fabricmc/loom/build/nesting/JarNester.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public static void nestJars(Collection<File> jars, File modJar, Logger logger) {

Preconditions.checkArgument(FabricModJsonFactory.isModJar(modJar), "Cannot nest jars into none mod jar " + modJar.getName());

// Ensure deterministic ordering of entries in fabric.mod.json
Collection<File> sortedJars = jars.stream().sorted().toList();

try {
ZipUtils.add(modJar.toPath(), jars.stream().map(file -> {
ZipUtils.add(modJar.toPath(), sortedJars.stream().map(file -> {
try {
return new Pair<>("META-INF/jars/" + file.getName(), Files.readAllBytes(file.toPath()));
} catch (IOException e) {
Expand All @@ -67,7 +70,7 @@ public static void nestJars(Collection<File> jars, File modJar, Logger logger) {
nestedJars = new JsonArray();
}

for (File file : jars) {
for (File file : sortedJars) {
String nestedJarPath = "META-INF/jars/" + file.getName();
Preconditions.checkArgument(FabricModJsonFactory.isModJar(file), "Cannot nest none mod jar: " + file.getName());

Expand Down

0 comments on commit 29c2166

Please sign in to comment.