Skip to content

Commit fcea5f0

Browse files
committed
Remove hard-coding of several assumptions about the NeoForm config
1 parent 96e5a7c commit fcea5f0

File tree

7 files changed

+50
-12
lines changed

7 files changed

+50
-12
lines changed

src/main/java/net/neoforged/neoform/runtime/actions/PatchActionFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.neoforged.neoform.runtime.graph.NodeOutput;
66
import net.neoforged.neoform.runtime.graph.NodeOutputType;
77
import net.neoforged.neoform.runtime.utils.ToolCoordinate;
8+
import org.jetbrains.annotations.Nullable;
89

910
import java.util.List;
1011
import java.util.Objects;
@@ -13,11 +14,15 @@ public final class PatchActionFactory {
1314

1415
public static NodeOutput makeAction(ExecutionNodeBuilder builder,
1516
DataSource patches,
16-
NodeOutput sources,
17+
@Nullable NodeOutput sources,
1718
String basePathPrefix,
1819
String modifiedPathPrefix) {
1920
Objects.requireNonNull(patches, "patches");
20-
builder.input("input", sources.asInput());
21+
if (sources != null ) {
22+
builder.input("input", sources.asInput());
23+
} else if (!builder.hasInput("input")) {
24+
throw new IllegalStateException("The builder must have an input named 'input' when no explit sources are given.");
25+
}
2126
var mainOutput = builder.output("output", NodeOutputType.ZIP, "ZIP file containing the patched sources");
2227
builder.output("outputRejects", NodeOutputType.ZIP, "ZIP file containing the rejected patches");
2328

src/main/java/net/neoforged/neoform/runtime/actions/SplitResourcesFromClassesAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt
6767
Path mappingsPath = null;
6868
if (generateDistManifestSettings != null) {
6969
otherDistJarPath = environment.getRequiredInputPath(INPUT_OTHER_DIST_JAR);
70-
mappingsPath = environment.getRequiredInputPath(INPUT_MAPPINGS);
70+
mappingsPath = environment.getInputPath(INPUT_MAPPINGS);
7171
}
7272

7373
var classesJar = environment.getOutputPath("output");
@@ -132,6 +132,7 @@ private static void generateDistSourceManifest(String distId,
132132
ZipFile jar,
133133
String otherDistId,
134134
Path otherDistJarPath,
135+
@Nullable
135136
Path mappingsPath,
136137
JarOutputStream resourcesJarOut) throws IOException {
137138
var mappings = mappingsPath != null ? IMappingFile.load(mappingsPath.toFile()) : null;

src/main/java/net/neoforged/neoform/runtime/cli/RunNeoFormCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ private void execute(NeoFormEngine engine) throws InterruptedException, IOExcept
348348
));
349349

350350
if (neededResults.isEmpty()) {
351-
System.err.println("No results requested. Available results: " + engine.getAvailableResults());
351+
System.err.println("No results requested using --write-result=<result>:<path>. Available results: " + engine.getAvailableResults());
352352
System.exit(1);
353353
}
354354

src/main/java/net/neoforged/neoform/runtime/engine/NeoFormEngine.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.neoforged.neoform.runtime.graph.ExecutionNode;
2929
import net.neoforged.neoform.runtime.graph.ExecutionNodeBuilder;
3030
import net.neoforged.neoform.runtime.graph.NodeExecutionException;
31+
import net.neoforged.neoform.runtime.graph.NodeInput;
3132
import net.neoforged.neoform.runtime.graph.NodeOutput;
3233
import net.neoforged.neoform.runtime.graph.NodeOutputType;
3334
import net.neoforged.neoform.runtime.graph.ResultRepresentation;
@@ -182,16 +183,18 @@ public void loadNeoFormProcess(NeoFormDistConfig distConfig) {
182183
addNodeForStep(graph, distConfig, step);
183184
}
184185

185-
var renameOutput = graph.getRequiredOutput("rename", "output");
186-
187186
var sourcesOutput = graph.getRequiredOutput("patch", "output");
188187

189188
var compiledOutput = addRecompileStep(distConfig, sourcesOutput);
190189

191190
var sourcesAndCompiledOutput = addMergeWithSourcesStep(compiledOutput, sourcesOutput);
192191

193192
// Register the sources and the compiled binary as results
194-
graph.setResult("vanillaDeobfuscated", renameOutput);
193+
// Vanilla deobfuscated is equivalent to the input to the decompiler
194+
var decompile = graph.getNode("decompile");
195+
if (decompile != null && decompile.inputs().get("input") instanceof NodeInput.NodeInputForOutput nodeInputForOutput) {
196+
graph.setResult("vanillaDeobfuscated", nodeInputForOutput.getOutput());
197+
}
195198
graph.setResult("sources", sourcesOutput);
196199
graph.setResult("compiled", compiledOutput);
197200
graph.setResult("sourcesAndCompiled", sourcesAndCompiledOutput);
@@ -343,11 +346,15 @@ private void addNodeForStep(ExecutionGraph graph, NeoFormDistConfig config, NeoF
343346

344347
action.generateSplitManifest("client", "server");
345348
builder.input(SplitResourcesFromClassesAction.INPUT_OTHER_DIST_JAR, serverJarInput);
346-
builder.input(SplitResourcesFromClassesAction.INPUT_MAPPINGS, graph.getRequiredOutput("mergeMappings", "output").asInput());
349+
if (graph.hasOutput("mergeMappings", "output")) {
350+
builder.input(SplitResourcesFromClassesAction.INPUT_MAPPINGS, graph.getRequiredOutput("mergeMappings", "output").asInput());
351+
}
347352
} else if ("stripServer".equals(step.getId())) {
348353
action.generateSplitManifest("server", "client");
349354
builder.input(SplitResourcesFromClassesAction.INPUT_OTHER_DIST_JAR, graph.getRequiredOutput("downloadClient", "output").asInput());
350-
builder.input(SplitResourcesFromClassesAction.INPUT_MAPPINGS, graph.getRequiredOutput("mergeMappings", "output").asInput());
355+
if (graph.hasOutput("mergeMappings", "output")) {
356+
builder.input(SplitResourcesFromClassesAction.INPUT_MAPPINGS, graph.getRequiredOutput("mergeMappings", "output").asInput());
357+
}
351358
}
352359
}
353360

@@ -363,11 +370,10 @@ private void addNodeForStep(ExecutionGraph graph, NeoFormDistConfig config, NeoF
363370
));
364371
}
365372
case "patch" -> {
366-
builder.clearInputs();
367373
PatchActionFactory.makeAction(
368374
builder,
369375
getRequiredDataSource("patches"),
370-
graph.getRequiredOutput("inject", "output"),
376+
null,
371377
"a/",
372378
"b/"
373379
);
@@ -790,6 +796,11 @@ public <T> T getRequiredInput(String id, ResultRepresentation<T> representation)
790796
return node.getRequiredInput(id).getValue(representation);
791797
}
792798

799+
@Override
800+
public <T> T getInput(String id, ResultRepresentation<T> representation) throws IOException {
801+
return node.hasInput(id) ? node.getRequiredInput(id).getValue(representation) : null;
802+
}
803+
793804
@Override
794805
public Path getOutputPath(String id) {
795806
var output = node.getRequiredOutput(id);

src/main/java/net/neoforged/neoform/runtime/engine/ProcessingEnvironment.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.neoforged.neoform.runtime.artifacts.ArtifactManager;
44
import net.neoforged.neoform.runtime.graph.ResultRepresentation;
55
import net.neoforged.problems.ProblemReporter;
6+
import org.jetbrains.annotations.Nullable;
67

78
import java.io.IOException;
89
import java.io.UncheckedIOException;
@@ -43,8 +44,20 @@ default Path getRequiredInputPath(String id) {
4344
}
4445
}
4546

47+
@Nullable
48+
default Path getInputPath(String id) {
49+
try {
50+
return getInput(id, ResultRepresentation.PATH);
51+
} catch (IOException e) {
52+
throw new UncheckedIOException(e); // Getting a path should not fail
53+
}
54+
}
55+
4656
<T> T getRequiredInput(String id, ResultRepresentation<T> representation) throws IOException;
4757

58+
@Nullable
59+
<T> T getInput(String id, ResultRepresentation<T> representation) throws IOException;
60+
4861
/**
4962
* Also automatically calls {@link #setOutput(String, Path)} with the generated path.
5063
*/

src/main/java/net/neoforged/neoform/runtime/graph/ExecutionNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public Map<String, NodeInput> inputs() {
125125
return inputs;
126126
}
127127

128+
public boolean hasInput(String id) {
129+
return inputs.containsKey(id);
130+
}
131+
128132
public boolean hasOutput(String id) {
129133
return outputs.containsKey(id);
130134
}

src/main/java/net/neoforged/neoform/runtime/graph/NodeInput.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ void setNode(ExecutionNode node) {
3737

3838
public abstract <T> T getValue(ResultRepresentation<T> representation) throws IOException;
3939

40-
static final class NodeInputForOutput extends NodeInput {
40+
public static final class NodeInputForOutput extends NodeInput {
4141
private NodeOutput output;
4242

4343
public NodeInputForOutput(NodeOutput output) {
4444
this.output = output;
4545
}
4646

47+
public NodeOutput getOutput() {
48+
return output;
49+
}
50+
4751
@Override
4852
public void replaceReferences(NodeOutput oldOutput, NodeOutput newOutput) {
4953
if (this.output == oldOutput) {

0 commit comments

Comments
 (0)