Skip to content

Commit eae4135

Browse files
committed
Auto merge of #117708 - onur-ozkan:x-setup, r=clubby789
check config file before prompts on `x setup` First 2 commit moves the check of configuration existence to the first step of `x setup`. And then followed by a prompt that allows devs to decide whether to continue with the configuration override or exit bootstrap. Closes #110471 I can revert the last commit if needed. Maybe it's just me, but I feel it's better to have those tags capitalized. If you think otherwise, please let me know so that I can revert.
2 parents 4c8862b + d1e2640 commit eae4135

23 files changed

+112
-104
lines changed

src/bootstrap/bootstrap.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def require(cmd, exit=True, exception=False):
211211
if exception:
212212
raise
213213
elif exit:
214-
eprint("error: unable to run `{}`: {}".format(' '.join(cmd), exc))
214+
eprint("ERROR: unable to run `{}`: {}".format(' '.join(cmd), exc))
215215
eprint("Please make sure it's installed and in the path.")
216216
sys.exit(1)
217217
return None
@@ -681,7 +681,7 @@ def get_answer():
681681

682682
answer = self._should_fix_bins_and_dylibs = get_answer()
683683
if answer:
684-
eprint("info: You seem to be using Nix.")
684+
eprint("INFO: You seem to be using Nix.")
685685
return answer
686686

687687
def fix_bin_or_dylib(self, fname):
@@ -727,7 +727,7 @@ def fix_bin_or_dylib(self, fname):
727727
"nix-build", "-E", nix_expr, "-o", nix_deps_dir,
728728
])
729729
except subprocess.CalledProcessError as reason:
730-
eprint("warning: failed to call nix-build:", reason)
730+
eprint("WARNING: failed to call nix-build:", reason)
731731
return
732732
self.nix_deps_dir = nix_deps_dir
733733

@@ -747,7 +747,7 @@ def fix_bin_or_dylib(self, fname):
747747
try:
748748
subprocess.check_output([patchelf] + patchelf_args + [fname])
749749
except subprocess.CalledProcessError as reason:
750-
eprint("warning: failed to call patchelf:", reason)
750+
eprint("WARNING: failed to call patchelf:", reason)
751751
return
752752

753753
def rustc_stamp(self):
@@ -1005,7 +1005,7 @@ def check_vendored_status(self):
10051005
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
10061006
if os.getuid() == 0:
10071007
self.use_vendored_sources = True
1008-
eprint('info: looks like you\'re trying to run this command as root')
1008+
eprint('INFO: looks like you\'re trying to run this command as root')
10091009
eprint(' and so in order to preserve your $HOME this will now')
10101010
eprint(' use vendored sources by default.')
10111011

@@ -1017,14 +1017,14 @@ def check_vendored_status(self):
10171017
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
10181018
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
10191019
"--sync ./src/bootstrap/Cargo.toml "
1020-
eprint('error: vendoring required, but vendor directory does not exist.')
1020+
eprint('ERROR: vendoring required, but vendor directory does not exist.')
10211021
eprint(' Run `cargo vendor {}` to initialize the '
10221022
'vendor directory.'.format(sync_dirs))
10231023
eprint('Alternatively, use the pre-vendored `rustc-src` dist component.')
10241024
raise Exception("{} not found".format(vendor_dir))
10251025

10261026
if not os.path.exists(cargo_dir):
1027-
eprint('error: vendoring required, but .cargo/config does not exist.')
1027+
eprint('ERROR: vendoring required, but .cargo/config does not exist.')
10281028
raise Exception("{} not found".format(cargo_dir))
10291029
else:
10301030
if os.path.exists(cargo_dir):
@@ -1125,7 +1125,7 @@ def main():
11251125
# process has to happen before anything is printed out.
11261126
if help_triggered:
11271127
eprint(
1128-
"info: Downloading and building bootstrap before processing --help command.\n"
1128+
"INFO: Downloading and building bootstrap before processing --help command.\n"
11291129
" See src/bootstrap/README.md for help with common commands.")
11301130

11311131
exit_code = 0

src/bootstrap/bootstrap_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def serialize_and_parse(configure_args, bootstrap_args=None):
3434
# Verify this is actually valid TOML.
3535
tomllib.loads(build.config_toml)
3636
except ImportError:
37-
print("warning: skipping TOML validation, need at least python 3.11", file=sys.stderr)
37+
print("WARNING: skipping TOML validation, need at least python 3.11", file=sys.stderr)
3838
return build
3939

4040

src/bootstrap/configure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def parse_args(args):
253253
if not found:
254254
unknown_args.append(arg)
255255

256-
# Note: here and a few other places, we use [-1] to apply the *last* value
256+
# NOTE: here and a few other places, we use [-1] to apply the *last* value
257257
# passed. But if option-checking is enabled, then the known_args loop will
258258
# also assert that options are only passed once.
259259
option_checking = ('option-checking' not in known_args
@@ -477,7 +477,7 @@ def configure_section(lines, config):
477477
# These are used by rpm, but aren't accepted by x.py.
478478
# Give a warning that they're ignored, but not a hard error.
479479
if key in ["infodir", "localstatedir"]:
480-
print("warning: {} will be ignored".format(key))
480+
print("WARNING: {} will be ignored".format(key))
481481
else:
482482
raise RuntimeError("failed to find config line for {}".format(key))
483483

src/bootstrap/src/bin/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() {
6363
if suggest_setup {
6464
println!("WARNING: you have not made a `config.toml`");
6565
println!(
66-
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
66+
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
6767
`cp config.example.toml config.toml`"
6868
);
6969
} else if let Some(suggestion) = &changelog_suggestion {
@@ -76,7 +76,7 @@ fn main() {
7676
if suggest_setup {
7777
println!("WARNING: you have not made a `config.toml`");
7878
println!(
79-
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
79+
"HELP: consider running `./x.py setup` or copying `config.example.toml` by running \
8080
`cp config.example.toml config.toml`"
8181
);
8282
} else if let Some(suggestion) = &changelog_suggestion {
@@ -97,7 +97,7 @@ fn main() {
9797
}
9898

9999
if suggest_setup || changelog_suggestion.is_some() {
100-
println!("note: this message was printed twice to make it more likely to be seen");
100+
println!("NOTE: this message was printed twice to make it more likely to be seen");
101101
}
102102
}
103103

@@ -128,14 +128,14 @@ fn check_version(config: &Config) -> Option<String> {
128128

129129
msg.push_str("WARNING: there have been changes to x.py since you last updated.\n");
130130

131-
msg.push_str("note: to silence this warning, ");
131+
msg.push_str("NOTE: to silence this warning, ");
132132
msg.push_str(&format!(
133133
"update `config.toml` to use `change-id = {latest_config_id}` instead"
134134
));
135135
}
136136
} else {
137137
msg.push_str("WARNING: The `change-id` is missing in the `config.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
138-
msg.push_str("note: to silence this warning, ");
138+
msg.push_str("NOTE: to silence this warning, ");
139139
msg.push_str(&format!("add `change-id = {latest_config_id}` at the top of `config.toml`"));
140140
};
141141

src/bootstrap/src/bin/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn main() {
245245

246246
if status.success() {
247247
std::process::exit(0);
248-
// note: everything below here is unreachable. do not put code that
248+
// NOTE: everything below here is unreachable. do not put code that
249249
// should run on success, after this block.
250250
}
251251
if verbose > 0 {

src/bootstrap/src/core/build_steps/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn rm_rf(path: &Path) {
177177
&& p.file_name().and_then(std::ffi::OsStr::to_str)
178178
== Some("bootstrap.exe")
179179
{
180-
eprintln!("warning: failed to delete '{}'.", p.display());
180+
eprintln!("WARNING: failed to delete '{}'.", p.display());
181181
return Ok(());
182182
}
183183
Err(e)

src/bootstrap/src/core/build_steps/compile.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Step for Std {
141141
if builder.config.keep_stage.contains(&compiler.stage)
142142
|| builder.config.keep_stage_std.contains(&compiler.stage)
143143
{
144-
builder.info("Warning: Using a potentially old libstd. This may not behave well.");
144+
builder.info("WARNING: Using a potentially old libstd. This may not behave well.");
145145

146146
copy_third_party_objects(builder, &compiler, target);
147147
copy_self_contained_objects(builder, &compiler, target);
@@ -817,8 +817,8 @@ impl Step for Rustc {
817817
builder.ensure(Std::new(compiler, target));
818818

819819
if builder.config.keep_stage.contains(&compiler.stage) {
820-
builder.info("Warning: Using a potentially old librustc. This may not behave well.");
821-
builder.info("Warning: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
820+
builder.info("WARNING: Using a potentially old librustc. This may not behave well.");
821+
builder.info("WARNING: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
822822
builder.ensure(RustcLink::from_rustc(self, compiler));
823823
return;
824824
}
@@ -1203,8 +1203,8 @@ fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
12031203
}
12041204
if needs_codegen_backend_config {
12051205
run.builder.info(
1206-
"Warning: no codegen-backends config matched the requested path to build a codegen backend. \
1207-
Help: add backend to codegen-backends in config.toml.",
1206+
"WARNING: no codegen-backends config matched the requested path to build a codegen backend. \
1207+
HELP: add backend to codegen-backends in config.toml.",
12081208
);
12091209
return true;
12101210
}
@@ -1250,7 +1250,7 @@ impl Step for CodegenBackend {
12501250

12511251
if builder.config.keep_stage.contains(&compiler.stage) {
12521252
builder.info(
1253-
"Warning: Using a potentially old codegen backend. \
1253+
"WARNING: Using a potentially old codegen backend. \
12541254
This may not behave well.",
12551255
);
12561256
// Codegen backends are linked separately from this step today, so we don't do
@@ -1525,14 +1525,14 @@ impl Step for Sysroot {
15251525
let sysroot_lib_rustlib_src_rust = sysroot_lib_rustlib_src.join("rust");
15261526
if let Err(e) = symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_src_rust) {
15271527
eprintln!(
1528-
"warning: creating symbolic link `{}` to `{}` failed with {}",
1528+
"WARNING: creating symbolic link `{}` to `{}` failed with {}",
15291529
sysroot_lib_rustlib_src_rust.display(),
15301530
builder.src.display(),
15311531
e,
15321532
);
15331533
if builder.config.rust_remap_debuginfo {
15341534
eprintln!(
1535-
"warning: some `tests/ui` tests will fail when lacking `{}`",
1535+
"WARNING: some `tests/ui` tests will fail when lacking `{}`",
15361536
sysroot_lib_rustlib_src_rust.display(),
15371537
);
15381538
}
@@ -1545,7 +1545,7 @@ impl Step for Sysroot {
15451545
symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
15461546
{
15471547
eprintln!(
1548-
"warning: creating symbolic link `{}` to `{}` failed with {}",
1548+
"WARNING: creating symbolic link `{}` to `{}` failed with {}",
15491549
sysroot_lib_rustlib_rustcsrc_rust.display(),
15501550
builder.src.display(),
15511551
e,
@@ -1986,7 +1986,7 @@ pub fn stream_cargo(
19861986
builder.verbose(&format!("running: {cargo:?}"));
19871987
let mut child = match cargo.spawn() {
19881988
Ok(child) => child,
1989-
Err(e) => panic!("failed to execute command: {cargo:?}\nerror: {e}"),
1989+
Err(e) => panic!("failed to execute command: {cargo:?}\nERROR: {e}"),
19901990
};
19911991

19921992
// Spawn Cargo slurping up its JSON output. We'll start building up the
@@ -2050,7 +2050,7 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
20502050
}
20512051

20522052
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
2053-
// Note: `output` will propagate any errors here.
2053+
// NOTE: `output` will propagate any errors here.
20542054
output(Command::new("strip").arg("--strip-debug").arg(path));
20552055

20562056
// After running `strip`, we have to set the file modification time to what it was before,

src/bootstrap/src/core/build_steps/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ install!((self, builder, _config),
269269
}
270270
};
271271
RustDemangler, alias = "rust-demangler", Self::should_build(_config), only_hosts: true, {
272-
// Note: Even though `should_build` may return true for `extended` default tools,
272+
// NOTE: Even though `should_build` may return true for `extended` default tools,
273273
// dist::RustDemangler may still return None, unless the target-dependent `profiler` config
274274
// is also true, or the `tools` array explicitly includes "rust-demangler".
275275
if let Some(tarball) = builder.ensure(dist::RustDemangler {

src/bootstrap/src/core/build_steps/llvm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
156156

157157
if llvm_sha.is_empty() {
158158
eprintln!("error: could not find commit hash for downloading LLVM");
159-
eprintln!("help: maybe your repository history is too shallow?");
160-
eprintln!("help: consider disabling `download-ci-llvm`");
161-
eprintln!("help: or fetch enough history to include one upstream commit");
159+
eprintln!("HELP: maybe your repository history is too shallow?");
160+
eprintln!("HELP: consider disabling `download-ci-llvm`");
161+
eprintln!("HELP: or fetch enough history to include one upstream commit");
162162
panic!();
163163
}
164164

src/bootstrap/src/core/build_steps/setup.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ impl Step for Profile {
122122
return;
123123
}
124124

125+
let path = &run.builder.config.config.clone().unwrap_or(PathBuf::from("config.toml"));
126+
if path.exists() {
127+
eprintln!();
128+
eprintln!(
129+
"ERROR: you asked for a new config file, but one already exists at `{}`",
130+
t!(path.canonicalize()).display()
131+
);
132+
133+
match prompt_user(
134+
"Do you wish to override the existing configuration (which will allow the setup process to continue)?: [y/N]",
135+
) {
136+
Ok(Some(PromptResult::Yes)) => {
137+
t!(fs::remove_file(path));
138+
}
139+
_ => {
140+
println!("Exiting.");
141+
crate::exit!(1);
142+
}
143+
}
144+
}
145+
125146
// for Profile, `run.paths` will have 1 and only 1 element
126147
// this is because we only accept at most 1 path from user input.
127148
// If user calls `x.py setup` without arguments, the interactive TUI
@@ -191,7 +212,7 @@ pub fn setup(config: &Config, profile: Profile) {
191212
if profile == Profile::Tools {
192213
eprintln!();
193214
eprintln!(
194-
"note: the `tools` profile sets up the `stage2` toolchain (use \
215+
"NOTE: the `tools` profile sets up the `stage2` toolchain (use \
195216
`rustup toolchain link 'name' build/host/stage2` to use rustc)"
196217
)
197218
}
@@ -204,19 +225,6 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
204225
if profile == Profile::None {
205226
return;
206227
}
207-
if path.exists() {
208-
eprintln!();
209-
eprintln!(
210-
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
211-
path.display()
212-
);
213-
eprintln!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
214-
eprintln!(
215-
"note: this will use the configuration in {}",
216-
profile.include_path(&config.src).display()
217-
);
218-
crate::exit!(1);
219-
}
220228

221229
let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap();
222230
let settings = format!(
@@ -406,8 +414,8 @@ pub fn interactive_path() -> io::Result<Profile> {
406414
break match parse_with_abbrev(&input) {
407415
Ok(profile) => profile,
408416
Err(err) => {
409-
eprintln!("error: {err}");
410-
eprintln!("note: press Ctrl+C to exit");
417+
eprintln!("ERROR: {err}");
418+
eprintln!("NOTE: press Ctrl+C to exit");
411419
continue;
412420
}
413421
};
@@ -436,8 +444,8 @@ fn prompt_user(prompt: &str) -> io::Result<Option<PromptResult>> {
436444
"p" | "print" => return Ok(Some(PromptResult::Print)),
437445
"" => return Ok(None),
438446
_ => {
439-
eprintln!("error: unrecognized option '{}'", input.trim());
440-
eprintln!("note: press Ctrl+C to exit");
447+
eprintln!("ERROR: unrecognized option '{}'", input.trim());
448+
eprintln!("NOTE: press Ctrl+C to exit");
441449
}
442450
};
443451
}
@@ -504,7 +512,7 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
504512
match fs::hard_link(src, &dst) {
505513
Err(e) => {
506514
eprintln!(
507-
"error: could not create hook {}: do you already have the git hook installed?\n{}",
515+
"ERROR: could not create hook {}: do you already have the git hook installed?\n{}",
508516
dst.display(),
509517
e
510518
);
@@ -570,10 +578,10 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<()> {
570578
);
571579
match mismatched_settings {
572580
Some(true) => eprintln!(
573-
"warning: existing `.vscode/settings.json` is out of date, x.py will update it"
581+
"WARNING: existing `.vscode/settings.json` is out of date, x.py will update it"
574582
),
575583
Some(false) => eprintln!(
576-
"warning: existing `.vscode/settings.json` has been modified by user, x.py will back it up and replace it"
584+
"WARNING: existing `.vscode/settings.json` has been modified by user, x.py will back it up and replace it"
577585
),
578586
_ => (),
579587
}
@@ -600,7 +608,7 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<()> {
600608
// exists and is not current version or outdated, so back it up
601609
let mut backup = vscode_settings.clone();
602610
backup.set_extension("json.bak");
603-
eprintln!("warning: copying `settings.json` to `settings.json.bak`");
611+
eprintln!("WARNING: copying `settings.json` to `settings.json.bak`");
604612
fs::copy(&vscode_settings, &backup)?;
605613
"Updated"
606614
}

src/bootstrap/src/core/build_steps/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
7373
build.build();
7474
}
7575
} else {
76-
println!("help: consider using the `--run` flag to automatically run suggested tests");
76+
println!("HELP: consider using the `--run` flag to automatically run suggested tests");
7777
}
7878
}

0 commit comments

Comments
 (0)