-
Notifications
You must be signed in to change notification settings - Fork 29
Respect Lua mode in CLI compilation #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| package de.peeeq.wurstio; | ||
|
|
||
| import com.google.common.base.Charsets; | ||
| import com.google.common.io.Files; | ||
| import org.wurstscript.projectconfig.WurstProjectConfigData; | ||
| import org.wurstscript.projectconfig.WurstProjectConfigReader; | ||
| import de.peeeq.wurstio.compilationserver.WurstServer; | ||
|
|
@@ -11,8 +9,6 @@ | |
| import de.peeeq.wurstio.languageserver.WFile; | ||
| import de.peeeq.wurstio.languageserver.requests.CliBuildMap; | ||
| import de.peeeq.wurstio.map.importer.ImportFile; | ||
| import de.peeeq.wurstio.mpq.MpqEditor; | ||
| import de.peeeq.wurstio.mpq.MpqEditorFactory; | ||
| import de.peeeq.wurstio.objectreader.ObjectExportService; | ||
| import de.peeeq.wurstscript.CompileTimeInfo; | ||
| import de.peeeq.wurstscript.ErrorReporting; | ||
|
|
@@ -147,11 +143,19 @@ public static void main(String[] args) { | |
| compileArgs = new RunArgs(mergedArgs); | ||
| } | ||
|
|
||
| if (runArgs.isBuild() && runArgs.getInputmap() != null && workspaceroot != null) { | ||
| if (workspaceroot != null) { | ||
| Path root = Paths.get(workspaceroot); | ||
| Path inputMap = root.resolve(runArgs.getInputmap()); | ||
| Path inputMap = runArgs.isBuild() && runArgs.getInputmap() != null | ||
| ? root.resolve(runArgs.getInputmap()) | ||
| : runArgs.getMapFile() == null ? null : Paths.get(runArgs.getMapFile()); | ||
| WurstProjectConfigData projectConfig = WurstProjectConfigReader.load(root.resolve(FILE_NAME)); | ||
| if (java.nio.file.Files.exists(inputMap) && projectConfig != null) { | ||
| if (inputMap != null) { | ||
| if (!java.nio.file.Files.exists(inputMap)) { | ||
| throw new RuntimeException("Input map does not exist: " + inputMap); | ||
| } | ||
| if (projectConfig == null) { | ||
| throw new RuntimeException(FILE_NAME + " file doesn't exist or is invalid."); | ||
| } | ||
| CliBuildMap cliBuildMap = new CliBuildMap( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the CLI is invoked with AGENTS.md reference: AGENTS.md:L162-L164 Useful? React with 👍 / 👎. |
||
| WFile.create(root.toFile()), | ||
| Optional.of(inputMap.toFile()), | ||
|
|
@@ -170,30 +174,14 @@ public static void main(String[] args) { | |
| } | ||
| } | ||
|
|
||
| String mapFilePath = runArgs.getMapFile(); | ||
|
|
||
| CompilationProcess compilationProcess = new CompilationProcess(gui, compileArgs); | ||
| @Nullable CharSequence compiledScript; | ||
|
|
||
| if (mapFilePath != null && workspaceroot != null) { | ||
| try (MpqEditor mpqEditor = MpqEditorFactory.getEditor(Optional.of(new File(mapFilePath)))) { | ||
| File projectFolder = Paths.get(workspaceroot).toFile(); | ||
| compiledScript = compilationProcess.doCompilation(mpqEditor, projectFolder, true); | ||
| if (compiledScript != null) { | ||
| gui.sendProgress("Writing to map"); | ||
| mpqEditor.deleteFile("war3map.j"); | ||
| byte[] war3map = compiledScript.toString().getBytes(Charsets.UTF_8); | ||
| mpqEditor.insertFile("war3map.j", war3map); | ||
| } | ||
| ImportFile.importFilesFromImports(projectFolder, mpqEditor); | ||
| } | ||
| } else { | ||
| compiledScript = compilationProcess.doCompilation(null, true); | ||
| } | ||
| compiledScript = compilationProcess.doCompilation(null, true); | ||
|
|
||
| if (compiledScript != null) { | ||
| File scriptFile = new File("compiled.j.txt"); | ||
| Files.write(compiledScript.toString().getBytes(Charsets.UTF_8), scriptFile); | ||
| File scriptFile = new File(compileArgs.isLua() ? "compiled.lua.txt" : "compiled.j.txt"); | ||
| java.nio.file.Files.writeString(scriptFile.toPath(), compiledScript); | ||
| } | ||
|
|
||
| gui.sendProgress("Finished!"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package de.peeeq.wurstio; | ||
|
|
||
| import de.peeeq.wurstscript.RunArgs; | ||
| import de.peeeq.wurstscript.gui.WurstGuiCliImpl; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| public class CompilationProcessLuaTests { | ||
|
|
||
| @Test | ||
| public void luaModeDoesNotEmitJassScript() throws Exception { | ||
| Path project = Files.createTempDirectory("wurst-cli-lua"); | ||
| Path source = project.resolve("Main.wurst"); | ||
| Path requestedJassOutput = project.resolve("output.j"); | ||
| Path output = project.resolve("output.lua"); | ||
| Files.writeString(source, "package Main\nfunction foo()\nendpackage\n"); | ||
| Files.writeString(requestedJassOutput, "stale jass output"); | ||
|
|
||
| RunArgs runArgs = new RunArgs("-lua", "-out", requestedJassOutput.toString(), source.toString()); | ||
| CompilationProcess process = new CompilationProcess(new WurstGuiCliImpl(true), runArgs); | ||
|
|
||
| CharSequence result = process.doCompilation(null, project.toFile(), false); | ||
|
|
||
| assertTrue(result != null, "Lua compilation should succeed"); | ||
| assertTrue(Files.exists(output), "Lua output should be written"); | ||
| assertFalse(Files.exists(requestedJassOutput), "Lua compilation must not emit a .j file"); | ||
| assertFalse(result.toString().contains("takes nothing returns nothing"), | ||
| "CLI Lua compilation must not use the Jass backend"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user previously compiled Jass to
-out output.jand then reruns the same command with-lua, this branch writesoutput.luabut leaves the oldoutput.juntouched. Downstream tools that still inspect the explicitly requested path can therefore consume obsolete Jass, and the new guarantee that Lua mode does not leave a.jartifact only holds in a clean directory. Delete the superseded file or write the Lua output to the exact requested path.Useful? React with 👍 / 👎.