Skip to content

Commit b771d90

Browse files
committed
Revamp the order setup executes
- Create `config.toml` last. It's the most likely to error, and used to stop later steps from executing - Don't print an error message + exit if the git hook already exists; that's expected
1 parent 86251da commit b771d90

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/bootstrap/setup.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,10 @@ impl fmt::Display for Profile {
8080
}
8181

8282
pub fn setup(config: &Config, profile: Option<Profile>) {
83-
let path = &config.config.clone().unwrap_or(PathBuf::from("config.toml"));
8483
let profile = profile.unwrap_or_else(|| t!(interactive_path()));
85-
setup_config_toml(path, profile, config);
86-
8784
let stage_path =
8885
["build", config.build.rustc_target_arg(), "stage1"].join(&MAIN_SEPARATOR.to_string());
8986

90-
println!();
91-
9287
if !rustup_installed() && profile != Profile::User {
9388
eprintln!("`rustup` is not installed; cannot link `stage1` toolchain");
9489
} else if stage_dir_exists(&stage_path[..]) {
@@ -109,8 +104,6 @@ pub fn setup(config: &Config, profile: Option<Profile>) {
109104
Profile::User => &["dist", "build"],
110105
};
111106

112-
println!();
113-
114107
t!(install_git_hook_maybe(&config));
115108

116109
println!();
@@ -125,10 +118,14 @@ pub fn setup(config: &Config, profile: Option<Profile>) {
125118
"For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html"
126119
);
127120
}
121+
122+
let path = &config.config.clone().unwrap_or(PathBuf::from("config.toml"));
123+
setup_config_toml(path, profile, config);
128124
}
129125

130126
fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
131127
if path.exists() {
128+
eprintln!();
132129
eprintln!(
133130
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
134131
path.display()
@@ -304,7 +301,18 @@ pub fn interactive_path() -> io::Result<Profile> {
304301

305302
// install a git hook to automatically run tidy --bless, if they want
306303
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
304+
let git = t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
305+
assert!(output.status.success(), "failed to run `git`");
306+
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
307+
}));
308+
let dst = git.join("hooks").join("pre-push");
309+
if dst.exists() {
310+
// The git hook has already been set up, or the user already has a custom hook.
311+
return Ok(());
312+
}
313+
307314
let mut input = String::new();
315+
println!();
308316
println!(
309317
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
310318
If you'd like, x.py can install a git hook for you that will automatically run `tidy --bless` before
@@ -330,12 +338,6 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
330338

331339
if should_install {
332340
let src = config.src.join("src").join("etc").join("pre-push.sh");
333-
let git =
334-
t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
335-
assert!(output.status.success(), "failed to run `git`");
336-
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
337-
}));
338-
let dst = git.join("hooks").join("pre-push");
339341
match fs::hard_link(src, &dst) {
340342
Err(e) => eprintln!(
341343
"error: could not create hook {}: do you already have the git hook installed?\n{}",

0 commit comments

Comments
 (0)