Skip to content

Commit ed9e384

Browse files
authored
Lua hot reload: a -build -luaHotReload takes the run arguments, not the build-only ones (#1559)
The command line added the build-only '+' lines of wurst_run.args to every -build. A new project's file has +opt, +inline and +localOptimizations, which -luaHotReload refuses, so the documented command-line hot reload failed on a default project ("-luaHotReload is for development builds: remove -inline and -opt."). A hot reload build is a development build of the map a hot run starts, and takes the run arguments.
1 parent 9854dee commit ed9e384

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static void main(String[] args) {
132132
List<String> mergedArgs = new ArrayList<>(asList(args));
133133
if (workspaceroot != null) {
134134
WLogger.info("workspaceroot: " + workspaceroot);
135-
List<String> argsList = getCompileArgs(WFile.create(workspaceroot), runArgs.isBuild());
135+
List<String> argsList = workspaceCompileArgs(workspaceroot, runArgs);
136136
WLogger.info("workspaceroot: " + (argsList == null));
137137
mergedArgs.addAll(argsList);
138138
compileArgs = new RunArgs(mergedArgs);
@@ -219,6 +219,15 @@ public static void main(String[] args) {
219219
}
220220
}
221221

222+
/**
223+
* The arguments of the workspace's wurst_run.args which this command line adds to its own. A hot reload build is
224+
* a development build of the map a hot run starts, so it takes the run arguments: the build-only lines turn on
225+
* the optimisations which -luaHotReload refuses, and a new project's file has them.
226+
*/
227+
static List<String> workspaceCompileArgs(String workspaceroot, RunArgs runArgs) {
228+
return getCompileArgs(WFile.create(workspaceroot), runArgs.isBuild() && !runArgs.isLuaHotReload());
229+
}
230+
222231
private static void printCompactMessages(WurstGui gui) {
223232
if (gui.getErrorCount() > 0) {
224233
System.out.println("Errors: " + gui.getErrorCount());

‎de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package de.peeeq.wurstio;
22

33
import de.peeeq.wurstscript.CompileTimeInfo;
4+
import de.peeeq.wurstscript.RunArgs;
45
import org.testng.annotations.Test;
56

67
import java.io.ByteArrayOutputStream;
78
import java.io.PrintStream;
89
import java.nio.charset.StandardCharsets;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.util.List;
913

1014
import static org.testng.Assert.assertEquals;
15+
import static org.testng.Assert.assertFalse;
1116
import static org.testng.Assert.assertTrue;
1217

1318
public class MainTests {
@@ -24,6 +29,23 @@ public void versionPrintsCompilerVersion() {
2429
assertEquals(output.trim(), CompileTimeInfo.version);
2530
}
2631

32+
@Test
33+
public void hotReloadBuildTakesTheRunArgumentsNotTheBuildOnlyOnes() throws Exception {
34+
Path project = Files.createTempDirectory("wurst-hot-reload-build-args");
35+
Files.writeString(project.resolve("wurst.build"), "projectName: HotReloadArgs\n");
36+
// What the compiler writes into a new project's wurst_run.args.
37+
Files.writeString(project.resolve("wurst_run.args"), "-stacktraces\n+opt\n+inline\n+localOptimizations\n");
38+
39+
List<String> hotReload = Main.workspaceCompileArgs(project.toString(), new RunArgs("-build", "-luaHotReload"));
40+
assertTrue(hotReload.contains("-stacktraces"));
41+
assertFalse(hotReload.contains("-opt"), "-luaHotReload refuses -opt, so a hot reload build cannot take it");
42+
assertFalse(hotReload.contains("-inline"));
43+
assertFalse(hotReload.contains("-localOptimizations"));
44+
45+
List<String> release = Main.workspaceCompileArgs(project.toString(), new RunArgs("-build"));
46+
assertTrue(release.containsAll(List.of("-stacktraces", "-opt", "-inline", "-localOptimizations")));
47+
}
48+
2749
private String captureStdout(Runnable action) {
2850
PrintStream previousOut = System.out;
2951
ByteArrayOutputStream output = new ByteArrayOutputStream();

‎docs/LUA_HOT_RELOAD.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ Editor side (implemented, `LuaHotReloadSession`, `RunMap`):
241241
with the reasons as its error message; the VS Code extension shows the first line and writes the rest to its
242242
output. While a hot run is active, the VS Code extension sends it on every save of a Wurst file.
243243

244-
Without the editor, a map built with `-build ... -luaHotReload` (with run arguments: `-luaHotReload` refuses `-inline`
245-
and `-opt`) starts a session and takes payloads from the compiler's command line, which is how the in-game test drives
244+
Without the editor, a map built with `-build ... -luaHotReload` (which takes the run arguments of `wurst_run.args`, not
245+
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
246246
it:
247247

248248
```

0 commit comments

Comments
 (0)