Skip to content

Commit e1f4629

Browse files
committed
Replace the random substring of a linker argument with a placeholder and nullify the timestamp field of XCOFF files for file comparison.
1 parent 243d2ca commit e1f4629

File tree

1 file changed

+50
-3
lines changed
  • tests/run-make/reproducible-build

1 file changed

+50
-3
lines changed

tests/run-make/reproducible-build/rmake.rs

+50-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// Tracking Issue: https://github.com/rust-lang/rust/issues/129080
2222

2323
use run_make_support::{
24-
bin_name, cwd, diff, is_darwin, is_windows, rfs, run_in_tmpdir, rust_lib_name, rustc,
24+
bin_name, cwd, diff, is_darwin, is_windows, regex, rfs, run_in_tmpdir, rust_lib_name, rustc,
2525
};
2626

2727
fn main() {
@@ -117,7 +117,40 @@ fn smoke_test(flag: Option<SmokeFlag>) {
117117
.input("reproducible-build.rs")
118118
.linker(&cwd().join(bin_name("linker")).display().to_string())
119119
.run();
120-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
120+
121+
#[cfg(not(target_os = "aix"))]
122+
{
123+
diff()
124+
.actual_file("linker-arguments1")
125+
.expected_file("linker-arguments2")
126+
.run();
127+
}
128+
#[cfg(target_os = "aix")]
129+
{
130+
// The AIX link command includes an additional argument
131+
// that specifies the file containing exported symbols, e.g.,
132+
// -bE:/tmp/rustcO6hxkY/list.exp. In this example, the part of the
133+
// directory name "rustcO6hxkY" is randomly generated to ensure that
134+
// different linking processes do not collide. For the purpose
135+
// of comparing link arguments, the randomly generated part is
136+
// replaced with a placeholder.
137+
let content1 =
138+
std::fs::read_to_string("linker-arguments1").expect("Failed to read file");
139+
let content2 =
140+
std::fs::read_to_string("linker-arguments2").expect("Failed to read file");
141+
142+
// Define the regex for the directory name containing the random substring.
143+
let re = regex::Regex::new(r"rustc[a-zA-Z0-9]{6}/list\.exp").expect("Invalid regex");
144+
145+
// Compare link commands with random strings replaced by placeholders.
146+
assert!(
147+
re.replace_all(&content1, "rustcXXXXXX/list.exp")
148+
.to_string()
149+
== re
150+
.replace_all(&content2, "rustcXXXXXX/list.exp")
151+
.to_string()
152+
);
153+
}
121154
});
122155
}
123156

@@ -207,7 +240,21 @@ fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
207240
std::env::set_current_dir(&base_dir).unwrap();
208241
match crate_type {
209242
CrateType::Bin => {
210-
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
243+
#[cfg(not(target_os = "aix"))]
244+
{
245+
assert!(
246+
rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo"))
247+
);
248+
}
249+
#[cfg(target_os = "aix")]
250+
{
251+
// At the 4th-byte offset, the AIX XCOFF file header defines a
252+
// 4-byte timestamp. Nullify the timestamp before performing a
253+
// binary comparison.
254+
let mut file1 = rfs::read(bin_name("reproducible-build"));
255+
let mut file2 = rfs::read(bin_name("foo"));
256+
assert!(file1[4..8].fill(0x00) == file2[4..8].fill(0x00));
257+
};
211258
}
212259
CrateType::Rlib => {
213260
assert!(

0 commit comments

Comments
 (0)