|
8 | 8 | import com.adacore.lkql_jit.options.LKQLOptions; |
9 | 9 | import com.adacore.lkql_jit.options.RuleInstance; |
10 | 10 | import java.io.File; |
| 11 | +import java.io.FileNotFoundException; |
| 12 | +import java.io.FileOutputStream; |
11 | 13 | import java.io.IOException; |
| 14 | +import java.io.OutputStream; |
| 15 | +import java.nio.file.FileSystems; |
12 | 16 | import java.nio.file.Files; |
13 | 17 | import java.nio.file.Paths; |
14 | 18 | import java.util.*; |
@@ -94,6 +98,11 @@ public static class Args implements Callable<Integer> { |
94 | 98 | @CommandLine.Option(names = "--files-from", description = "The file containing the files") |
95 | 99 | public String filesFrom = null; |
96 | 100 |
|
| 101 | + @CommandLine.Option( |
| 102 | + names = "--log-file", |
| 103 | + description = "The file used by the worker to output logs") |
| 104 | + public String gnatcheckLogFile = null; |
| 105 | + |
97 | 106 | @CommandLine.Option( |
98 | 107 | names = "--ignore-project-switches", |
99 | 108 | description = |
@@ -244,6 +253,18 @@ protected int executeScript(Context.Builder contextBuilder) { |
244 | 253 | // Finally, pass the options to the LKQL engine |
245 | 254 | contextBuilder.option("lkql.options", optionsBuilder.build().toJson().toString()); |
246 | 255 |
|
| 256 | + try { |
| 257 | + // Install a log handler only if gnatcheckLogFile is set |
| 258 | + if (this.args.gnatcheckLogFile != null) { |
| 259 | + var logFile = FileSystems.getDefault().getPath(this.args.gnatcheckLogFile); |
| 260 | + OutputStream outputStream = new FileOutputStream(logFile.toFile()); |
| 261 | + contextBuilder.logHandler(outputStream); |
| 262 | + } |
| 263 | + } catch (FileNotFoundException e) { |
| 264 | + System.err.println( |
| 265 | + "WORKER_ERROR: Could not create log file: " + this.args.gnatcheckLogFile); |
| 266 | + } |
| 267 | + |
247 | 268 | // Create the context and run the script in it |
248 | 269 | try (Context context = contextBuilder.build()) { |
249 | 270 | final Source source = Source.newBuilder("lkql", checkerSource, "checker.lkql").build(); |
|
0 commit comments