runtime test/Go: Use $PATH and $GOROOT to find go executable.

This commit is contained in:
Wolfgang Johannes Kohnen 2016-05-21 22:51:36 +00:00
parent 3406acabe5
commit b6f384bf3c
1 changed files with 16 additions and 6 deletions

View File

@ -418,10 +418,21 @@ public abstract class BaseTest {
} }
private String locateTool(String tool) { private String locateTool(String tool) {
String[] roots = { "/usr/bin/", "/usr/local/bin/", "/usr/local/go/bin/" }; ArrayList<String> paths = new ArrayList<String>(); // default cap is about right
for (String root : roots) {
if (new File(root + tool).exists()) { String pathEnv = System.getenv("PATH");
return root + tool; if (pathEnv != null) {
paths.addAll(Arrays.asList(pathEnv.split(pathSep)));
}
String goroot = System.getenv("GOROOT");
if (goroot != null) {
paths.add(goroot + File.separatorChar + "bin");
}
for (String path : paths) {
File candidate = new File(path + File.separatorChar + tool);
if (candidate.exists()) {
return candidate.getPath();
} }
} }
return null; return null;
@ -434,8 +445,7 @@ public abstract class BaseTest {
if (prop == null || prop.length() == 0) { if (prop == null || prop.length() == 0) {
prop = locateTool("go"); prop = locateTool("go");
} }
File file = new File(prop); if (prop == null) {
if (!file.exists()) {
throw new RuntimeException("Missing system property:" + propName); throw new RuntimeException("Missing system property:" + propName);
} }
return prop; return prop;