Skip to content

Commit

Permalink
add options for writing split-version intermediary to split files
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Sep 21, 2024
1 parent 751e9e5 commit 1d4cf37
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
46 changes: 25 additions & 21 deletions src/main/java/net/fabricmc/stitch/commands/GenStateSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,30 @@ public void generate(File file, Classpath storageClient, Classpath storageServer

tmp.mkdirs();

BufferedWriter cw = new BufferedWriter(new FileWriter(client));
BufferedWriter sw = new BufferedWriter(new FileWriter(server));
generate(client, server, storageClient, storageServer, storageClientOld, storageServerOld);

cw.write("v1\tofficial\t" + targetNamespace + "\n");
sw.write("v1\tofficial\t" + targetNamespace + "\n");
try {
new CommandCombineTiny().run(new String[] {
client.getAbsolutePath(),
server.getAbsolutePath(),
file.getAbsolutePath()
});
} catch (Exception e) {
throw new IOException(e);
}


client.delete();
server.delete();
tmp.delete();
}

public void generate(File clientFile, File serverFile, Classpath storageClient, Classpath storageServer, Classpath storageClientOld, Classpath storageServerOld) throws IOException {
BufferedWriter cw = (clientFile == null) ? null : new BufferedWriter(new FileWriter(clientFile));
BufferedWriter sw = (serverFile == null) ? null : new BufferedWriter(new FileWriter(serverFile));

if (cw != null) cw.write("v1\tofficial\t" + targetNamespace + "\n");
if (sw != null) sw.write("v1\tofficial\t" + targetNamespace + "\n");

// hack to make sure we don't write them multiple times
Set<String> serverClasses = new HashSet<>();
Expand Down Expand Up @@ -78,23 +97,8 @@ public void generate(File file, Classpath storageClient, Classpath storageServer

serverClasses.clear();

cw.close();
sw.close();

try {
new CommandCombineTiny().run(new String[] {
client.getAbsolutePath(),
server.getAbsolutePath(),
file.getAbsolutePath()
});
} catch (Exception e) {
throw new IOException(e);
}


client.delete();
server.delete();
tmp.delete();
if (cw != null) cw.close();
if (sw != null) sw.close();
}

private String next(AbstractJarEntry centry, AbstractJarEntry sentry, String prefix) {
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/net/fabricmc/stitch/util/IntermediaryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ public static void generateMappings(SplitArgs args) throws IOException {
}

System.err.println("Generating new mappings...");
state.generate(args.newIntermediaryFile, storageClientNew, storageServerNew, storageClientOld, storageServerOld);
if (args.newIntermediaryFile != null) {
state.generate(args.newIntermediaryFile, storageClientNew, storageServerNew, storageClientOld, storageServerOld);
} else {
state.generate(args.newClientIntermediaryFile, args.newServerIntermediaryFile, storageClientNew, storageServerNew, storageClientOld, storageServerOld);
}
System.err.println("Done!");
}

Expand Down Expand Up @@ -321,6 +325,8 @@ public static class SplitArgs extends Args {
File oldClientIntermediaryFile;
File oldServerIntermediaryFile;
File newIntermediaryFile;
File newClientIntermediaryFile;
File newServerIntermediaryFile;
File clientMatchesFile;
File serverMatchesFile;
File clientServerMatchesFile;
Expand Down Expand Up @@ -442,6 +448,20 @@ public SplitArgsBuilder oldServerIntermediaryFile(File file) {

public SplitArgsBuilder newIntermediaryFile(File file) {
args.newIntermediaryFile = file;
args.newClientIntermediaryFile = null;
args.newServerIntermediaryFile = null;
return this;
}

public SplitArgsBuilder newClientIntermediaryFile(File file) {
args.newIntermediaryFile = null;
args.newClientIntermediaryFile = file;
return this;
}

public SplitArgsBuilder newServerIntermediaryFile(File file) {
args.newIntermediaryFile = null;
args.newServerIntermediaryFile = file;
return this;
}

Expand Down

0 comments on commit 1d4cf37

Please sign in to comment.