Skip to content

Commit 2a6d02e

Browse files
authored
Auto merge of #37769 - alexcrichton:rustbuild-python, r=brson
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
2 parents 01d061f + 5f62613 commit 2a6d02e

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

Diff for: src/bootstrap/check.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,15 @@ pub fn compiletest(build: &Build,
130130
build.test_helpers_out(target).display()));
131131
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
132132

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

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

146144
if let Some(ref gdb) = build.config.gdb {

Diff for: src/bootstrap/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct Config {
9090
pub codegen_tests: bool,
9191
pub nodejs: Option<PathBuf>,
9292
pub gdb: Option<PathBuf>,
93+
pub python: Option<PathBuf>,
9394
}
9495

9596
/// Per-target configuration stored in the global configuration structure.
@@ -130,6 +131,7 @@ struct Build {
130131
gdb: Option<String>,
131132
vendor: Option<bool>,
132133
nodejs: Option<String>,
134+
python: Option<String>,
133135
}
134136

135137
/// TOML representation of how the LLVM build is configured.
@@ -237,6 +239,7 @@ impl Config {
237239
config.cargo = build.cargo.map(PathBuf::from);
238240
config.nodejs = build.nodejs.map(PathBuf::from);
239241
config.gdb = build.gdb.map(PathBuf::from);
242+
config.python = build.python.map(PathBuf::from);
240243
set(&mut config.compiler_docs, build.compiler_docs);
241244
set(&mut config.docs, build.docs);
242245
set(&mut config.submodules, build.submodules);
@@ -466,6 +469,10 @@ impl Config {
466469
self.rustc = Some(push_exe_path(path.clone(), &["bin", "rustc"]));
467470
self.cargo = Some(push_exe_path(path, &["bin", "cargo"]));
468471
}
472+
"CFG_PYTHON" if value.len() > 0 => {
473+
let path = parse_configure_path(value);
474+
self.python = Some(path);
475+
}
469476
_ => {}
470477
}
471478
}

Diff for: src/bootstrap/config.toml.example

+11-1
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@
8282
# Indicate whether submodules are managed and updated automatically.
8383
#submodules = true
8484

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

89+
# The node.js executable to use. Note that this is only used for the emscripten
90+
# target when running tests, otherwise this can be omitted.
91+
#nodejs = "node"
92+
93+
# Python interpreter to use for various tasks throughout the build, notably
94+
# rustdoc tests, the lldb python interpreter, and some dist bits and pieces.
95+
# Note that Python 2 is currently required.
96+
#python = "python2.7"
97+
8898
# Indicate whether the vendored sources are used for Rust dependencies or not
8999
#vendor = false
90100

Diff for: src/bootstrap/dist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn mingw(build: &Build, host: &str) {
9999
// (which is what we want).
100100
//
101101
// FIXME: this script should be rewritten into Rust
102-
let mut cmd = Command::new("python");
102+
let mut cmd = Command::new(build.python());
103103
cmd.arg(build.src.join("src/etc/make-win-dist.py"))
104104
.arg(tmpdir(build))
105105
.arg(&image)
@@ -159,7 +159,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
159159
//
160160
// FIXME: this script should be rewritten into Rust
161161
if host.contains("pc-windows-gnu") {
162-
let mut cmd = Command::new("python");
162+
let mut cmd = Command::new(build.python());
163163
cmd.arg(build.src.join("src/etc/make-win-dist.py"))
164164
.arg(&image)
165165
.arg(tmpdir(build))

Diff for: src/bootstrap/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ impl Build {
774774
.or(self.config.musl_root.as_ref())
775775
.map(|p| &**p)
776776
}
777+
778+
/// Path to the python interpreter to use
779+
fn python(&self) -> &Path {
780+
self.config.python.as_ref().unwrap()
781+
}
777782
}
778783

779784
impl<'a> Compiler<'a> {

Diff for: src/bootstrap/sanity.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,17 @@ pub fn check(build: &mut Build) {
7979
break
8080
}
8181

82-
need_cmd("python".as_ref());
82+
if build.config.python.is_none() {
83+
build.config.python = have_cmd("python2.7".as_ref());
84+
}
85+
if build.config.python.is_none() {
86+
build.config.python = have_cmd("python2".as_ref());
87+
}
88+
if build.config.python.is_none() {
89+
need_cmd("python".as_ref());
90+
build.config.python = Some("python".into());
91+
}
92+
need_cmd(build.config.python.as_ref().unwrap().as_ref());
8393

8494

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

0 commit comments

Comments
 (0)