From 44993449855a480f70b455785a5ed5bde24caffd Mon Sep 17 00:00:00 2001 From: ericvergnaud Date: Fri, 19 Jun 2015 02:10:19 +0800 Subject: [PATCH] added -root parameter to generate all targets --- .gitignore | 2 + .../antlr/v4/testgen/TargetConfiguration.java | 36 +++++++++++++++++ .../org/antlr/v4/testgen/TestGenerator.java | 39 ++++++++++++++----- 3 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 runtime-testsuite/src/org/antlr/v4/testgen/TargetConfiguration.java diff --git a/.gitignore b/.gitignore index df2735b00..92136af15 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ tmp/ bilder.py bilder.pyc bild.log + +bild_output.txt diff --git a/runtime-testsuite/src/org/antlr/v4/testgen/TargetConfiguration.java b/runtime-testsuite/src/org/antlr/v4/testgen/TargetConfiguration.java new file mode 100644 index 000000000..e40b8c9e3 --- /dev/null +++ b/runtime-testsuite/src/org/antlr/v4/testgen/TargetConfiguration.java @@ -0,0 +1,36 @@ +package org.antlr.v4.testgen; + +import java.util.Arrays; +import java.util.List; + +public class TargetConfiguration { + + public static List ALL = Arrays.asList( new TargetConfiguration[] { + new TargetConfiguration("tool/test/", + "tool/test/org/antlr/v4/test/runtime/java/Java.test.stg"), + new TargetConfiguration("../antlr4-csharp/tool/test/", + "../antlr4-csharp/tool/test/org/antlr/v4/test/runtime/csharp/CSharp.test.stg"), + new TargetConfiguration("../antlr4-python2/tool/test/", + "../antlr4-python2/tool/test/org/antlr/v4/test/runtime/python2/Python2.test.stg"), + new TargetConfiguration("../antlr4-python3/tool/test/", + "../antlr4-python3/tool/test/org/antlr/v4/test/runtime/python3/Python3.test.stg"), + new TargetConfiguration("../antlr4-javascript/tool/test/", + "../antlr4-javascript/tool/test/org/antlr/v4/test/runtime/javascript/node/Node.test.stg"), + new TargetConfiguration("../antlr4-javascript/tool/test/", + "../antlr4-javascript/tool/test/org/antlr/v4/test/runtime/javascript/chrome/Chrome.test.stg"), + new TargetConfiguration("../antlr4-javascript/tool/test/", + "../antlr4-javascript/tool/test/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg"), + new TargetConfiguration("../antlr4-javascript/tool/test/", + "../antlr4-javascript/tool/test/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg"), + new TargetConfiguration("../antlr4-javascript/tool/test/", + "../antlr4-javascript/tool/test/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg") + }); + + String outDir; + String templates; + + public TargetConfiguration(String outDir, String templates) { + this.outDir = outDir; + this.templates = templates; + } +} diff --git a/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java b/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java index 6586e87b2..5075b339a 100644 --- a/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java +++ b/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java @@ -66,6 +66,7 @@ public class TestGenerator { * $ java org.antlr.v4.testgen.TestGenerator -o /tmp -templates /Users/parrt/antlr/code/antlr4/tool/test/org/antlr/v4/test/runtime/java/Java.test.stg */ public static void main(String[] args) { + String rootDir = null; String outDir = null; String targetSpecificTemplateFile = null; boolean viz = false; @@ -73,7 +74,11 @@ public class TestGenerator { int i = 0; while (args != null && i < args.length) { String arg = args[i]; - if (arg.startsWith("-o")) { + if (arg.startsWith("-root")) { + i++; + rootDir = args[i]; + } + else if (arg.startsWith("-o")) { i++; outDir = args[i]; } @@ -86,7 +91,11 @@ public class TestGenerator { } i++; } - + if ( rootDir!=null) { + genAllTargets(rootDir, viz); + System.exit(0); + } + if ( outDir==null || targetSpecificTemplateFile==null ) { System.err.println("You must give an output root dir and templates file"); System.exit(1); @@ -94,7 +103,16 @@ public class TestGenerator { genTarget(outDir, targetSpecificTemplateFile, viz); } - + + public static void genAllTargets(final String rootDir, boolean viz) { + for(TargetConfiguration config : TargetConfiguration.ALL) { + String outDir = rootDir + config.outDir; + String templates = rootDir + config.templates; + genTarget(outDir, templates, viz); + } + + } + public static void genTarget(final String outDir, String targetSpecificTemplateFile, boolean viz) { TestGenerator gen = new TestGenerator("UTF-8", new File(targetSpecificTemplateFile), @@ -109,15 +127,16 @@ public class TestGenerator { public File getOutputDir(String templateFolder) { String targetName = getTargetNameFromTemplatesFileName(); // compute package - int packageStart = templateFolder.indexOf("org/antlr/v4/test/runtime"); - int templatesStart = templateFolder.indexOf("/templates"); - String packageDir = templateFolder.substring(packageStart,templatesStart); - File root = outputDirectory; - File f = new File(root, packageDir); - return new File(f, targetName.toLowerCase()); + String templatePath = runtimeTemplates.getPath(); + int packageStart = templatePath.indexOf("org/antlr/v4/test/runtime"); + int packageEnd = templatePath.indexOf("/" + targetName + ".test.stg"); + String packageDir = templatePath.substring(packageStart, packageEnd); + return new File(outputDirectory, packageDir); } @Override - public String getTestTemplatesResourceDir() { return "runtime-testsuite/resources/org/antlr/v4/test/runtime/templates"; } + public String getTestTemplatesResourceDir() { + return "runtime-testsuite/resources/org/antlr/v4/test/runtime/templates"; + } }; gen.info("Generating target " + gen.getTargetNameFromTemplatesFileName()); gen.execute();