From 240f28832978235d18c0b3ade44814784a20d2fc Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 24 Dec 2021 13:03:02 -0600 Subject: [PATCH] Move some more bootstrap logic from python to rust Same rationale as https://github.com/rust-lang/rust/pull/76544; it would be nice to make python entirely optional at some point. This also removes $ROOT as an option for the build directory; I haven't been using it, and like Alex said in https://github.com/rust-lang/rust/pull/76544#discussion_r488248930 it seems like a misfeature. This allows running `cargo run` from src/bootstrap, although that still gives lots of compile errors if you don't use the beta toolchain. --- src/bootstrap/Cargo.toml | 1 + src/bootstrap/bootstrap.py | 3 +-- src/bootstrap/config.rs | 35 ++++++++++++++--------------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index fe9d6a727ed..4c32547f059 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -3,6 +3,7 @@ name = "bootstrap" version = "0.0.0" edition = "2021" build = "build.rs" +default-run = "bootstrap" [lib] path = "lib.rs" diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 6c1128b393f..532e072bc7e 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1267,7 +1267,7 @@ def bootstrap(help_triggered): build.check_vendored_status() build_dir = build.get_toml('build-dir', 'build') or 'build' - build.build_dir = os.path.abspath(build_dir.replace("$ROOT", build.rust_root)) + build.build_dir = os.path.abspath(build_dir) with open(os.path.join(build.rust_root, "src", "stage0.json")) as f: data = json.load(f) @@ -1302,7 +1302,6 @@ def bootstrap(help_triggered): env = os.environ.copy() env["BOOTSTRAP_PARENT_ID"] = str(os.getpid()) env["BOOTSTRAP_PYTHON"] = sys.executable - env["BUILD_DIR"] = build.build_dir env["RUSTC_BOOTSTRAP"] = '1' if toml_path: env["BOOTSTRAP_CONFIG"] = toml_path diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b17b94f2893..0a5bda50687 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -6,7 +6,6 @@ use std::cmp; use std::collections::{HashMap, HashSet}; use std::env; -use std::ffi::OsString; use std::fmt; use std::fs; use std::path::{Path, PathBuf}; @@ -392,7 +391,6 @@ derive_merge! { build: Option, host: Option>, target: Option>, - // This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable build_dir: Option, cargo: Option, rustc: Option, @@ -588,18 +586,6 @@ derive_merge! { } impl Config { - fn path_from_python(var_key: &str) -> PathBuf { - match env::var_os(var_key) { - Some(var_val) => Self::normalize_python_path(var_val), - _ => panic!("expected '{}' to be set", var_key), - } - } - - /// Normalizes paths from Python slightly. We don't trust paths from Python (#49785). - fn normalize_python_path(path: OsString) -> PathBuf { - Path::new(&path).components().collect() - } - pub fn default_opts() -> Config { let mut config = Config::default(); config.llvm_optimize = true; @@ -625,7 +611,7 @@ impl Config { let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); // Undo `src/bootstrap` config.src = manifest_dir.parent().unwrap().parent().unwrap().to_owned(); - config.out = Config::path_from_python("BUILD_DIR"); + config.out = PathBuf::from("build"); config.initial_cargo = PathBuf::from(env!("CARGO")); config.initial_rustc = PathBuf::from(env!("RUSTC")); @@ -655,12 +641,6 @@ impl Config { config.llvm_profile_use = flags.llvm_profile_use; config.llvm_profile_generate = flags.llvm_profile_generate; - if config.dry_run { - let dir = config.out.join("tmp-dry-run"); - t!(fs::create_dir_all(&dir)); - config.out = dir; - } - #[cfg(test)] let get_toml = |_| TomlConfig::default(); #[cfg(not(test))] @@ -695,6 +675,19 @@ impl Config { let build = toml.build.unwrap_or_default(); + set(&mut config.out, build.build_dir.map(String::into)); + t!(fs::create_dir_all(&config.out)); + config.out = t!( + config.out.canonicalize(), + format!("failed to canonicalize {}", config.out.display()) + ); + + if config.dry_run { + let dir = config.out.join("tmp-dry-run"); + t!(fs::create_dir_all(&dir)); + config.out = dir; + } + config.hosts = if let Some(arg_host) = flags.host { arg_host } else if let Some(file_host) = build.host {