]> git.lizzy.rs Git - rust.git/commitdiff
Stop accessing current_dir in bootstrap
authorMark Simulacrum <mark.simulacrum@gmail.com>
Sat, 10 Mar 2018 01:14:35 +0000 (18:14 -0700)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Tue, 3 Apr 2018 17:39:15 +0000 (11:39 -0600)
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.

src/bootstrap/bootstrap.py
src/bootstrap/config.rs
src/bootstrap/flags.rs
src/bootstrap/lib.rs

index eeac4436e6454f984edf3fe860d73989efffa1ac..cf54591f25cd576cd62fa204f939a95bfec1d40e 100644 (file)
@@ -314,7 +314,7 @@ class RustBuild(object):
         self.build_dir = os.path.join(os.getcwd(), "build")
         self.clean = False
         self.config_toml = ''
-        self.rust_root = os.path.abspath(os.path.join(__file__, '../../..'))
+        self.rust_root = ''
         self.use_locked_deps = ''
         self.use_vendored_sources = ''
         self.verbose = False
@@ -710,6 +710,7 @@ def bootstrap(help_triggered):
     parser = argparse.ArgumentParser(description='Build rust')
     parser.add_argument('--config')
     parser.add_argument('--build')
+    parser.add_argument('--src')
     parser.add_argument('--clean', action='store_true')
     parser.add_argument('-v', '--verbose', action='count', default=0)
 
@@ -718,6 +719,7 @@ def bootstrap(help_triggered):
 
     # Configure initial bootstrap
     build = RustBuild()
+    build.rust_root = args.src or os.path.abspath(os.path.join(__file__, '../../..'))
     build.verbose = args.verbose
     build.clean = args.clean
 
@@ -788,6 +790,7 @@ def bootstrap(help_triggered):
     env["SRC"] = build.rust_root
     env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
     env["BOOTSTRAP_PYTHON"] = sys.executable
+    env["BUILD_DIR"] = build.build_dir
     run(args, env=env, verbose=build.verbose)
 
 
index 33850debd3bdbff0056a5482642e2217a34dc08f..8df5f406619193850b349941a447423a8a0996f2 100644 (file)
@@ -143,6 +143,7 @@ pub struct Config {
     // These are either the stage0 downloaded binaries or the locally installed ones.
     pub initial_cargo: PathBuf,
     pub initial_rustc: PathBuf,
+    pub out: PathBuf,
 }
 
 /// Per-target configuration stored in the global configuration structure.
@@ -344,7 +345,8 @@ pub fn parse(args: &[String]) -> Config {
         config.rustc_error_format = flags.rustc_error_format;
         config.on_fail = flags.on_fail;
         config.stage = flags.stage;
-        config.src = flags.src;
+        // set by bootstrap.py
+        config.src = env::var_os("SRC").map(PathBuf::from).expect("'SRC' to be set");
         config.jobs = flags.jobs;
         config.cmd = flags.cmd;
         config.incremental = flags.incremental;
@@ -368,12 +370,8 @@ pub fn parse(args: &[String]) -> Config {
         }).unwrap_or_else(|| TomlConfig::default());
 
         let build = toml.build.clone().unwrap_or(Build::default());
-        set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
-        set(&mut config.build, flags.build);
-        if config.build.is_empty() {
-            // set by bootstrap.py
-            config.build = INTERNER.intern_str(&env::var("BUILD").unwrap());
-        }
+        // set by bootstrap.py
+        config.build = INTERNER.intern_str(&env::var("BUILD").unwrap());
         config.hosts.push(config.build.clone());
         for host in build.host.iter() {
             let host = INTERNER.intern_str(host);
@@ -514,13 +512,13 @@ pub fn parse(args: &[String]) -> Config {
                 let mut target = Target::default();
 
                 if let Some(ref s) = cfg.llvm_config {
-                    target.llvm_config = Some(env::current_dir().unwrap().join(s));
+                    target.llvm_config = Some(config.src.join(s));
                 }
                 if let Some(ref s) = cfg.jemalloc {
-                    target.jemalloc = Some(env::current_dir().unwrap().join(s));
+                    target.jemalloc = Some(config.src.join(s));
                 }
                 if let Some(ref s) = cfg.android_ndk {
-                    target.ndk = Some(env::current_dir().unwrap().join(s));
+                    target.ndk = Some(config.src.join(s));
                 }
                 target.cc = cfg.cc.clone().map(PathBuf::from);
                 target.cxx = cfg.cxx.clone().map(PathBuf::from);
@@ -541,8 +539,8 @@ pub fn parse(args: &[String]) -> Config {
             set(&mut config.rust_dist_src, t.src_tarball);
         }
 
-        let cwd = t!(env::current_dir());
-        let out = cwd.join("build");
+        let out = env::var_os("BUILD_DIR").map(PathBuf::from).expect("'BUILD_DIR' set");
+        config.out = out.clone();
 
         let stage0_root = out.join(&config.build).join("stage0/bin");
         config.initial_rustc = match build.rustc {
index c5af0f8e2e15331cc45fbf779b471731cde82149..60b22e35832f95ecd683fc4bb5c602d7478cce1b 100644 (file)
@@ -33,12 +33,10 @@ pub struct Flags {
     pub on_fail: Option<String>,
     pub stage: Option<u32>,
     pub keep_stage: Option<u32>,
-    pub build: Option<Interned<String>>,
 
     pub host: Vec<Interned<String>>,
     pub target: Vec<Interned<String>>,
     pub config: Option<PathBuf>,
-    pub src: PathBuf,
     pub jobs: Option<u32>,
     pub cmd: Subcommand,
     pub incremental: bool,
@@ -278,10 +276,6 @@ pub fn parse(args: &[String]) -> Flags {
             _ => { }
         };
         // Get any optional paths which occur after the subcommand
-        let cwd = t!(env::current_dir());
-        let src = matches.opt_str("src").map(PathBuf::from)
-            .or_else(|| env::var_os("SRC").map(PathBuf::from))
-            .unwrap_or(cwd.clone());
         let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
 
         let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
@@ -374,7 +368,6 @@ pub fn parse(args: &[String]) -> Flags {
             on_fail: matches.opt_str("on-fail"),
             rustc_error_format: matches.opt_str("error-format"),
             keep_stage: matches.opt_str("keep-stage").map(|j| j.parse().unwrap()),
-            build: matches.opt_str("build").map(|s| INTERNER.intern_string(s)),
             host: split(matches.opt_strs("host"))
                 .into_iter().map(|x| INTERNER.intern_string(x)).collect::<Vec<_>>(),
             target: split(matches.opt_strs("target"))
@@ -385,7 +378,6 @@ pub fn parse(args: &[String]) -> Flags {
             incremental: matches.opt_present("incremental"),
             exclude: split(matches.opt_strs("exclude"))
                 .into_iter().map(|p| p.into()).collect::<Vec<_>>(),
-            src,
         }
     }
 }
index 833faf3618d67151c0b7e840d49a4388136636e2..8b19bff3f6af87d160123c44b6cf8a7bdf8cd0d3 100644 (file)
@@ -309,9 +309,8 @@ impl Build {
     ///
     /// By default all build output will be placed in the current directory.
     pub fn new(config: Config) -> Build {
-        let cwd = t!(env::current_dir());
         let src = config.src.clone();
-        let out = cwd.join("build");
+        let out = config.out.clone();
 
         let is_sudo = match env::var_os("SUDO_USER") {
             Some(sudo_user) => {