Skip to content

Commit 3f959aa

Browse files
committed
modify when we read file
1 parent accb1fb commit 3f959aa

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::core::build_steps::tool::{self, RustcPrivateCompilers, SourceType, To
1414
use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor};
1515
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
1616
use crate::core::config::TargetSelection;
17-
use crate::core::config::flags::{get_completion, get_help};
17+
use crate::core::config::flags::{get_completion, top_level_help};
1818
use crate::utils::exec::command;
1919
use crate::{Mode, t};
2020

@@ -514,11 +514,10 @@ impl Step for GenerateHelp {
514514
type Output = ();
515515

516516
fn run(self, builder: &Builder<'_>) {
517+
let help = top_level_help();
517518
let path = get_help_path(builder);
518-
if let Some(help) = get_help(&path) {
519-
std::fs::write(&path, help)
520-
.unwrap_or_else(|e| panic!("writing help into {} failed: {e:?}", path.display()));
521-
}
519+
std::fs::write(&path, help)
520+
.unwrap_or_else(|e| panic!("writing help into {} failed: {e:?}", path.display()));
522521
}
523522

524523
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::core::builder::{
2828
crate_description,
2929
};
3030
use crate::core::config::TargetSelection;
31-
use crate::core::config::flags::{Subcommand, get_completion, get_help};
31+
use crate::core::config::flags::{Subcommand, get_completion, top_level_help};
3232
use crate::utils::build_stamp::{self, BuildStamp};
3333
use crate::utils::exec::{BootstrapCommand, command};
3434
use crate::utils::helpers::{
@@ -1295,12 +1295,20 @@ HELP: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
12951295
}
12961296

12971297
builder.info("x.py help check");
1298-
let help_path = get_help_path(builder);
12991298
if builder.config.cmd.bless() {
13001299
builder.ensure(crate::core::build_steps::run::GenerateHelp);
1301-
} else if get_help(&help_path).is_some() {
1302-
eprintln!("x.py help was changed; run `x.py run generate-help` to update them");
1303-
crate::exit!(1);
1300+
} else {
1301+
let help_path = get_help_path(builder);
1302+
let cur_help = std::fs::read_to_string(&help_path).unwrap_or_else(|err| {
1303+
eprintln!("couldn't read {}: {}", help_path.display(), err.to_string());
1304+
crate::exit!(1);
1305+
});
1306+
let new_help = top_level_help();
1307+
1308+
if new_help != cur_help {
1309+
eprintln!("x.py help was changed; run `x.py run generate-help` to update it");
1310+
crate::exit!(1);
1311+
}
13041312
}
13051313
}
13061314

src/bootstrap/src/core/config/flags.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -702,24 +702,8 @@ pub fn get_completion(shell: &dyn Generator, path: &Path) -> Option<String> {
702702
Some(String::from_utf8(buf).expect("completion script should be UTF-8"))
703703
}
704704

705-
/// Return the help of the bootstrap if the result differs from the current
706-
/// help in `path`. It always returns the help if `path` does not exist.
707-
pub fn get_help(path: &Path) -> Option<String> {
705+
/// Return the top level help of the bootstrap.
706+
pub fn top_level_help() -> String {
708707
let mut cmd = Flags::command();
709-
let cur_help = if !path.exists() {
710-
String::new()
711-
} else {
712-
std::fs::read_to_string(path).unwrap_or_else(|_| {
713-
eprintln!("couldn't read {}", path.display());
714-
crate::exit!(1)
715-
})
716-
};
717-
718-
let new_help = cmd.render_help();
719-
720-
if new_help.to_string() == cur_help {
721-
return None;
722-
}
723-
724-
Some(new_help.to_string())
708+
cmd.render_help().to_string()
725709
}

0 commit comments

Comments
 (0)