mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
feat(trim-paths): set env CARGO_TRIM_PATHS
for build scripts
This commit is contained in:
parent
4aee12c1f8
commit
dd0aea350c
@ -307,6 +307,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
|
||||
cmd.env("CARGO_MANIFEST_LINKS", links);
|
||||
}
|
||||
|
||||
if let Some(trim_paths) = unit.profile.trim_paths.as_ref() {
|
||||
cmd.env("CARGO_TRIM_PATHS", trim_paths.to_string());
|
||||
}
|
||||
|
||||
// Be sure to pass along all enabled features for this package, this is the
|
||||
// last piece of statically known information that we have.
|
||||
for feat in &unit.features {
|
||||
|
@ -327,6 +327,7 @@ impl Profiles {
|
||||
result.root = for_unit_profile.root;
|
||||
result.debuginfo = for_unit_profile.debuginfo;
|
||||
result.opt_level = for_unit_profile.opt_level;
|
||||
result.trim_paths = for_unit_profile.trim_paths.clone();
|
||||
result
|
||||
}
|
||||
|
||||
|
@ -511,3 +511,69 @@ fn object_works() {
|
||||
assert!(memchr::memmem::find(&stdout, registry_src_bytes).is_none());
|
||||
assert!(memchr::memmem::find(&stdout, pkg_root).is_none());
|
||||
}
|
||||
|
||||
// TODO: might want to move to test/testsuite/build_script.rs once stabilized.
|
||||
#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")]
|
||||
fn custom_build_env_var_trim_paths() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.file("build.rs", "")
|
||||
.build();
|
||||
|
||||
let test_cases = [
|
||||
("[]", "none"),
|
||||
("\"all\"", "all"),
|
||||
("\"diagnostics\"", "diagnostics"),
|
||||
("\"macro\"", "macro"),
|
||||
("\"none\"", "none"),
|
||||
("\"object\"", "object"),
|
||||
("false", "none"),
|
||||
("true", "all"),
|
||||
(
|
||||
r#"["diagnostics", "macro", "object"]"#,
|
||||
"diagnostics,macro,object",
|
||||
),
|
||||
];
|
||||
|
||||
for (opts, expected) in test_cases {
|
||||
p.change_file(
|
||||
"Cargo.toml",
|
||||
&format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
||||
[profile.dev]
|
||||
trim-paths = {opts}
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
p.change_file(
|
||||
"build.rs",
|
||||
&format!(
|
||||
r#"
|
||||
fn main() {{
|
||||
assert_eq!(
|
||||
std::env::var("CARGO_TRIM_PATHS").unwrap().as_str(),
|
||||
"{expected}",
|
||||
);
|
||||
}}
|
||||
"#
|
||||
),
|
||||
);
|
||||
|
||||
p.cargo("build -Ztrim-paths")
|
||||
.masquerade_as_nightly_cargo(&["-Ztrim-paths"])
|
||||
.run();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user