Skip to content

Commit 84b5b34

Browse files
Stop accessing current_dir in bootstrap
This ensures that the working directory of rustbuild has no effect on it's run; since tests will run with a different cwd this is required for consistent behavior.
1 parent 637ac17 commit 84b5b34

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

src/bootstrap/bootstrap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def __init__(self):
314314
self.build_dir = os.path.join(os.getcwd(), "build")
315315
self.clean = False
316316
self.config_toml = ''
317-
self.rust_root = os.path.abspath(os.path.join(__file__, '../../..'))
317+
self.rust_root = ''
318318
self.use_locked_deps = ''
319319
self.use_vendored_sources = ''
320320
self.verbose = False
@@ -710,6 +710,7 @@ def bootstrap(help_triggered):
710710
parser = argparse.ArgumentParser(description='Build rust')
711711
parser.add_argument('--config')
712712
parser.add_argument('--build')
713+
parser.add_argument('--src')
713714
parser.add_argument('--clean', action='store_true')
714715
parser.add_argument('-v', '--verbose', action='count', default=0)
715716

@@ -718,6 +719,7 @@ def bootstrap(help_triggered):
718719

719720
# Configure initial bootstrap
720721
build = RustBuild()
722+
build.rust_root = args.src or os.path.abspath(os.path.join(__file__, '../../..'))
721723
build.verbose = args.verbose
722724
build.clean = args.clean
723725

@@ -788,6 +790,7 @@ def bootstrap(help_triggered):
788790
env["SRC"] = build.rust_root
789791
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
790792
env["BOOTSTRAP_PYTHON"] = sys.executable
793+
env["BUILD_DIR"] = build.build_dir
791794
run(args, env=env, verbose=build.verbose)
792795

793796

src/bootstrap/config.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct Config {
143143
// These are either the stage0 downloaded binaries or the locally installed ones.
144144
pub initial_cargo: PathBuf,
145145
pub initial_rustc: PathBuf,
146+
pub out: PathBuf,
146147
}
147148

148149
/// Per-target configuration stored in the global configuration structure.
@@ -344,7 +345,8 @@ impl Config {
344345
config.rustc_error_format = flags.rustc_error_format;
345346
config.on_fail = flags.on_fail;
346347
config.stage = flags.stage;
347-
config.src = flags.src;
348+
// set by bootstrap.py
349+
config.src = env::var_os("SRC").map(PathBuf::from).expect("'SRC' to be set");
348350
config.jobs = flags.jobs;
349351
config.cmd = flags.cmd;
350352
config.incremental = flags.incremental;
@@ -368,12 +370,8 @@ impl Config {
368370
}).unwrap_or_else(|| TomlConfig::default());
369371

370372
let build = toml.build.clone().unwrap_or(Build::default());
371-
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
372-
set(&mut config.build, flags.build);
373-
if config.build.is_empty() {
374-
// set by bootstrap.py
375-
config.build = INTERNER.intern_str(&env::var("BUILD").unwrap());
376-
}
373+
// set by bootstrap.py
374+
config.build = INTERNER.intern_str(&env::var("BUILD").unwrap());
377375
config.hosts.push(config.build.clone());
378376
for host in build.host.iter() {
379377
let host = INTERNER.intern_str(host);
@@ -514,13 +512,13 @@ impl Config {
514512
let mut target = Target::default();
515513

516514
if let Some(ref s) = cfg.llvm_config {
517-
target.llvm_config = Some(env::current_dir().unwrap().join(s));
515+
target.llvm_config = Some(config.src.join(s));
518516
}
519517
if let Some(ref s) = cfg.jemalloc {
520-
target.jemalloc = Some(env::current_dir().unwrap().join(s));
518+
target.jemalloc = Some(config.src.join(s));
521519
}
522520
if let Some(ref s) = cfg.android_ndk {
523-
target.ndk = Some(env::current_dir().unwrap().join(s));
521+
target.ndk = Some(config.src.join(s));
524522
}
525523
target.cc = cfg.cc.clone().map(PathBuf::from);
526524
target.cxx = cfg.cxx.clone().map(PathBuf::from);
@@ -541,8 +539,8 @@ impl Config {
541539
set(&mut config.rust_dist_src, t.src_tarball);
542540
}
543541

544-
let cwd = t!(env::current_dir());
545-
let out = cwd.join("build");
542+
let out = env::var_os("BUILD_DIR").map(PathBuf::from).expect("'BUILD_DIR' set");
543+
config.out = out.clone();
546544

547545
let stage0_root = out.join(&config.build).join("stage0/bin");
548546
config.initial_rustc = match build.rustc {

src/bootstrap/flags.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ pub struct Flags {
3333
pub on_fail: Option<String>,
3434
pub stage: Option<u32>,
3535
pub keep_stage: Option<u32>,
36-
pub build: Option<Interned<String>>,
3736

3837
pub host: Vec<Interned<String>>,
3938
pub target: Vec<Interned<String>>,
4039
pub config: Option<PathBuf>,
41-
pub src: PathBuf,
4240
pub jobs: Option<u32>,
4341
pub cmd: Subcommand,
4442
pub incremental: bool,
@@ -278,10 +276,6 @@ Arguments:
278276
_ => { }
279277
};
280278
// Get any optional paths which occur after the subcommand
281-
let cwd = t!(env::current_dir());
282-
let src = matches.opt_str("src").map(PathBuf::from)
283-
.or_else(|| env::var_os("SRC").map(PathBuf::from))
284-
.unwrap_or(cwd.clone());
285279
let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
286280

287281
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
@@ -374,7 +368,6 @@ Arguments:
374368
on_fail: matches.opt_str("on-fail"),
375369
rustc_error_format: matches.opt_str("error-format"),
376370
keep_stage: matches.opt_str("keep-stage").map(|j| j.parse().unwrap()),
377-
build: matches.opt_str("build").map(|s| INTERNER.intern_string(s)),
378371
host: split(matches.opt_strs("host"))
379372
.into_iter().map(|x| INTERNER.intern_string(x)).collect::<Vec<_>>(),
380373
target: split(matches.opt_strs("target"))
@@ -385,7 +378,6 @@ Arguments:
385378
incremental: matches.opt_present("incremental"),
386379
exclude: split(matches.opt_strs("exclude"))
387380
.into_iter().map(|p| p.into()).collect::<Vec<_>>(),
388-
src,
389381
}
390382
}
391383
}

src/bootstrap/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,8 @@ impl Build {
309309
///
310310
/// By default all build output will be placed in the current directory.
311311
pub fn new(config: Config) -> Build {
312-
let cwd = t!(env::current_dir());
313312
let src = config.src.clone();
314-
let out = cwd.join("build");
313+
let out = config.out.clone();
315314

316315
let is_sudo = match env::var_os("SUDO_USER") {
317316
Some(sudo_user) => {

0 commit comments

Comments
 (0)