Skip to content

Commit 2de3cf8

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 9eeb265 commit 2de3cf8

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::{
@@ -79,6 +80,9 @@ fn main() {
7980
}
8081

8182
let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
83+
let dump_bootstrap_shims = config.dump_bootstrap_shims;
84+
let out_dir = config.out.clone();
85+
8286
Build::new(config).build();
8387

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

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

0 commit comments

Comments
 (0)