|
13 | 13 | import java.nio.file.Files; |
14 | 14 | import java.nio.file.Path; |
15 | 15 | import java.nio.file.Paths; |
| 16 | +import java.util.ArrayList; |
16 | 17 | import java.util.List; |
17 | 18 | import java.util.Optional; |
18 | 19 | import java.util.concurrent.CompletableFuture; |
@@ -90,7 +91,7 @@ private static CompletableFuture<Object> buildMap(WurstLanguageServer server, Ex |
90 | 91 | } |
91 | 92 |
|
92 | 93 | Optional<File> map = mapPath.map(File::new); |
93 | | - List<String> compileArgs = getCompileArgs(workspaceRoot); |
| 94 | + List<String> compileArgs = getCompileArgs(workspaceRoot, true); |
94 | 95 | return server.worker().handle(new BuildMap(server, workspaceRoot, wc3Path, map, compileArgs)).thenApply(x -> x); |
95 | 96 | } |
96 | 97 |
|
@@ -121,27 +122,54 @@ private static Optional<String> getString(JsonObject options, String key) { |
121 | 122 | private static final List<String> defaultArgs = ImmutableList.of("-runcompiletimefunctions", "-injectobjects", "-stacktraces"); |
122 | 123 |
|
123 | 124 | public static List<String> getCompileArgs(WFile rootPath, String... additionalArgs) { |
| 125 | + return getCompileArgs(rootPath, false, additionalArgs); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Reads the workspace run-args file. A leading '-' is shared by run and build; |
| 130 | + * a leading '+' is build-only and is normalized to '-' for the compiler. |
| 131 | + */ |
| 132 | + public static List<String> getCompileArgs(WFile rootPath, boolean forBuild, String... additionalArgs) { |
124 | 133 | try { |
125 | 134 | Path configFile = Paths.get(rootPath.toString(), "wurst_run.args"); |
126 | 135 | if (Files.exists(configFile)) { |
127 | 136 | try (Stream<String> lines = Files.lines(configFile)) { |
128 | | - List<String> args = Stream.concat( |
129 | | - lines.filter(s -> s.startsWith("-")), |
130 | | - Stream.of(additionalArgs) |
131 | | - ).collect(Collectors.toList()); |
| 137 | + List<String> args = new ArrayList<>(lines |
| 138 | + .map(String::trim) |
| 139 | + .filter(s -> !s.isEmpty() && !s.startsWith("#")) |
| 140 | + .filter(s -> s.startsWith("-") || (forBuild && s.startsWith("+"))) |
| 141 | + .map(s -> forBuild && s.startsWith("+") ? "-" + s.substring(1) : s) |
| 142 | + .collect(Collectors.toList())); |
| 143 | + if (forBuild) { |
| 144 | + addBuildDefault(args, "-opt"); |
| 145 | + addBuildDefault(args, "-inline"); |
| 146 | + addBuildDefault(args, "-localOptimizations"); |
| 147 | + } |
| 148 | + args.addAll(List.of(additionalArgs)); |
132 | 149 | return WurstBuildConfig.fromWorkspaceRoot(rootPath).applyToCompileArgs(args); |
133 | 150 | } |
134 | 151 | } else { |
135 | | - |
136 | | - String cfg = String.join("\n", defaultArgs) + "\n"; |
| 152 | + String cfg = String.join("\n", defaultArgs) |
| 153 | + + "\n+opt\n+inline\n+localOptimizations\n"; |
137 | 154 | Files.write(configFile, cfg.getBytes(Charsets.UTF_8)); |
138 | | - return WurstBuildConfig.fromWorkspaceRoot(rootPath).applyToCompileArgs( |
139 | | - Stream.concat(defaultArgs.stream(), Stream.of(additionalArgs)).collect(Collectors.toList()) |
140 | | - ); |
| 155 | + List<String> args = new ArrayList<>(defaultArgs); |
| 156 | + if (forBuild) { |
| 157 | + args.add("-opt"); |
| 158 | + args.add("-inline"); |
| 159 | + args.add("-localOptimizations"); |
| 160 | + } |
| 161 | + args.addAll(List.of(additionalArgs)); |
| 162 | + return WurstBuildConfig.fromWorkspaceRoot(rootPath).applyToCompileArgs(args); |
141 | 163 | } |
142 | 164 | } catch (IOException e) { |
143 | 165 | throw new RuntimeException("Could not access wurst_run.args config file", e); |
144 | 166 | } |
145 | 167 | } |
146 | 168 |
|
| 169 | + private static void addBuildDefault(List<String> args, String option) { |
| 170 | + if (!args.contains(option)) { |
| 171 | + args.add(option); |
| 172 | + } |
| 173 | + } |
| 174 | + |
147 | 175 | } |
0 commit comments