Skip to content

Commit 2338e57

Browse files
Rollup merge of #135174 - xingxue-ibm:reproducible-build-aix, r=jieyouxu
[AIX] Port test case run-make/reproducible-build The test case `run-make/reproducible-build` verifies that two identical invocations of the compiler produce the same output by comparing the linker arguments, resulting binaries, and other artifacts. However, the AIX linker command includes an argument that specifies the file containing exported symbols, with a file path that contains a randomly generated substring to prevent collisions between different linking processes. Additionally, the AIX XCOFF file header includes a 4-byte timestamp. This PR replaces the random substring with a placeholder and nullifies the timestamp field in the XCOFF files for the comparisons.
2 parents 2b97db2 + 7f31b57 commit 2338e57

File tree

1 file changed

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

1 file changed

+44
-3
lines changed

Diff for: tests/run-make/reproducible-build/rmake.rs

+44-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,34 @@ 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().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
124+
}
125+
#[cfg(target_os = "aix")]
126+
{
127+
// The AIX link command includes an additional argument
128+
// that specifies the file containing exported symbols, e.g.,
129+
// -bE:/tmp/rustcO6hxkY/list.exp. In this example, the part of the
130+
// directory name "rustcO6hxkY" is randomly generated to ensure that
131+
// different linking processes do not collide. For the purpose
132+
// of comparing link arguments, the randomly generated part is
133+
// replaced with a placeholder.
134+
let content1 =
135+
std::fs::read_to_string("linker-arguments1").expect("Failed to read file");
136+
let content2 =
137+
std::fs::read_to_string("linker-arguments2").expect("Failed to read file");
138+
139+
// Define the regex for the directory name containing the random substring.
140+
let re = regex::Regex::new(r"rustc[a-zA-Z0-9]{6}/list\.exp").expect("Invalid regex");
141+
142+
// Compare link commands with random strings replaced by placeholders.
143+
assert!(
144+
re.replace_all(&content1, "rustcXXXXXX/list.exp").to_string()
145+
== re.replace_all(&content2, "rustcXXXXXX/list.exp").to_string()
146+
);
147+
}
121148
});
122149
}
123150

@@ -207,7 +234,21 @@ fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
207234
std::env::set_current_dir(&base_dir).unwrap();
208235
match crate_type {
209236
CrateType::Bin => {
210-
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
237+
#[cfg(not(target_os = "aix"))]
238+
{
239+
assert!(
240+
rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo"))
241+
);
242+
}
243+
#[cfg(target_os = "aix")]
244+
{
245+
// At the 4th-byte offset, the AIX XCOFF file header defines a
246+
// 4-byte timestamp. Nullify the timestamp before performing a
247+
// binary comparison.
248+
let mut file1 = rfs::read(bin_name("reproducible-build"));
249+
let mut file2 = rfs::read(bin_name("foo"));
250+
assert!(file1[4..8].fill(0x00) == file2[4..8].fill(0x00));
251+
};
211252
}
212253
CrateType::Rlib => {
213254
assert!(

0 commit comments

Comments
 (0)