From a243a0b3145969b3cc9c60ed77487a599226a1fc Mon Sep 17 00:00:00 2001 From: Frotty Date: Tue, 22 Oct 2019 22:20:45 +0200 Subject: [PATCH] fixes --- .../de/peeeq/wurstio/CompilationProcess.java | 6 +++++- .../src/main/java/de/peeeq/wurstio/Main.java | 20 +++++++++++++------ .../peeeq/wurstio/WurstCompilerJassImpl.java | 5 ++--- .../java/de/peeeq/wurstscript/RunArgs.java | 8 +++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompilationProcess.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompilationProcess.java index eed18547e..27139e860 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompilationProcess.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompilationProcess.java @@ -38,7 +38,11 @@ public CompilationProcess(WurstGui gui, RunArgs runArgs) { } @Nullable CharSequence doCompilation(@Nullable MpqEditor mpqEditor) throws IOException { - WurstCompilerJassImpl compiler = new WurstCompilerJassImpl(timeTaker, null, gui, mpqEditor, runArgs); + return doCompilation(mpqEditor, null); + } + + @Nullable CharSequence doCompilation(@Nullable MpqEditor mpqEditor, @Nullable File projectFolder) throws IOException { + WurstCompilerJassImpl compiler = new WurstCompilerJassImpl(timeTaker, projectFolder, gui, mpqEditor, runArgs); gui.sendProgress("Check input map"); if (mpqEditor != null && !mpqEditor.canWrite()) { WLogger.severe("The supplied map is invalid/corrupted/protected and Wurst cannot write to it.\n" + 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 8e27c15aa..f48cf0007 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 @@ -28,10 +28,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.LinkedList; import java.util.List; import static de.peeeq.wurstio.languageserver.ProjectConfigBuilder.FILE_NAME; import static de.peeeq.wurstio.languageserver.WurstCommands.getCompileArgs; +import static java.util.Arrays.asList; public class Main { @@ -107,8 +109,9 @@ public static void main(String[] args) { WurstProjectConfigData projectConfig = null; Path buildDir = null; Path target = null; - if (runArgs.isBuild() && runArgs.getInputmap() != null && runArgs.getWorkspaceroot() != null) { - Path root = Paths.get(runArgs.getWorkspaceroot()); + String workspaceroot = runArgs.getWorkspaceroot(); + if (runArgs.isBuild() && runArgs.getInputmap() != null && workspaceroot != null) { + Path root = Paths.get(workspaceroot); Path inputMap = root.resolve(runArgs.getInputmap()); projectConfig = WurstProjectConfig.INSTANCE.loadProject(root.resolve(FILE_NAME)); @@ -131,15 +134,20 @@ public static void main(String[] args) { } RunArgs compileArgs = runArgs; - if (runArgs.getWorkspaceroot() != null) { - compileArgs = new RunArgs(getCompileArgs(WFile.create(Paths.get(runArgs.getWorkspaceroot())))); + if (workspaceroot != null) { + WLogger.info("workspaceroot: " + workspaceroot); + List argList = new LinkedList<>(asList(args)); + List argsList = getCompileArgs(WFile.create(workspaceroot)); + WLogger.info("workspaceroot: " + (argsList == null)); + argList.addAll(argsList); + compileArgs = new RunArgs(argList); } CompilationProcess compilationProcess = new CompilationProcess(gui, compileArgs); @Nullable CharSequence compiledScript; - if (mapFilePath != null) { + if (mapFilePath != null && workspaceroot != null) { try (MpqEditor mpqEditor = MpqEditorFactory.getEditor(new File(mapFilePath))) { - compiledScript = compilationProcess.doCompilation(mpqEditor); + compiledScript = compilationProcess.doCompilation(mpqEditor, Paths.get(workspaceroot).toFile()); if (compiledScript != null) { gui.sendProgress("Writing to map"); mpqEditor.deleteFile("war3map.j"); diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java index fee951a37..2a45077cb 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java @@ -180,8 +180,8 @@ private void addDependencyFolder(File f, String folderName) { if (file.getName().endsWith(".w3x") || file.getName().endsWith(".w3m")) { mapFile = file; } else if (file.isDirectory()) { - if (projectFolder != null) { - throw new RuntimeException("Cannot set projectFolder to " + file + " because it is already set to " + projectFolder); + if (projectFolder != null && !file.getParent().equals(projectFolder.getAbsolutePath())) { + throw new RuntimeException("Cannot set projectFolder to " + file + " because it is already set to non parent " + projectFolder); } projectFolder = file; } @@ -497,7 +497,6 @@ public JassProg transformProgToJass() { if (runArgs.isHotStartmap() || runArgs.isHotReload()) { addJassHotCodeReloadCode(); } - if (runArgs.isOptimize()) { beginPhase(12, "froptimize"); optimizer.optimize(); 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 7ab58ebd6..41997e17d 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 @@ -20,7 +20,9 @@ public class RunArgs { private @Nullable String outFile = null; private @Nullable String workspaceroot = null; private @Nullable String inputmap = null; + private List options = Lists.newArrayList(); + private List libDirs = Lists.newArrayList(); private RunOption optionHelp; private RunOption optionOpt; @@ -47,7 +49,6 @@ public class RunArgs { private RunOption optionMeasureTimes; private RunOption optionHotStartmap; private RunOption optionHotReload; - private RunOption optionBuild; public RunArgs with(String... additionalArgs) { @@ -58,6 +59,7 @@ public RunArgs with(String... additionalArgs) { private class RunOption { final String name; + final String descr; final @Nullable Consumer argHandler; boolean isSet; @@ -66,15 +68,14 @@ private class RunOption { this.descr = descr; this.argHandler = null; } - RunOption(String name, String descr, Consumer argHandler2) { this.name = name; this.descr = descr; this.argHandler = argHandler2; } - } + } public static RunArgs defaults() { return new RunArgs(); } @@ -344,4 +345,5 @@ public boolean isLua() { return optionLua.isSet; } + }