diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /src/bootstrap/lib.rs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bootstrap/lib.rs')
-rw-r--r-- | src/bootstrap/lib.rs | 137 |
1 files changed, 81 insertions, 56 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 943f51341..0a7aff622 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -27,6 +27,7 @@ use std::process::{Command, Stdio}; use std::str; use build_helper::ci::{gha, CiEnv}; +use build_helper::detail_exit_macro; use channel::GitInfo; use config::{DryRun, Target}; use filetime::FileTime; @@ -60,6 +61,7 @@ mod run; mod sanity; mod setup; mod suggest; +mod synthetic_targets; mod tarball; mod test; mod tool; @@ -221,13 +223,14 @@ pub struct Build { initial_cargo: PathBuf, initial_lld: PathBuf, initial_libdir: PathBuf, + initial_sysroot: PathBuf, // Runtime state filled in later on // C/C++ compilers and archiver for all targets - cc: HashMap<TargetSelection, cc::Tool>, - cxx: HashMap<TargetSelection, cc::Tool>, - ar: HashMap<TargetSelection, PathBuf>, - ranlib: HashMap<TargetSelection, PathBuf>, + cc: RefCell<HashMap<TargetSelection, cc::Tool>>, + cxx: RefCell<HashMap<TargetSelection, cc::Tool>>, + ar: RefCell<HashMap<TargetSelection, PathBuf>>, + ranlib: RefCell<HashMap<TargetSelection, PathBuf>>, // Miscellaneous // allow bidirectional lookups: both name -> path and path -> name crates: HashMap<Interned<String>, Crate>, @@ -330,7 +333,7 @@ forward! { create(path: &Path, s: &str), remove(f: &Path), tempdir() -> PathBuf, - try_run(cmd: &mut Command) -> bool, + try_run(cmd: &mut Command) -> Result<(), ()>, llvm_link_shared() -> bool, download_rustc() -> bool, initial_rustfmt() -> Option<PathBuf>, @@ -388,13 +391,16 @@ impl Build { "/dummy".to_string() } else { output(Command::new(&config.initial_rustc).arg("--print").arg("sysroot")) - }; + } + .trim() + .to_string(); + let initial_libdir = initial_target_dir .parent() .unwrap() .parent() .unwrap() - .strip_prefix(initial_sysroot.trim()) + .strip_prefix(&initial_sysroot) .unwrap() .to_path_buf(); @@ -414,7 +420,6 @@ impl Build { bootstrap_out.display() ) } - config.check_build_rustc_version(); if rust_info.is_from_tarball() && config.description.is_none() { config.description = Some("built from a source tarball".to_owned()); @@ -425,6 +430,7 @@ impl Build { initial_cargo: config.initial_cargo.clone(), initial_lld, initial_libdir, + initial_sysroot: initial_sysroot.into(), local_rebuild: config.local_rebuild, fail_fast: config.cmd.fail_fast(), doc_tests: config.cmd.doc_tests(), @@ -446,10 +452,10 @@ impl Build { miri_info, rustfmt_info, in_tree_llvm_info, - cc: HashMap::new(), - cxx: HashMap::new(), - ar: HashMap::new(), - ranlib: HashMap::new(), + cc: RefCell::new(HashMap::new()), + cxx: RefCell::new(HashMap::new()), + ar: RefCell::new(HashMap::new()), + ranlib: RefCell::new(HashMap::new()), crates: HashMap::new(), crate_paths: HashMap::new(), is_sudo, @@ -477,7 +483,7 @@ impl Build { } build.verbose("finding compilers"); - cc_detect::find(&mut build); + cc_detect::find(&build); // When running `setup`, the profile is about to change, so any requirements we have now may // be different on the next invocation. Don't check for them until the next time x.py is // run. This is ok because `setup` never runs any build commands, so it won't fail if commands are missing. @@ -593,6 +599,9 @@ impl Build { let mut git = self.config.git(); if let Some(branch) = current_branch { + // If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name. + // This syntax isn't accepted by `branch.{branch}`. Strip it. + let branch = branch.strip_prefix("heads/").unwrap_or(&branch); git.arg("-c").arg(format!("branch.{branch}.remote=origin")); } git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]); @@ -608,11 +617,13 @@ impl Build { } // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error). - let has_local_modifications = !self.try_run( - Command::new("git") - .args(&["diff-index", "--quiet", "HEAD"]) - .current_dir(&absolute_path), - ); + let has_local_modifications = self + .try_run( + Command::new("git") + .args(&["diff-index", "--quiet", "HEAD"]) + .current_dir(&absolute_path), + ) + .is_err(); if has_local_modifications { self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); } @@ -700,7 +711,7 @@ impl Build { for failure in failures.iter() { eprintln!(" - {}\n", failure); } - detail_exit(1); + detail_exit_macro!(1); } #[cfg(feature = "build-metrics")] @@ -777,7 +788,7 @@ impl Build { /// Component directory that Cargo will produce output into (e.g. /// release/debug) fn cargo_dir(&self) -> &'static str { - if self.config.rust_optimize { "release" } else { "debug" } + if self.config.rust_optimize.is_release() { "release" } else { "debug" } } fn tools_dir(&self, compiler: Compiler) -> PathBuf { @@ -1001,6 +1012,15 @@ impl Build { self.msg(Kind::Check, self.config.stage, what, self.config.build, target) } + fn msg_doc( + &self, + compiler: Compiler, + what: impl Display, + target: impl Into<Option<TargetSelection>> + Copy, + ) -> Option<gha::Group> { + self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into()) + } + fn msg_build( &self, compiler: Compiler, @@ -1021,8 +1041,8 @@ impl Build { host: impl Into<Option<TargetSelection>>, target: impl Into<Option<TargetSelection>>, ) -> Option<gha::Group> { - let action = action.into(); - let msg = |fmt| format!("{action:?}ing stage{stage} {what}{fmt}"); + let action = action.into().description(); + let msg = |fmt| format!("{action} stage{stage} {what}{fmt}"); let msg = if let Some(target) = target.into() { let host = host.into().unwrap(); if host == target { @@ -1045,8 +1065,8 @@ impl Build { what: impl Display, target: TargetSelection, ) -> Option<gha::Group> { - let action = action.into(); - let msg = format!("{action:?}ing {what} for {target}"); + let action = action.into().description(); + let msg = format!("{action} {what} for {target}"); self.group(&msg) } @@ -1058,8 +1078,8 @@ impl Build { host: TargetSelection, target: TargetSelection, ) -> Option<gha::Group> { - let action = action.into(); - let msg = |fmt| format!("{action:?}ing {what} {fmt}"); + let action = action.into().description(); + let msg = |fmt| format!("{action} {what} {fmt}"); let msg = if host == target { msg(format_args!("(stage{stage} -> stage{}, {target})", stage + 1)) } else { @@ -1069,7 +1089,6 @@ impl Build { } fn group(&self, msg: &str) -> Option<gha::Group> { - self.info(&msg); match self.config.dry_run { DryRun::SelfCheck => None, DryRun::Disabled | DryRun::UserSelected => Some(gha::group(&msg)), @@ -1099,16 +1118,22 @@ impl Build { } /// Returns the path to the C compiler for the target specified. - fn cc(&self, target: TargetSelection) -> &Path { - self.cc[&target].path() + fn cc(&self, target: TargetSelection) -> PathBuf { + if self.config.dry_run() { + return PathBuf::new(); + } + self.cc.borrow()[&target].path().into() } /// Returns a list of flags to pass to the C compiler for the target /// specified. fn cflags(&self, target: TargetSelection, which: GitRepo, c: CLang) -> Vec<String> { + if self.config.dry_run() { + return Vec::new(); + } let base = match c { - CLang::C => &self.cc[&target], - CLang::Cxx => &self.cxx[&target], + CLang::C => self.cc.borrow()[&target].clone(), + CLang::Cxx => self.cxx.borrow()[&target].clone(), }; // Filter out -O and /O (the optimization flags) that we picked up from @@ -1149,19 +1174,28 @@ impl Build { } /// Returns the path to the `ar` archive utility for the target specified. - fn ar(&self, target: TargetSelection) -> Option<&Path> { - self.ar.get(&target).map(|p| &**p) + fn ar(&self, target: TargetSelection) -> Option<PathBuf> { + if self.config.dry_run() { + return None; + } + self.ar.borrow().get(&target).cloned() } /// Returns the path to the `ranlib` utility for the target specified. - fn ranlib(&self, target: TargetSelection) -> Option<&Path> { - self.ranlib.get(&target).map(|p| &**p) + fn ranlib(&self, target: TargetSelection) -> Option<PathBuf> { + if self.config.dry_run() { + return None; + } + self.ranlib.borrow().get(&target).cloned() } /// Returns the path to the C++ compiler for the target specified. - fn cxx(&self, target: TargetSelection) -> Result<&Path, String> { - match self.cxx.get(&target) { - Some(p) => Ok(p.path()), + fn cxx(&self, target: TargetSelection) -> Result<PathBuf, String> { + if self.config.dry_run() { + return Ok(PathBuf::new()); + } + match self.cxx.borrow().get(&target) { + Some(p) => Ok(p.path().into()), None => { Err(format!("target `{}` is not configured as a host, only as a target", target)) } @@ -1169,21 +1203,24 @@ impl Build { } /// Returns the path to the linker for the given target if it needs to be overridden. - fn linker(&self, target: TargetSelection) -> Option<&Path> { - if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref()) + fn linker(&self, target: TargetSelection) -> Option<PathBuf> { + if self.config.dry_run() { + return Some(PathBuf::new()); + } + if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.clone()) { Some(linker) } else if target.contains("vxworks") { // need to use CXX compiler as linker to resolve the exception functions // that are only existed in CXX libraries - Some(self.cxx[&target].path()) + Some(self.cxx.borrow()[&target].path().into()) } else if target != self.config.build && util::use_host_linker(target) && !target.contains("msvc") { Some(self.cc(target)) } else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target { - Some(&self.initial_lld) + Some(self.initial_lld.clone()) } else { None } @@ -1483,7 +1520,7 @@ impl Build { "Error: Unable to find the stamp file {}, did you try to keep a nonexistent build stage?", stamp.display() ); - crate::detail_exit(1); + crate::detail_exit_macro!(1); } let mut paths = Vec::new(); @@ -1675,7 +1712,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section to download LLVM rather than building it. " ); - detail_exit(1); + detail_exit_macro!(1); } } @@ -1740,18 +1777,6 @@ fn chmod(path: &Path, perms: u32) { #[cfg(windows)] fn chmod(_path: &Path, _perms: u32) {} -/// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.) -/// If the test is running and code is an error code, it will cause a panic. -fn detail_exit(code: i32) -> ! { - // if in test and code is an error code, panic with status code provided - if cfg!(test) { - panic!("status code: {}", code); - } else { - // otherwise,exit with provided status code - std::process::exit(code); - } -} - impl Compiler { pub fn with_stage(mut self, stage: u32) -> Compiler { self.stage = stage; |