Skip to content

Commit 0cfc9e5

Browse files
committed
sort dump files at the end of bootstrap
To ensure deterministic results we must sort the dump lines. This is necessary because the order of rustc invocations different almost all the time. Signed-off-by: onur-ozkan <[email protected]>
1 parent fe301c3 commit 0cfc9e5

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/bootstrap/src/bin/main.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::io::Write;
1010
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
1111
use std::process;
1212
use std::{
13-
env, fs,
14-
io::{self, IsTerminal},
13+
env,
14+
fs::{self, OpenOptions},
15+
io::{self, BufRead, BufReader, IsTerminal},
1516
};
1617

1718
use bootstrap::{
@@ -74,6 +75,9 @@ fn main() {
7475
}
7576

7677
let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
78+
let dump_bootstrap_shims = config.dump_bootstrap_shims;
79+
let out_dir = config.out.clone();
80+
7781
Build::new(config).build();
7882

7983
if suggest_setup {
@@ -102,6 +106,29 @@ fn main() {
102106
if suggest_setup || changelog_suggestion.is_some() {
103107
println!("NOTE: this message was printed twice to make it more likely to be seen");
104108
}
109+
110+
if dump_bootstrap_shims {
111+
let dump_dir = out_dir.join("bootstrap-shims-dump");
112+
assert!(dump_dir.exists());
113+
114+
for entry in walkdir::WalkDir::new(&dump_dir) {
115+
let entry = t!(entry);
116+
117+
if !entry.file_type().is_file() {
118+
continue;
119+
}
120+
121+
let file = t!(fs::File::open(&entry.path()));
122+
123+
// To ensure deterministic results we must sort the dump lines.
124+
// This is necessary because the order of rustc invocations different
125+
// almost all the time.
126+
let mut lines: Vec<String> = t!(BufReader::new(&file).lines().collect());
127+
lines.sort_by_key(|t| t.to_lowercase());
128+
let mut file = t!(OpenOptions::new().write(true).truncate(true).open(&entry.path()));
129+
t!(file.write_all(lines.join("\n").as_bytes()));
130+
}
131+
}
105132
}
106133

107134
fn check_version(config: &Config) -> Option<String> {

0 commit comments

Comments
 (0)