From 276ba8b97d8127fb1efbf84a22bef010d784b9ee Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 2 Jul 2018 13:02:00 -0700 Subject: [PATCH] Support systems which don't have a "python" command. (#386) Add support for finding an appropriate python command on systems which don't have "python". Try "python3" and "python2.7". Fixed #381. --- cranelift/test-all.sh | 2 +- lib/codegen/build.rs | 16 +++++++++++++++- lib/codegen/meta/check.sh | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cranelift/test-all.sh b/cranelift/test-all.sh index 5c280523d3..4bb7330f09 100755 --- a/cranelift/test-all.sh +++ b/cranelift/test-all.sh @@ -46,7 +46,7 @@ else needcheck=yes fi if [ -n "$needcheck" ]; then - banner "$(python --version 2>&1), $(python3 --version 2>&1)" + banner "Checking python source files" "$topdir/lib/codegen/meta/check.sh" touch "$tsfile" || echo no target directory fi diff --git a/lib/codegen/build.rs b/lib/codegen/build.rs index d127f357b4..c52c70873e 100644 --- a/lib/codegen/build.rs +++ b/lib/codegen/build.rs @@ -26,6 +26,7 @@ fn main() { let target_triple = env::var("TARGET").expect("The TARGET environment variable must be set"); let cretonne_targets = env::var("CRETONNE_TARGETS").ok(); let cretonne_targets = cretonne_targets.as_ref().map(|s| s.as_ref()); + let python = identify_python(); // Configure isa targets cfg. match isa_targets(cretonne_targets, &target_triple) { @@ -60,7 +61,7 @@ fn main() { // Launch build script with Python. We'll just find python in the path. // Use -B to disable .pyc files, because they cause trouble for vendoring // scripts, and this is a build step that isn't run very often anyway. - let status = process::Command::new("python") + let status = process::Command::new(python) .current_dir(crate_dir) .arg("-B") .arg(build_script) @@ -73,6 +74,19 @@ fn main() { } } +fn identify_python() -> &'static str { + for python in &["python", "python3", "python2.7"] { + if process::Command::new(python) + .arg("--version") + .status() + .is_ok() + { + return python; + } + } + panic!("The Cretonne build requires Python (version 2.7 or version 3)"); +} + /// Represents known ISA target. #[derive(Copy, Clone)] enum Isa { diff --git a/lib/codegen/meta/check.sh b/lib/codegen/meta/check.sh index ce34f78f4b..14e51da065 100755 --- a/lib/codegen/meta/check.sh +++ b/lib/codegen/meta/check.sh @@ -5,7 +5,8 @@ cd "$topdir" function runif { if type "$1" > /dev/null; then - echo " === $1 ===" + version=$("$1" --version 2>&1) + echo " === $1: $version ===" "$@" else echo "$1 not found" @@ -19,7 +20,7 @@ runif flake8 . runif mypy --py2 build.py # Python unit tests. -runif python -m unittest discover +runif python2.7 -m unittest discover # Then run the unit tests again with Python 3. # We get deprecation warnings about assertRaisesRegexp which was renamed in