From b7b2ce1f7af6c67637ada48c49962a607b2cc4a2 Mon Sep 17 00:00:00 2001 From: Frotty Date: Thu, 11 Jun 2026 12:48:26 +0200 Subject: [PATCH] add runarg to control prod flag --- .../languageserver/requests/MapRequest.java | 6 +++++- .../java/de/peeeq/wurstscript/RunArgs.java | 6 ++++++ .../tests/MapRequestPatchTargetTests.java | 19 ++++++++++++++++++- .../tests/wurstscript/utils/UtilsTest.java | 6 ++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java index a291ed517..1153ea15d 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java @@ -766,7 +766,7 @@ protected File executeBuildMapPipeline(ModelManager modelManager, WurstGui gui, File targetMapFile = getBuildOutputMapFile(projectConfig, buildDir); targetMapFile = ensureWritableBuildOutput(targetMapFile, false); - CompilationResult result = compileScript(modelManager, gui, Optional.of(targetMapFile), projectConfig, buildDir, true); + CompilationResult result = compileScript(modelManager, gui, Optional.of(targetMapFile), projectConfig, buildDir, isProductionBuild()); injectMapData(gui, Optional.of(targetMapFile), result); targetMapFile = ensureWritableBuildOutput(targetMapFile, true); @@ -787,6 +787,10 @@ protected File executeBuildMapPipeline(ModelManager modelManager, WurstGui gui, return targetMapFile; } + protected boolean isProductionBuild() { + return !runArgs.isDevBuild(); + } + protected File ensureWritableBuildOutput(File targetMapFile, boolean isFinalWrite) { String lockMessage = isFinalWrite ? "The output map file is still in use and cannot be replaced.\nClick Retry, choose Rename to use a temporary file name, or Cancel." diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java index 221ba2ec5..a6fb6b95c 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/RunArgs.java @@ -54,6 +54,7 @@ public class RunArgs { private final RunOption optionHotStartmap; private final RunOption optionHotReload; private final RunOption optionTestTimeout; + private final RunOption optionDevBuild; private int functionSplitLimit = 10000; /** @@ -144,6 +145,7 @@ public RunArgs(String... args) { optionHotReload = addOption("hotreload", "Reloads the mapscript after running the map with Jass Hot Code Reload (JHCR)."); optionBuild = addOption("build", "Builds an output map from the input map and library directories."); + optionDevBuild = addOption("dev", "Builds an output map in development/run mode, so compiletime isProductionBuild() is false."); addOptionWithArg("workspaceroot", "The next argument should be the root folder of the project to build.", arg -> workspaceroot = arg); addOptionWithArg("inputmap", "The next argument should be the input map.", arg -> inputmap = arg); optionLua = addOption("lua", "Choose Lua as the compilation target."); @@ -398,6 +400,10 @@ public boolean isBuild() { return optionBuild.isSet; } + public boolean isDevBuild() { + return optionDevBuild.isSet; + } + public String getWorkspaceroot() { return workspaceroot; } diff --git a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java index f99357437..83b88a134 100644 --- a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java +++ b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java @@ -252,6 +252,15 @@ public void pre124PatchPropagatesLegacyJassChecksToCompileArgs() throws Exceptio "modern build must not carry the legacy flag: " + modern.exposedCompileArgs()); } + @Test + public void devBuildFlagMakesBuildPipelineNonProduction() throws Exception { + TestMapRequest dev = new TestMapRequest(projectWithPatch("v2.0"), Optional.empty(), Optional.empty(), List.of("-dev")); + assertFalse(dev.exposedIsProductionBuild(), "CLI build with -dev should expose isProductionBuild() = false to compiletime"); + + TestMapRequest release = new TestMapRequest(projectWithPatch("v2.0"), Optional.empty(), Optional.empty()); + assertTrue(release.exposedIsProductionBuild(), "CLI build without -dev should remain production by default"); + } + private static Path projectWithPatch(String patch) throws Exception { Path project = Files.createTempDirectory("wurst-map-request-patch"); Files.createDirectories(project.resolve("wurst")); @@ -264,7 +273,11 @@ private static Path projectWithPatch(String patch) throws Exception { private static final class TestMapRequest extends MapRequest { TestMapRequest(Path projectRoot, Optional wc3Path, Optional gameExePath) { - super(null, Optional.empty(), List.of(), WFile.create(projectRoot), wc3Path, gameExePath); + this(projectRoot, wc3Path, gameExePath, List.of()); + } + + TestMapRequest(Path projectRoot, Optional wc3Path, Optional gameExePath, List compileArgs) { + super(null, Optional.empty(), compileArgs, WFile.create(projectRoot), wc3Path, gameExePath); } Optional detectedVersion() { @@ -279,6 +292,10 @@ List exposedCompileArgs() { return compileArgs; } + boolean exposedIsProductionBuild() { + return isProductionBuild(); + } + @Override public Object execute(ModelManager modelManager) { return null; diff --git a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/utils/UtilsTest.java b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/utils/UtilsTest.java index b50f9ea73..8f1b95f70 100644 --- a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/utils/UtilsTest.java +++ b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/utils/UtilsTest.java @@ -20,6 +20,12 @@ public void compactOutputFlag() { Assert.assertTrue(new RunArgs("-compactOutput").isCompactOutput()); } + @Test + public void devBuildFlag() { + Assert.assertTrue(new RunArgs("-dev").isDevBuild()); + Assert.assertFalse(new RunArgs().isDevBuild()); + } + @Test public void compactCompileErrorIsSingleLine() { CompileError error = new CompileError((WPos) null, "first line\nsecond line");