Allow using download-ci-llvm = true
outside the git checkout
@bjorn3 noticed that this is already allowed today when download-llvm is disabled, but breaks with it enabled: ``` $ ./rust2/x.py build fatal: not a git repository (or any of the parent directories): .git thread 'main' panicked at 'command did not execute successfully: "git" "rev-list" "--author=bors@rust-lang.org" "-n1" "--first-parent" "HEAD" "--" "/home/jnelson/rust-lang/rust2/src/llvm-project" "/home/jnelson/rust-lang/rust2/src/bootstrap/download-ci-llvm-stamp" "/home/jnelson/rust-lang/rust2/src/version" expected success, got: exit status: 128', src/bootstrap/native.rs:134:20 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` Support it too for consistency. It's unclear to me when anyone would need to use this, but @bjorn3 feels we should support it, and it's not much additional effort to get it working. This also updates a bunch of other git commands that were similarly depending on the current directory.
This commit is contained in:
parent
a09c668c96
commit
56e42b8713
5 changed files with 34 additions and 29 deletions
|
@ -1128,11 +1128,7 @@ impl Config {
|
||||||
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
|
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
|
||||||
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
|
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
|
||||||
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
|
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
|
||||||
config.download_rustc_commit = download_ci_rustc_commit(
|
config.download_rustc_commit = download_ci_rustc_commit(&config, rust.download_rustc);
|
||||||
&config.stage0_metadata,
|
|
||||||
rust.download_rustc,
|
|
||||||
config.verbose > 0,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
config.rust_profile_use = flags.rust_profile_use;
|
config.rust_profile_use = flags.rust_profile_use;
|
||||||
config.rust_profile_generate = flags.rust_profile_generate;
|
config.rust_profile_generate = flags.rust_profile_generate;
|
||||||
|
@ -1304,6 +1300,15 @@ impl Config {
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A git invocation which runs inside the source directory.
|
||||||
|
///
|
||||||
|
/// Use this rather than `Command::new("git")` in order to support out-of-tree builds.
|
||||||
|
pub(crate) fn git(&self) -> Command {
|
||||||
|
let mut git = Command::new("git");
|
||||||
|
git.current_dir(&self.src);
|
||||||
|
git
|
||||||
|
}
|
||||||
|
|
||||||
/// Try to find the relative path of `bindir`, otherwise return it in full.
|
/// Try to find the relative path of `bindir`, otherwise return it in full.
|
||||||
pub fn bindir_relative(&self) -> &Path {
|
pub fn bindir_relative(&self) -> &Path {
|
||||||
let bindir = &self.bindir;
|
let bindir = &self.bindir;
|
||||||
|
@ -1453,9 +1458,8 @@ fn threads_from_config(v: u32) -> u32 {
|
||||||
|
|
||||||
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
|
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
|
||||||
fn download_ci_rustc_commit(
|
fn download_ci_rustc_commit(
|
||||||
stage0_metadata: &Stage0Metadata,
|
config: &Config,
|
||||||
download_rustc: Option<StringOrBool>,
|
download_rustc: Option<StringOrBool>,
|
||||||
verbose: bool,
|
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
// If `download-rustc` is not set, default to rebuilding.
|
// If `download-rustc` is not set, default to rebuilding.
|
||||||
let if_unchanged = match download_rustc {
|
let if_unchanged = match download_rustc {
|
||||||
|
@ -1468,7 +1472,7 @@ fn download_ci_rustc_commit(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle running from a directory other than the top level
|
// Handle running from a directory other than the top level
|
||||||
let top_level = output(Command::new("git").args(&["rev-parse", "--show-toplevel"]));
|
let top_level = output(config.git().args(&["rev-parse", "--show-toplevel"]));
|
||||||
let top_level = top_level.trim_end();
|
let top_level = top_level.trim_end();
|
||||||
let compiler = format!("{top_level}/compiler/");
|
let compiler = format!("{top_level}/compiler/");
|
||||||
let library = format!("{top_level}/library/");
|
let library = format!("{top_level}/library/");
|
||||||
|
@ -1476,9 +1480,10 @@ fn download_ci_rustc_commit(
|
||||||
// Look for a version to compare to based on the current commit.
|
// Look for a version to compare to based on the current commit.
|
||||||
// Only commits merged by bors will have CI artifacts.
|
// Only commits merged by bors will have CI artifacts.
|
||||||
let merge_base = output(
|
let merge_base = output(
|
||||||
Command::new("git")
|
config
|
||||||
|
.git()
|
||||||
.arg("rev-list")
|
.arg("rev-list")
|
||||||
.arg(format!("--author={}", stage0_metadata.config.git_merge_commit_email))
|
.arg(format!("--author={}", config.stage0_metadata.config.git_merge_commit_email))
|
||||||
.args(&["-n1", "--first-parent", "HEAD"]),
|
.args(&["-n1", "--first-parent", "HEAD"]),
|
||||||
);
|
);
|
||||||
let commit = merge_base.trim_end();
|
let commit = merge_base.trim_end();
|
||||||
|
@ -1491,13 +1496,14 @@ fn download_ci_rustc_commit(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn if there were changes to the compiler or standard library since the ancestor commit.
|
// Warn if there were changes to the compiler or standard library since the ancestor commit.
|
||||||
let has_changes = !t!(Command::new("git")
|
let has_changes = !t!(config
|
||||||
|
.git()
|
||||||
.args(&["diff-index", "--quiet", &commit, "--", &compiler, &library])
|
.args(&["diff-index", "--quiet", &commit, "--", &compiler, &library])
|
||||||
.status())
|
.status())
|
||||||
.success();
|
.success();
|
||||||
if has_changes {
|
if has_changes {
|
||||||
if if_unchanged {
|
if if_unchanged {
|
||||||
if verbose {
|
if config.verbose > 0 {
|
||||||
println!(
|
println!(
|
||||||
"warning: saw changes to compiler/ or library/ since {commit}; \
|
"warning: saw changes to compiler/ or library/ since {commit}; \
|
||||||
ignoring `download-rustc`"
|
ignoring `download-rustc`"
|
||||||
|
|
|
@ -72,7 +72,9 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
};
|
};
|
||||||
if git_available {
|
if git_available {
|
||||||
let in_working_tree = match Command::new("git")
|
let in_working_tree = match build
|
||||||
|
.config
|
||||||
|
.git()
|
||||||
.arg("rev-parse")
|
.arg("rev-parse")
|
||||||
.arg("--is-inside-work-tree")
|
.arg("--is-inside-work-tree")
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
|
@ -84,10 +86,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
};
|
};
|
||||||
if in_working_tree {
|
if in_working_tree {
|
||||||
let untracked_paths_output = output(
|
let untracked_paths_output = output(
|
||||||
Command::new("git")
|
build.config.git().arg("status").arg("--porcelain").arg("--untracked-files=normal"),
|
||||||
.arg("status")
|
|
||||||
.arg("--porcelain")
|
|
||||||
.arg("--untracked-files=normal"),
|
|
||||||
);
|
);
|
||||||
let untracked_paths = untracked_paths_output
|
let untracked_paths = untracked_paths_output
|
||||||
.lines()
|
.lines()
|
||||||
|
|
|
@ -634,7 +634,8 @@ impl Build {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let output = output(
|
let output = output(
|
||||||
Command::new("git")
|
self.config
|
||||||
|
.git()
|
||||||
.args(&["config", "--file"])
|
.args(&["config", "--file"])
|
||||||
.arg(&self.config.src.join(".gitmodules"))
|
.arg(&self.config.src.join(".gitmodules"))
|
||||||
.args(&["--get-regexp", "path"]),
|
.args(&["--get-regexp", "path"]),
|
||||||
|
@ -1271,12 +1272,12 @@ impl Build {
|
||||||
// That's our beta number!
|
// That's our beta number!
|
||||||
// (Note that we use a `..` range, not the `...` symmetric difference.)
|
// (Note that we use a `..` range, not the `...` symmetric difference.)
|
||||||
let count = output(
|
let count = output(
|
||||||
Command::new("git")
|
self.config
|
||||||
|
.git()
|
||||||
.arg("rev-list")
|
.arg("rev-list")
|
||||||
.arg("--count")
|
.arg("--count")
|
||||||
.arg("--merges")
|
.arg("--merges")
|
||||||
.arg("refs/remotes/origin/master..HEAD")
|
.arg("refs/remotes/origin/master..HEAD"),
|
||||||
.current_dir(&self.src),
|
|
||||||
);
|
);
|
||||||
let n = count.trim().parse().unwrap();
|
let n = count.trim().parse().unwrap();
|
||||||
self.prerelease_version.set(Some(n));
|
self.prerelease_version.set(Some(n));
|
||||||
|
|
|
@ -118,7 +118,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
|
||||||
if !config.llvm_from_ci {
|
if !config.llvm_from_ci {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut rev_list = Command::new("git");
|
let mut rev_list = config.git();
|
||||||
rev_list.args(&[
|
rev_list.args(&[
|
||||||
PathBuf::from("rev-list"),
|
PathBuf::from("rev-list"),
|
||||||
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
|
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
|
||||||
|
|
|
@ -136,7 +136,7 @@ pub fn setup(config: &Config, profile: Profile) {
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
t!(install_git_hook_maybe(&config.src));
|
t!(install_git_hook_maybe(&config));
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ pub fn interactive_path() -> io::Result<Profile> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// install a git hook to automatically run tidy --bless, if they want
|
// install a git hook to automatically run tidy --bless, if they want
|
||||||
fn install_git_hook_maybe(src_path: &Path) -> io::Result<()> {
|
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
println!(
|
println!(
|
||||||
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
|
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
|
||||||
|
@ -328,13 +328,12 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
|
||||||
};
|
};
|
||||||
|
|
||||||
if should_install {
|
if should_install {
|
||||||
let src = src_path.join("src").join("etc").join("pre-push.sh");
|
let src = config.src.join("src").join("etc").join("pre-push.sh");
|
||||||
let git = t!(Command::new("git").args(&["rev-parse", "--git-common-dir"]).output().map(
|
let git =
|
||||||
|output| {
|
t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
|
||||||
assert!(output.status.success(), "failed to run `git`");
|
assert!(output.status.success(), "failed to run `git`");
|
||||||
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
|
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
let dst = git.join("hooks").join("pre-push");
|
let dst = git.join("hooks").join("pre-push");
|
||||||
match fs::hard_link(src, &dst) {
|
match fs::hard_link(src, &dst) {
|
||||||
Err(e) => eprintln!(
|
Err(e) => eprintln!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue