diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java index bb0206e09..6159e462f 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java @@ -132,7 +132,7 @@ public static void main(String[] args) { List mergedArgs = new ArrayList<>(asList(args)); if (workspaceroot != null) { WLogger.info("workspaceroot: " + workspaceroot); - List argsList = getCompileArgs(WFile.create(workspaceroot), runArgs.isBuild()); + List argsList = workspaceCompileArgs(workspaceroot, runArgs); WLogger.info("workspaceroot: " + (argsList == null)); mergedArgs.addAll(argsList); compileArgs = new RunArgs(mergedArgs); @@ -219,6 +219,15 @@ public static void main(String[] args) { } } + /** + * The arguments of the workspace's wurst_run.args which this command line adds to its own. A hot reload build is + * a development build of the map a hot run starts, so it takes the run arguments: the build-only lines turn on + * the optimisations which -luaHotReload refuses, and a new project's file has them. + */ + static List workspaceCompileArgs(String workspaceroot, RunArgs runArgs) { + return getCompileArgs(WFile.create(workspaceroot), runArgs.isBuild() && !runArgs.isLuaHotReload()); + } + private static void printCompactMessages(WurstGui gui) { if (gui.getErrorCount() > 0) { System.out.println("Errors: " + gui.getErrorCount()); diff --git a/de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java b/de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java index 148fea42a..8641e012c 100644 --- a/de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java +++ b/de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java @@ -1,13 +1,18 @@ package de.peeeq.wurstio; import de.peeeq.wurstscript.CompileTimeInfo; +import de.peeeq.wurstscript.RunArgs; import org.testng.annotations.Test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; public class MainTests { @@ -24,6 +29,23 @@ public void versionPrintsCompilerVersion() { assertEquals(output.trim(), CompileTimeInfo.version); } + @Test + public void hotReloadBuildTakesTheRunArgumentsNotTheBuildOnlyOnes() throws Exception { + Path project = Files.createTempDirectory("wurst-hot-reload-build-args"); + Files.writeString(project.resolve("wurst.build"), "projectName: HotReloadArgs\n"); + // What the compiler writes into a new project's wurst_run.args. + Files.writeString(project.resolve("wurst_run.args"), "-stacktraces\n+opt\n+inline\n+localOptimizations\n"); + + List hotReload = Main.workspaceCompileArgs(project.toString(), new RunArgs("-build", "-luaHotReload")); + assertTrue(hotReload.contains("-stacktraces")); + assertFalse(hotReload.contains("-opt"), "-luaHotReload refuses -opt, so a hot reload build cannot take it"); + assertFalse(hotReload.contains("-inline")); + assertFalse(hotReload.contains("-localOptimizations")); + + List release = Main.workspaceCompileArgs(project.toString(), new RunArgs("-build")); + assertTrue(release.containsAll(List.of("-stacktraces", "-opt", "-inline", "-localOptimizations"))); + } + private String captureStdout(Runnable action) { PrintStream previousOut = System.out; ByteArrayOutputStream output = new ByteArrayOutputStream(); diff --git a/docs/LUA_HOT_RELOAD.md b/docs/LUA_HOT_RELOAD.md index b317254a1..6a5a012da 100644 --- a/docs/LUA_HOT_RELOAD.md +++ b/docs/LUA_HOT_RELOAD.md @@ -241,8 +241,8 @@ Editor side (implemented, `LuaHotReloadSession`, `RunMap`): with the reasons as its error message; the VS Code extension shows the first line and writes the rest to its output. While a hot run is active, the VS Code extension sends it on every save of a Wurst file. -Without the editor, a map built with `-build ... -luaHotReload` (with run arguments: `-luaHotReload` refuses `-inline` -and `-opt`) starts a session and takes payloads from the compiler's command line, which is how the in-game test drives +Without the editor, a map built with `-build ... -luaHotReload` (which takes the run arguments of `wurst_run.args`, not +its build-only `+` lines: `-luaHotReload` refuses `-inline` and `-opt`) starts a session and takes payloads from the compiler's command line, which is how the in-game test drives it: ```