Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static void main(String[] args) {
List<String> mergedArgs = new ArrayList<>(asList(args));
if (workspaceroot != null) {
WLogger.info("workspaceroot: " + workspaceroot);
List<String> argsList = getCompileArgs(WFile.create(workspaceroot), runArgs.isBuild());
List<String> argsList = workspaceCompileArgs(workspaceroot, runArgs);
WLogger.info("workspaceroot: " + (argsList == null));
mergedArgs.addAll(argsList);
compileArgs = new RunArgs(mergedArgs);
Expand Down Expand Up @@ -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<String> 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());
Expand Down
22 changes: 22 additions & 0 deletions de.peeeq.wurstscript/src/test/java/de/peeeq/wurstio/MainTests.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<String> 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<String> 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();
Expand Down
4 changes: 2 additions & 2 deletions docs/LUA_HOT_RELOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
Loading