Skip to content

Commit 1d75464

Browse files
authored
add runarg to control prod flag (#1196)
1 parent 0dc510f commit 1d75464

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ protected File executeBuildMapPipeline(ModelManager modelManager, WurstGui gui,
766766
File targetMapFile = getBuildOutputMapFile(projectConfig, buildDir);
767767
targetMapFile = ensureWritableBuildOutput(targetMapFile, false);
768768

769-
CompilationResult result = compileScript(modelManager, gui, Optional.of(targetMapFile), projectConfig, buildDir, true);
769+
CompilationResult result = compileScript(modelManager, gui, Optional.of(targetMapFile), projectConfig, buildDir, isProductionBuild());
770770
injectMapData(gui, Optional.of(targetMapFile), result);
771771

772772
targetMapFile = ensureWritableBuildOutput(targetMapFile, true);
@@ -787,6 +787,10 @@ protected File executeBuildMapPipeline(ModelManager modelManager, WurstGui gui,
787787
return targetMapFile;
788788
}
789789

790+
protected boolean isProductionBuild() {
791+
return !runArgs.isDevBuild();
792+
}
793+
790794
protected File ensureWritableBuildOutput(File targetMapFile, boolean isFinalWrite) {
791795
String lockMessage = isFinalWrite
792796
? "The output map file is still in use and cannot be replaced.\nClick Retry, choose Rename to use a temporary file name, or Cancel."

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class RunArgs {
5454
private final RunOption optionHotStartmap;
5555
private final RunOption optionHotReload;
5656
private final RunOption optionTestTimeout;
57+
private final RunOption optionDevBuild;
5758
private int functionSplitLimit = 10000;
5859

5960
/**
@@ -144,6 +145,7 @@ public RunArgs(String... args) {
144145
optionHotReload = addOption("hotreload", "Reloads the mapscript after running the map with Jass Hot Code Reload (JHCR).");
145146

146147
optionBuild = addOption("build", "Builds an output map from the input map and library directories.");
148+
optionDevBuild = addOption("dev", "Builds an output map in development/run mode, so compiletime isProductionBuild() is false.");
147149
addOptionWithArg("workspaceroot", "The next argument should be the root folder of the project to build.", arg -> workspaceroot = arg);
148150
addOptionWithArg("inputmap", "The next argument should be the input map.", arg -> inputmap = arg);
149151
optionLua = addOption("lua", "Choose Lua as the compilation target.");
@@ -398,6 +400,10 @@ public boolean isBuild() {
398400
return optionBuild.isSet;
399401
}
400402

403+
public boolean isDevBuild() {
404+
return optionDevBuild.isSet;
405+
}
406+
401407
public String getWorkspaceroot() {
402408
return workspaceroot;
403409
}

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ public void pre124PatchPropagatesLegacyJassChecksToCompileArgs() throws Exceptio
252252
"modern build must not carry the legacy flag: " + modern.exposedCompileArgs());
253253
}
254254

255+
@Test
256+
public void devBuildFlagMakesBuildPipelineNonProduction() throws Exception {
257+
TestMapRequest dev = new TestMapRequest(projectWithPatch("v2.0"), Optional.empty(), Optional.empty(), List.of("-dev"));
258+
assertFalse(dev.exposedIsProductionBuild(), "CLI build with -dev should expose isProductionBuild() = false to compiletime");
259+
260+
TestMapRequest release = new TestMapRequest(projectWithPatch("v2.0"), Optional.empty(), Optional.empty());
261+
assertTrue(release.exposedIsProductionBuild(), "CLI build without -dev should remain production by default");
262+
}
263+
255264
private static Path projectWithPatch(String patch) throws Exception {
256265
Path project = Files.createTempDirectory("wurst-map-request-patch");
257266
Files.createDirectories(project.resolve("wurst"));
@@ -264,7 +273,11 @@ private static Path projectWithPatch(String patch) throws Exception {
264273

265274
private static final class TestMapRequest extends MapRequest {
266275
TestMapRequest(Path projectRoot, Optional<String> wc3Path, Optional<String> gameExePath) {
267-
super(null, Optional.empty(), List.of(), WFile.create(projectRoot), wc3Path, gameExePath);
276+
this(projectRoot, wc3Path, gameExePath, List.of());
277+
}
278+
279+
TestMapRequest(Path projectRoot, Optional<String> wc3Path, Optional<String> gameExePath, List<String> compileArgs) {
280+
super(null, Optional.empty(), compileArgs, WFile.create(projectRoot), wc3Path, gameExePath);
268281
}
269282

270283
Optional<GameVersion> detectedVersion() {
@@ -279,6 +292,10 @@ List<String> exposedCompileArgs() {
279292
return compileArgs;
280293
}
281294

295+
boolean exposedIsProductionBuild() {
296+
return isProductionBuild();
297+
}
298+
282299
@Override
283300
public Object execute(ModelManager modelManager) {
284301
return null;

de.peeeq.wurstscript/src/test/java/tests/wurstscript/utils/UtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public void compactOutputFlag() {
2020
Assert.assertTrue(new RunArgs("-compactOutput").isCompactOutput());
2121
}
2222

23+
@Test
24+
public void devBuildFlag() {
25+
Assert.assertTrue(new RunArgs("-dev").isDevBuild());
26+
Assert.assertFalse(new RunArgs().isDevBuild());
27+
}
28+
2329
@Test
2430
public void compactCompileErrorIsSingleLine() {
2531
CompileError error = new CompileError((WPos) null, "first line\nsecond line");

0 commit comments

Comments
 (0)