Skip to content

Commit 9c6b413

Browse files
committed
massive refactor of reproducible-build test
1 parent 6f554ec commit 9c6b413

File tree

1 file changed

+167
-154
lines changed
  • tests/run-make/reproducible-build

1 file changed

+167
-154
lines changed

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

Lines changed: 167 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
// - Fn Pointer shims
2020
// See https://github.com/rust-lang/rust/pull/32293
2121

22-
// FIXME(Oneirical): ignore-musl
23-
// FIXME(Oneirical): two of these test blocks will apparently fail on windows
24-
// FIXME(Oneirical): try it on test-various
22+
// FIXME(Oneirical): ignore-windows
2523
// # FIXME: Builds of `bin` crate types are not deterministic with debuginfo=2 on
2624
// # Windows.
2725
// # See: https://github.com/rust-lang/rust/pull/87320#issuecomment-920105533
@@ -30,193 +28,208 @@
3028
use run_make_support::{bin_name, cwd, diff, rfs, run_in_tmpdir, rust_lib_name, rustc};
3129

3230
fn main() {
33-
run_in_tmpdir(|| {
34-
rustc().input("linker.rs").opt().run();
35-
rustc().input("reproducible-build-aux.rs").run();
36-
rustc()
37-
.input("reproducible-build.rs")
38-
.linker(&cwd().join(bin_name("linker")).display().to_string())
39-
.run();
40-
rustc()
41-
.input("reproducible-build.rs")
42-
.linker(&cwd().join(bin_name("linker")).display().to_string())
43-
.run();
44-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
45-
});
31+
// Smoke tests. Simple flags, build should be reproducible.
32+
eprintln!("smoke_test => None");
33+
smoke_test(None);
34+
eprintln!("smoke_test => SmokeFlag::Debug");
35+
smoke_test(Some(SmokeFlag::Debug));
36+
eprintln!("smoke_test => SmokeFlag::Opt");
37+
smoke_test(Some(SmokeFlag::Opt));
4638

47-
run_in_tmpdir(|| {
48-
rustc().input("linker.rs").opt().run();
49-
rustc().arg("-g").input("reproducible-build-aux.rs").run();
50-
rustc()
51-
.arg("-g")
52-
.input("reproducible-build.rs")
53-
.linker(&cwd().join(bin_name("linker")).display().to_string())
54-
.run();
55-
rustc()
56-
.arg("-g")
57-
.input("reproducible-build.rs")
58-
.linker(&cwd().join(bin_name("linker")).display().to_string())
59-
.run();
60-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
61-
});
39+
// Builds should be reproducible even through custom library search paths
40+
// or remap path prefixes.
41+
eprintln!("paths_test => PathsFlag::Link");
42+
paths_test(PathsFlag::Link);
43+
eprintln!("paths_test => PathsFlag::Remap");
44+
paths_test(PathsFlag::Remap);
6245

63-
run_in_tmpdir(|| {
64-
rustc().input("linker.rs").opt().run();
65-
rustc().opt().input("reproducible-build-aux.rs").run();
66-
rustc()
67-
.opt()
68-
.input("reproducible-build.rs")
69-
.linker(&cwd().join(bin_name("linker")).display().to_string())
70-
.run();
71-
rustc()
72-
.opt()
73-
.input("reproducible-build.rs")
74-
.linker(&cwd().join(bin_name("linker")).display().to_string())
75-
.run();
76-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
77-
});
46+
// Builds should be reproducible even if each build is done in a different directory,
47+
// with both --remap-path-prefix and -Z remap-cwd-prefix.
7848

79-
run_in_tmpdir(|| {
80-
rustc().input("reproducible-build-aux.rs").run();
81-
rustc().input("reproducible-build.rs").crate_type("rlib").library_search_path("b").run();
82-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
83-
rustc().input("reproducible-build.rs").crate_type("rlib").library_search_path("a").run();
84-
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
85-
});
49+
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
50+
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
51+
// See https://github.com/rust-lang/rust/issues/89911
52+
53+
// This specific case would fail on OSX, should -Cdebuginfo=2 be added.
54+
eprintln!("diff_dir_test => Bin, Path");
55+
diff_dir_test(CrateType::Bin, RemapType::Path);
56+
57+
eprintln!("diff_dir_test => Rlib, Path");
58+
diff_dir_test(CrateType::Rlib, RemapType::Path);
59+
60+
//FIXME(Oneirical): This specific case would fail on both Linux and OSX, should -Cdebuginfo=2
61+
// be added.
62+
// See https://github.com/rust-lang/rust/issues/89911
63+
eprintln!("diff_dir_test => Bin, Cwd false");
64+
diff_dir_test(CrateType::Bin, RemapType::Cwd { is_empty: false });
65+
66+
eprintln!("diff_dir_test => Rlib, Cwd false");
67+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: false });
68+
eprintln!("diff_dir_test => Rlib, Cwd true");
69+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: true });
8670

71+
eprintln!("final extern test");
72+
// Builds should be reproducible when using the --extern flag.
8773
run_in_tmpdir(|| {
8874
rustc().input("reproducible-build-aux.rs").run();
8975
rustc()
9076
.input("reproducible-build.rs")
9177
.crate_type("rlib")
92-
.arg("--remap-path-prefix=/a=/c")
78+
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
9379
.run();
9480
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
81+
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
9582
rustc()
9683
.input("reproducible-build.rs")
9784
.crate_type("rlib")
98-
.arg("--remap-path-prefix=/b=/c")
85+
.extern_("reproducible_build_aux", rust_lib_name("bar"))
9986
.run();
100-
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
87+
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
10188
});
89+
}
10290

91+
#[track_caller]
92+
fn smoke_test(flag: Option<SmokeFlag>) {
10393
run_in_tmpdir(|| {
94+
rustc().input("linker.rs").opt().run();
10495
rustc().input("reproducible-build-aux.rs").run();
105-
rfs::create_dir("test");
106-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
107-
rustc()
96+
let mut compiler1 = rustc();
97+
let mut compiler2 = rustc();
98+
if let Some(flag) = flag {
99+
match flag {
100+
SmokeFlag::Debug => {
101+
compiler1.arg("-g");
102+
compiler2.arg("-g");
103+
}
104+
SmokeFlag::Opt => {
105+
compiler1.opt();
106+
compiler2.opt();
107+
}
108+
};
109+
};
110+
compiler1
108111
.input("reproducible-build.rs")
109-
.crate_type("bin")
110-
.arg(&format!("--remap-path-prefix={}=/b", cwd().display()))
112+
.linker(&cwd().join(bin_name("linker")).display().to_string())
111113
.run();
112-
eprintln!("{:#?}", rfs::shallow_find_dir_entries(cwd()));
113-
rfs::copy(bin_name("reproducible_build"), bin_name("foo"));
114-
rustc()
115-
.input("test/reproducible-build.rs")
116-
.crate_type("bin")
117-
.arg("--remap-path-prefix=/test=/b")
114+
compiler2
115+
.input("reproducible-build.rs")
116+
.linker(&cwd().join(bin_name("linker")).display().to_string())
118117
.run();
119-
assert_eq!(rfs::read(bin_name("reproducible_build")), rfs::read(bin_name("foo")));
118+
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
120119
});
120+
}
121121

122+
#[track_caller]
123+
fn paths_test(flag: PathsFlag) {
122124
run_in_tmpdir(|| {
123125
rustc().input("reproducible-build-aux.rs").run();
124-
rfs::create_dir("test");
125-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
126-
rustc()
127-
.input("reproducible-build.rs")
128-
.crate_type("rlib")
129-
.arg(&format!("--remap-path-prefix={}=/b", cwd().display()))
130-
.run();
131-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
132-
rustc()
133-
.input("test/reproducible-build.rs")
134-
.crate_type("rlib")
135-
.arg("--remap-path-prefix=/test=/b")
136-
.run();
126+
let mut compiler1 = rustc();
127+
let mut compiler2 = rustc();
128+
match flag {
129+
PathsFlag::Link => {
130+
compiler1.library_search_path("a");
131+
compiler2.library_search_path("b");
132+
}
133+
PathsFlag::Remap => {
134+
compiler1.arg("--remap-path-prefix=/a=/c");
135+
compiler2.arg("--remap-path-prefix=/b=/c");
136+
}
137+
}
138+
compiler1.input("reproducible-build.rs").crate_type("rlib").run();
139+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
140+
compiler2.input("reproducible-build.rs").crate_type("rlib").run();
137141
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
138142
});
143+
}
139144

145+
#[track_caller]
146+
fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
140147
run_in_tmpdir(|| {
148+
let base_dir = cwd();
141149
rustc().input("reproducible-build-aux.rs").run();
142150
rfs::create_dir("test");
143151
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
144-
rustc()
152+
let mut compiler1 = rustc();
153+
let mut compiler2 = rustc();
154+
match crate_type {
155+
CrateType::Bin => {
156+
compiler1.crate_type("bin");
157+
compiler2.crate_type("bin");
158+
}
159+
CrateType::Rlib => {
160+
compiler1.crate_type("rlib");
161+
compiler2.crate_type("rlib");
162+
}
163+
}
164+
match remap_type {
165+
RemapType::Path => {
166+
compiler1.arg(&format!("--remap-path-prefix={}=/b", cwd().display()));
167+
compiler2
168+
.arg(format!("--remap-path-prefix={}=/b", base_dir.join("test").display()));
169+
}
170+
RemapType::Cwd { is_empty } => {
171+
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
172+
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
173+
// See https://github.com/rust-lang/rust/issues/89911
174+
if !matches!(crate_type, CrateType::Bin) {
175+
compiler1.arg("-Cdebuginfo=2");
176+
compiler2.arg("-Cdebuginfo=2");
177+
}
178+
if is_empty {
179+
compiler1.arg("-Zremap-cwd-prefix=");
180+
compiler2.arg("-Zremap-cwd-prefix=");
181+
} else {
182+
compiler1.arg("-Zremap-cwd-prefix=.");
183+
compiler2.arg("-Zremap-cwd-prefix=.");
184+
}
185+
}
186+
}
187+
compiler1.input("reproducible-build.rs").run();
188+
match crate_type {
189+
CrateType::Bin => {
190+
rfs::rename(bin_name("reproducible-build"), bin_name("foo"));
191+
}
192+
CrateType::Rlib => {
193+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
194+
}
195+
}
196+
std::env::set_current_dir("test").unwrap();
197+
compiler2
145198
.input("reproducible-build.rs")
146-
.crate_type("bin")
147-
.arg("-Zremap-path-prefix=.")
148-
.arg("-Cdebuginfo=2")
149-
.run();
150-
rfs::copy(bin_name("reproducible_build"), bin_name("first"));
151-
rustc()
152-
.input("test/reproducible-build.rs")
153-
.crate_type("bin")
154-
.arg("-Zremap-path-prefix=.")
155-
.arg("-Cdebuginfo=2")
156-
.run();
157-
assert_eq!(rfs::read(bin_name("first")), rfs::read(bin_name("reproducible_build")));
199+
.library_search_path(&base_dir)
200+
.out_dir(&base_dir)
201+
.run();
202+
std::env::set_current_dir(&base_dir).unwrap();
203+
match crate_type {
204+
CrateType::Bin => {
205+
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
206+
}
207+
CrateType::Rlib => {
208+
assert_eq!(
209+
rfs::read(rust_lib_name("foo")),
210+
rfs::read(rust_lib_name("reproducible_build"))
211+
);
212+
}
213+
}
158214
});
215+
}
159216

160-
run_in_tmpdir(|| {
161-
rustc().input("reproducible-build-aux.rs").run();
162-
rfs::create_dir("test");
163-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
164-
rustc()
165-
.input("reproducible-build.rs")
166-
.crate_type("rlib")
167-
.arg("-Zremap-path-prefix=.")
168-
.arg("-Cdebuginfo=2")
169-
.run();
170-
rfs::copy("reproducible_build", "first");
171-
rustc()
172-
.input("test/reproducible-build.rs")
173-
.crate_type("rlib")
174-
.arg("-Zremap-path-prefix=.")
175-
.arg("-Cdebuginfo=2")
176-
.run();
177-
assert_eq!(
178-
rfs::read(rust_lib_name("first")),
179-
rfs::read(rust_lib_name("reproducible_build"))
180-
);
181-
});
217+
enum SmokeFlag {
218+
Debug,
219+
Opt,
220+
}
182221

183-
run_in_tmpdir(|| {
184-
rustc().input("reproducible-build-aux.rs").run();
185-
rfs::create_dir("test");
186-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
187-
rustc()
188-
.input("reproducible-build.rs")
189-
.crate_type("rlib")
190-
.arg("-Zremap-path-prefix=")
191-
.arg("-Cdebuginfo=2")
192-
.run();
193-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("first"));
194-
rustc()
195-
.input("test/reproducible-build.rs")
196-
.crate_type("rlib")
197-
.arg("-Zremap-path-prefix=")
198-
.arg("-Cdebuginfo=2")
199-
.run();
200-
assert_eq!(
201-
rfs::read(rust_lib_name("first")),
202-
rfs::read(rust_lib_name("reproducible_build"))
203-
);
204-
});
222+
enum PathsFlag {
223+
Link,
224+
Remap,
225+
}
205226

206-
run_in_tmpdir(|| {
207-
rustc().input("reproducible-build-aux.rs").run();
208-
rustc()
209-
.input("reproducible-build.rs")
210-
.crate_type("rlib")
211-
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
212-
.run();
213-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
214-
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
215-
rustc()
216-
.input("reproducible-build.rs")
217-
.crate_type("rlib")
218-
.extern_("reproducible_build_aux", rust_lib_name("bar"))
219-
.run();
220-
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
221-
});
227+
enum CrateType {
228+
Bin,
229+
Rlib,
230+
}
231+
232+
enum RemapType {
233+
Path,
234+
Cwd { is_empty: bool },
222235
}

0 commit comments

Comments
 (0)