use of org.antlr.v4.runtime in project antlr4 by antlr.
the class BaseGoTest method groupSetUp.
/**
* Copies all files from go runtime to a temporary folder that is inside a valid GOPATH project structure.
*/
public static void groupSetUp() throws Exception {
tmpGopath = new File(System.getProperty("java.io.tmpdir"), "antlr-goruntime-tmpgopath-" + Long.toHexString(System.currentTimeMillis()));
ArrayList<String> pathsegments = new ArrayList<String>();
pathsegments.add("src");
pathsegments.addAll(Arrays.asList(GO_RUNTIME_IMPORT_PATH.split("/")));
File tmpPackageDir = tmpGopath;
for (String pathsegment : pathsegments) {
tmpPackageDir = new File(tmpPackageDir, pathsegment);
}
if (!tmpPackageDir.mkdirs()) {
throw new Exception("Could not create temp go runtime package dirs!");
}
File[] runtimeFiles = locateRuntime().listFiles();
if (runtimeFiles == null) {
throw new Exception("Go runtime file list is empty.");
}
for (File runtimeFile : runtimeFiles) {
File dest = new File(tmpPackageDir, runtimeFile.getName());
copyFile(runtimeFile, dest);
}
cacheGoRuntime(tmpPackageDir);
}
use of org.antlr.v4.runtime in project antlr4 by antlr.
the class BaseGoTest method locateRuntime.
private static File locateRuntime() {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final URL runtimeSrc = loader.getResource("Go");
if (runtimeSrc == null) {
throw new RuntimeException("Cannot find Go ANTLR runtime");
}
File runtimeDir = new File(runtimeSrc.getPath(), "antlr");
if (!runtimeDir.exists()) {
throw new RuntimeException("Cannot find Go ANTLR runtime");
}
return runtimeDir;
}
use of org.antlr.v4.runtime in project antlr4 by antlr.
the class BaseCppTest method locateRuntime.
protected String locateRuntime() {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final URL runtimeURL = loader.getResource("Cpp");
if (runtimeURL == null) {
throw new RuntimeException("Cannot find runtime");
}
// Windows not getting runtime right. See:
// http://stackoverflow.com/questions/6164448/convert-url-to-normal-windows-filename-java
// it was coming back "/C:/projects/antlr4-l7imv/runtime-testsuite/target/classes/Cpp"
String p;
try {
p = Paths.get(runtimeURL.toURI()).toFile().toString();
} catch (URISyntaxException use) {
p = "Can't find runtime";
}
return p;
}
use of org.antlr.v4.runtime in project antlr4 by antlr.
the class BaseCppTest method buildRuntime.
// TODO: add a buildRuntimeOnWindows variant.
private boolean buildRuntime() {
String runtimePath = locateRuntime();
System.out.println("Building ANTLR4 C++ runtime (if necessary) at " + runtimePath);
try {
String[] command = { "cmake", ".", /*"-DCMAKE_CXX_COMPILER=clang++",*/
"-DCMAKE_BUILD_TYPE=release" };
if (runCommand(command, runtimePath, "antlr runtime cmake", false) == null) {
return false;
}
} catch (Exception e) {
System.err.println("can't configure antlr cpp runtime cmake file");
}
try {
// Assuming a reasonable amount of available CPU cores.
String[] command = { "make", "-j", "8" };
if (runCommand(command, runtimePath, "building antlr runtime", true) == null)
return false;
} catch (Exception e) {
System.err.println("can't compile antlr cpp runtime");
e.printStackTrace(System.err);
try {
String[] command = { "ls", "-la" };
String output = runCommand(command, runtimePath + "/dist/", "printing library folder content", true);
System.out.println(output);
} catch (Exception e2) {
System.err.println("can't even list folder content");
e2.printStackTrace(System.err);
}
}
return true;
}
use of org.antlr.v4.runtime in project antlr4 by antlr.
the class BaseCppTest method execModule.
public String execModule(String fileName) {
String runtimePath = locateRuntime();
String includePath = runtimePath + "/runtime/src";
String binPath = new File(new File(tmpdir), "a.out").getAbsolutePath();
String inputPath = new File(new File(tmpdir), "input").getAbsolutePath();
// Build runtime using cmake once.
synchronized (runtimeBuiltOnce) {
if (!runtimeBuiltOnce) {
try {
String[] command = { "clang++", "--version" };
String output = runCommand(command, tmpdir, "printing compiler version", false);
System.out.println("Compiler version is: " + output);
} catch (Exception e) {
System.err.println("Can't get compiler version");
}
runtimeBuiltOnce = true;
if (!buildRuntime()) {
System.out.println("C++ runtime build failed\n");
return null;
}
System.out.println("C++ runtime build succeeded\n");
}
}
// Create symlink to the runtime. Currently only used on OSX.
String libExtension = (getOS().equals("mac")) ? "dylib" : "so";
try {
String[] command = { "ln", "-s", runtimePath + "/dist/libantlr4-runtime." + libExtension };
if (runCommand(command, tmpdir, "sym linking C++ runtime", true) == null)
return null;
} catch (Exception e) {
System.err.println("can't create link to " + runtimePath + "/dist/libantlr4-runtime." + libExtension);
e.printStackTrace(System.err);
return null;
}
try {
List<String> command2 = new ArrayList<String>(Arrays.asList("clang++", "-std=c++11", "-I", includePath, "-L.", "-lantlr4-runtime", "-o", "a.out"));
command2.addAll(allCppFiles(tmpdir));
if (runCommand(command2.toArray(new String[0]), tmpdir, "building test binary", true) == null) {
return null;
}
} catch (Exception e) {
System.err.println("can't compile test module: " + e.getMessage());
e.printStackTrace(System.err);
return null;
}
// Now run the newly minted binary. Reset the error output, as we could have got compiler warnings which are not relevant here.
this.stderrDuringParse = null;
try {
ProcessBuilder builder = new ProcessBuilder(binPath, inputPath);
builder.directory(new File(tmpdir));
Map<String, String> env = builder.environment();
env.put("LD_PRELOAD", runtimePath + "/dist/libantlr4-runtime." + libExtension);
String output = runProcess(builder, "running test binary", false);
if (output.length() == 0) {
output = null;
}
/* for debugging
System.out.println("=========================================================");
System.out.println(output);
System.out.println("=========================================================");
*/
return output;
} catch (Exception e) {
System.err.println("can't exec module: " + fileName);
e.printStackTrace(System.err);
}
return null;
}
Aggregations