Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion runtime-testsuite/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.config.fixed.parallelism=4
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public static String getRuntimePath(String language) {
return runtimePath.toString() + FileSeparator + language;
}

// Allows any target to add additional options for the antlr tool such as the location of the output files
// which is useful for the Go target for instance to avoid having to move them before running the test
//
protected List<String> getTargetToolOptions() {
return null;
}

public State run(RunOptions runOptions) {
List<String> options = new ArrayList<>();
if (runOptions.useVisitor) {
Expand All @@ -162,6 +169,14 @@ public State run(RunOptions runOptions) {
if (runOptions.superClass != null && runOptions.superClass.length() > 0) {
options.add("-DsuperClass=" + runOptions.superClass);
}

// See if the target wants to add tool options
//
List<String>targetOpts = getTargetToolOptions();
if (targetOpts != null) {
options.addAll(targetOpts);
}

ErrorQueue errorQueue = Generator.antlrOnString(getTempDirPath(), getLanguage(),
runOptions.grammarFileName, runOptions.grammarStr, false, options.toArray(new String[0]));

Expand Down
72 changes: 50 additions & 22 deletions runtime-testsuite/test/org/antlr/v4/test/runtime/go/GoRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public String[] getExtraRunArgs() {
private final static Map<String, String> environment;

private static String cachedGoMod;
private static String cachedGoSum;

static {
environment = new HashMap<>();
Expand All @@ -88,6 +89,8 @@ protected void initRuntime(RunOptions runOptions) throws Exception {
Processor.run(new String[]{runtimeToolPath, "mod", "init", "test"}, cachePath, environment);
Processor.run(new String[]{runtimeToolPath, "mod", "edit",
"-replace=" + GoRuntimeImportPath + "=" + runtimeFilesPath}, cachePath, environment);
Processor.run(new String[]{runtimeToolPath, "mod", "edit",
"-require=" + GoRuntimeImportPath + "@v4.0.0"}, cachePath, environment);
cachedGoMod = readFile(cachePath + FileSeparator, "go.mod");
}

Expand All @@ -111,36 +114,61 @@ protected String grammarParseRuleToRecognizerName(String startRuleName) {
return rn;
}

@Override
protected List<String> getTargetToolOptions() {
ArrayList<String> options = new ArrayList<String>();
options.add("-o");
options.add(tempTestDir.resolve("parser").toString());
return options;
}

@Override
protected CompiledState compile(RunOptions runOptions, GeneratedState generatedState) {
List<GeneratedFile> generatedFiles = generatedState.generatedFiles;
String tempDirPath = getTempDirPath();
File generatedParserDir = new File(tempDirPath, "parser");
if (!generatedParserDir.mkdir()) {
return new CompiledState(generatedState, new Exception("can't make dir " + generatedParserDir));
}
// List<GeneratedFile> generatedFiles = generatedState.generatedFiles;
// String tempDirPath = getTempDirPath();
// File generatedParserDir = new File(tempDirPath, "parser");
// if (!generatedParserDir.mkdir()) {
// return new CompiledState(generatedState, new Exception("can't make dir " + generatedParserDir));
// }
//
// // The generated files seem to need to be in the parser subdirectory.
// // We have no need to change the import of the runtime because of go mod replace so, we could just generate them
// // directly in to the parser subdir. But in case down the line, there is some reason to want to replace things in
// // the generated code, then I will leave this here, and we can use replaceInFile()
// //
// for (GeneratedFile generatedFile : generatedFiles) {
// try {
// Path originalFile = Paths.get(tempDirPath, generatedFile.name);
// Files.move(originalFile, Paths.get(tempDirPath, "parser", generatedFile.name));
// } catch (IOException e) {
// return new CompiledState(generatedState, e);
// }
// }

// We have already created a suitable go.mod file, though it may need to have go mod tidy run on it one time
//
writeFile(getTempDirPath(), "go.mod", cachedGoMod);

// The generated files seem to need to be in the parser subdirectory.
// We have no need to change the import of the runtime because of go mod replace so, we could just generate them
// directly in to the parser subdir. But in case down the line, there is some reason to want to replace things in
// the generated code, then I will leave this here, and we can use replaceInFile()
// We need to run a go mod tidy once, now that we have source code. This will generate a valid go.sum file and
// recognize the indirect requirements in the go.mod file. Then we re-cache the go.mod and cache
// the go.sum and therefore save sparking a new process for all the remaining go tests. This is probably
// a race condition as these tests are run in parallel, but it does not matter as they are all going to
// generate the same go.mod and go.sum file anyway.
//
for (GeneratedFile generatedFile : generatedFiles) {
Exception ex = null;
if (cachedGoSum == null) {
try {
Path originalFile = Paths.get(tempDirPath, generatedFile.name);
Files.move(originalFile, Paths.get(tempDirPath, "parser", generatedFile.name));
} catch (IOException e) {
return new CompiledState(generatedState, e);
Processor.run(new String[]{getRuntimeToolPath(), "mod", "tidy"}, getTempDirPath(), environment);
} catch (InterruptedException | IOException e) {
ex = e;
}
cachedGoMod = readFile(getTempDirPath() + FileSeparator, "go.mod");
cachedGoSum = readFile(getTempDirPath() + FileSeparator, "go.sum");
}

writeFile(tempDirPath, "go.mod", cachedGoMod);
Exception ex = null;
try {
Processor.run(new String[]{getRuntimeToolPath(), "mod", "tidy"}, tempDirPath, environment);
} catch (InterruptedException | IOException e) {
ex = e;
}
// We can now write the go.sum file, which will allow the go compiler to build the module
//
writeFile(getTempDirPath(), "go.sum", cachedGoSum);

return new CompiledState(generatedState, ex);
}
Expand Down