forked from jasder/antlr
Merge pull request #2964 from parrt/multi-py-versions
allow multiple versions when locating python tool
This commit is contained in:
commit
9f3ebd1667
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
package org.antlr.v4.test.runtime.python;
|
package org.antlr.v4.test.runtime.python;
|
||||||
|
|
||||||
|
import com.sun.codemodel.internal.JForEach;
|
||||||
import org.antlr.v4.Tool;
|
import org.antlr.v4.Tool;
|
||||||
import org.antlr.v4.automata.ATNFactory;
|
import org.antlr.v4.automata.ATNFactory;
|
||||||
import org.antlr.v4.automata.ATNPrinter;
|
import org.antlr.v4.automata.ATNPrinter;
|
||||||
|
@ -513,31 +514,33 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String locateTool(String tool) {
|
private String locateTool(List<String> tools) {
|
||||||
String[] roots = {
|
String[] roots = {
|
||||||
"/opt/local/bin", "/usr/bin/", "/usr/local/bin/",
|
"/opt/local/bin", "/usr/bin/", "/usr/local/bin/",
|
||||||
"/Users/"+System.getProperty("user.name")+"/anaconda3/bin/"
|
"/Users/"+System.getProperty("user.name")+"/anaconda3/bin/"
|
||||||
};
|
};
|
||||||
for(String root : roots) {
|
for(String root : roots) {
|
||||||
if(new File(root + tool).exists()) {
|
for (String tool : tools) {
|
||||||
return root+tool;
|
if ( new File(root+tool).exists() ) {
|
||||||
|
return root+tool;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Could not locate " + tool);
|
throw new RuntimeException("Could not locate " + tools);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String locatePython() {
|
protected String locatePython() {
|
||||||
String propName = getPropertyPrefix() + "-python";
|
String propName = getPropertyPrefix() + "-python";
|
||||||
String prop = System.getProperty(propName);
|
String prop = System.getProperty(propName);
|
||||||
if(prop==null || prop.length()==0)
|
if(prop==null || prop.length()==0)
|
||||||
prop = locateTool(getPythonExecutable());
|
prop = locateTool(getPythonExecutables());
|
||||||
File file = new File(prop);
|
File file = new File(prop);
|
||||||
if(!file.exists())
|
if(!file.exists())
|
||||||
throw new RuntimeException("Missing system property:" + propName);
|
throw new RuntimeException("Missing system property:" + propName);
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getPythonExecutable();
|
protected abstract List<String> getPythonExecutables();
|
||||||
|
|
||||||
protected String locateRuntime() { return locateRuntime(getLanguage()); }
|
protected String locateRuntime() { return locateRuntime(getLanguage()); }
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ package org.antlr.v4.test.runtime.python2;
|
||||||
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
||||||
import org.stringtemplate.v4.ST;
|
import org.stringtemplate.v4.ST;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||||
|
|
||||||
public class BasePython2Test extends BasePythonTest {
|
public class BasePython2Test extends BasePythonTest {
|
||||||
|
@ -19,8 +23,8 @@ public class BasePython2Test extends BasePythonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPythonExecutable() {
|
protected List<String> getPythonExecutables() {
|
||||||
return "python2.7";
|
return Collections.singletonList("python2.7");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,9 @@ package org.antlr.v4.test.runtime.python3;
|
||||||
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
||||||
import org.stringtemplate.v4.ST;
|
import org.stringtemplate.v4.ST;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||||
|
|
||||||
public class BasePython3Test extends BasePythonTest {
|
public class BasePython3Test extends BasePythonTest {
|
||||||
|
@ -18,9 +21,9 @@ public class BasePython3Test extends BasePythonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPythonExecutable() {
|
protected List<String> getPythonExecutables() {
|
||||||
return "python3.7";
|
return Arrays.asList("python3.7", "python3.8");
|
||||||
} // force 3.7
|
} // force 3.7 or 3.8
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeLexerTestFile(String lexerName, boolean showDFA) {
|
protected void writeLexerTestFile(String lexerName, boolean showDFA) {
|
||||||
|
|
Loading…
Reference in New Issue