Skip to content

Commit

Permalink
sort dump files at the end of bootstrap
Browse files Browse the repository at this point in the history
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 <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Dec 11, 2023
1 parent 9eeb265 commit 2de3cf8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::io::Write;
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
use std::process;
use std::{
env, fs,
io::{self, IsTerminal},
env,
fs::{self, OpenOptions},
io::{self, BufRead, BufReader, IsTerminal},
};

use bootstrap::{
Expand Down Expand Up @@ -79,6 +80,9 @@ fn main() {
}

let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
let dump_bootstrap_shims = config.dump_bootstrap_shims;
let out_dir = config.out.clone();

Build::new(config).build();

if suggest_setup {
Expand Down Expand Up @@ -107,6 +111,29 @@ fn main() {
if suggest_setup || changelog_suggestion.is_some() {
println!("NOTE: this message was printed twice to make it more likely to be seen");
}

if dump_bootstrap_shims {
let dump_dir = out_dir.join("bootstrap-shims-dump");
assert!(dump_dir.exists());

for entry in walkdir::WalkDir::new(&dump_dir) {
let entry = t!(entry);

if !entry.file_type().is_file() {
continue;
}

let file = t!(fs::File::open(&entry.path()));

// To ensure deterministic results we must sort the dump lines.
// This is necessary because the order of rustc invocations different
// almost all the time.
let mut lines: Vec<String> = t!(BufReader::new(&file).lines().collect());
lines.sort_by_key(|t| t.to_lowercase());
let mut file = t!(OpenOptions::new().write(true).truncate(true).open(&entry.path()));
t!(file.write_all(lines.join("\n").as_bytes()));
}
}
}

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

0 comments on commit 2de3cf8

Please sign in to comment.