Skip to content

Commit

Permalink
Auto merge of #37769 - alexcrichton:rustbuild-python, r=brson
Browse files Browse the repository at this point in the history
rustbuild: Allow configuration of python interpreter

Add a configuration key to `config.toml`, read it from `./configure`, and add
auto-detection if none of those were specified.

Closes #35760
  • Loading branch information
bors committed Nov 18, 2016
2 parents 01d061f + 5f62613 commit 2a6d02e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/bootstrap/check.rs
Expand Up @@ -130,17 +130,15 @@ pub fn compiletest(build: &Build,
build.test_helpers_out(target).display()));
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));

// FIXME: CFG_PYTHON should probably be detected more robustly elsewhere
let python_default = "python";
cmd.arg("--docck-python").arg(python_default);
cmd.arg("--docck-python").arg(build.python());

if build.config.build.ends_with("apple-darwin") {
// Force /usr/bin/python on OSX for LLDB tests because we're loading the
// LLDB plugin's compiled module which only works with the system python
// (namely not Homebrew-installed python)
cmd.arg("--lldb-python").arg("/usr/bin/python");
} else {
cmd.arg("--lldb-python").arg(python_default);
cmd.arg("--lldb-python").arg(build.python());
}

if let Some(ref gdb) = build.config.gdb {
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/config.rs
Expand Up @@ -90,6 +90,7 @@ pub struct Config {
pub codegen_tests: bool,
pub nodejs: Option<PathBuf>,
pub gdb: Option<PathBuf>,
pub python: Option<PathBuf>,
}

/// Per-target configuration stored in the global configuration structure.
Expand Down Expand Up @@ -130,6 +131,7 @@ struct Build {
gdb: Option<String>,
vendor: Option<bool>,
nodejs: Option<String>,
python: Option<String>,
}

/// TOML representation of how the LLVM build is configured.
Expand Down Expand Up @@ -237,6 +239,7 @@ impl Config {
config.cargo = build.cargo.map(PathBuf::from);
config.nodejs = build.nodejs.map(PathBuf::from);
config.gdb = build.gdb.map(PathBuf::from);
config.python = build.python.map(PathBuf::from);
set(&mut config.compiler_docs, build.compiler_docs);
set(&mut config.docs, build.docs);
set(&mut config.submodules, build.submodules);
Expand Down Expand Up @@ -466,6 +469,10 @@ impl Config {
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
}
"CFG_PYTHON" if value.len() > 0 => {
let path = parse_configure_path(value);
self.python = Some(path);
}
_ => {}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/bootstrap/config.toml.example
Expand Up @@ -82,9 +82,19 @@
# Indicate whether submodules are managed and updated automatically.
#submodules = true

# The path to (or name of) the GDB executable to use
# The path to (or name of) the GDB executable to use. This is only used for
# executing the debuginfo test suite.
#gdb = "gdb"

# The node.js executable to use. Note that this is only used for the emscripten
# target when running tests, otherwise this can be omitted.
#nodejs = "node"

# Python interpreter to use for various tasks throughout the build, notably
# rustdoc tests, the lldb python interpreter, and some dist bits and pieces.
# Note that Python 2 is currently required.
#python = "python2.7"

# Indicate whether the vendored sources are used for Rust dependencies or not
#vendor = false

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/dist.rs
Expand Up @@ -99,7 +99,7 @@ pub fn mingw(build: &Build, host: &str) {
// (which is what we want).
//
// FIXME: this script should be rewritten into Rust
let mut cmd = Command::new("python");
let mut cmd = Command::new(build.python());
cmd.arg(build.src.join("src/etc/make-win-dist.py"))
.arg(tmpdir(build))
.arg(&image)
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
//
// FIXME: this script should be rewritten into Rust
if host.contains("pc-windows-gnu") {
let mut cmd = Command::new("python");
let mut cmd = Command::new(build.python());
cmd.arg(build.src.join("src/etc/make-win-dist.py"))
.arg(&image)
.arg(tmpdir(build))
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/lib.rs
Expand Up @@ -774,6 +774,11 @@ impl Build {
.or(self.config.musl_root.as_ref())
.map(|p| &**p)
}

/// Path to the python interpreter to use
fn python(&self) -> &Path {
self.config.python.as_ref().unwrap()
}
}

impl<'a> Compiler<'a> {
Expand Down
12 changes: 11 additions & 1 deletion src/bootstrap/sanity.rs
Expand Up @@ -79,7 +79,17 @@ pub fn check(build: &mut Build) {
break
}

need_cmd("python".as_ref());
if build.config.python.is_none() {
build.config.python = have_cmd("python2.7".as_ref());
}
if build.config.python.is_none() {
build.config.python = have_cmd("python2".as_ref());
}
if build.config.python.is_none() {
need_cmd("python".as_ref());
build.config.python = Some("python".into());
}
need_cmd(build.config.python.as_ref().unwrap().as_ref());


if let Some(ref s) = build.config.nodejs {
Expand Down

0 comments on commit 2a6d02e

Please sign in to comment.