Skip to content

Commit ddb2180

Browse files
weihangloUrgau
andcommitted
test(trim-path): not remapped in build script gen'd code
This was discovered in <rust-lang/rust#111540 (comment)>. Co-authored-by: Urgau <[email protected]>
1 parent e7d8c62 commit ddb2180

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/testsuite/profile_trim_paths.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,78 @@ fn registry_dependency() {
246246
.run();
247247
}
248248

249+
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
250+
fn registry_dependency_with_build_script_codegen() {
251+
Package::new("bar", "0.0.1")
252+
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
253+
.file(
254+
"build.rs",
255+
r#"
256+
fn main() {
257+
let out_dir = std::env::var("OUT_DIR").unwrap();
258+
let dest = std::path::PathBuf::from(out_dir);
259+
std::fs::write(
260+
dest.join("bindings.rs"),
261+
"pub fn my_file() -> &'static str { file!() }",
262+
)
263+
.unwrap();
264+
}
265+
"#,
266+
)
267+
.file(
268+
"src/lib.rs",
269+
r#"
270+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
271+
"#,
272+
)
273+
.publish();
274+
let p = project()
275+
.file(
276+
"Cargo.toml",
277+
r#"
278+
[package]
279+
name = "foo"
280+
version = "0.0.1"
281+
edition = "2015"
282+
283+
[dependencies]
284+
bar = "0.0.1"
285+
286+
[profile.dev]
287+
trim-paths = "object"
288+
"#,
289+
)
290+
.file(
291+
"src/main.rs",
292+
r#"fn main() { println!("{}", bar::my_file()); }"#,
293+
)
294+
.build();
295+
296+
p.cargo("run --verbose -Ztrim-paths")
297+
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
298+
// Macros should be sanitized
299+
.with_stdout_data(str![[r#"
300+
[ROOT]/foo/target/debug/build/bar-[HASH]/out/bindings.rs
301+
302+
"#]]) // Omit the hash of Source URL
303+
.with_stderr_data(str![[r#"
304+
[UPDATING] `dummy-registry` index
305+
[LOCKING] 1 package to latest compatible version
306+
[DOWNLOADING] crates ...
307+
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
308+
[COMPILING] bar v0.0.1
309+
[RUNNING] `rustc --crate-name build_script_build [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/home/.cargo/registry/src= --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
310+
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
311+
[RUNNING] `rustc --crate-name bar [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/home/.cargo/registry/src= --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
312+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
313+
[RUNNING] `rustc --crate-name foo [..]-Zremap-path-scope=object --remap-path-prefix=[ROOT]/foo=. --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..]`
314+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
315+
[RUNNING] `target/debug/foo`
316+
317+
"#]])
318+
.run();
319+
}
320+
249321
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
250322
fn git_dependency() {
251323
let git_project = git::new("bar", |project| {

0 commit comments

Comments
 (0)