From 618701921dedb978f7b0ec524151baa2cae22854 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 1 Nov 2023 22:59:26 -0400 Subject: [PATCH 1/2] test(trim-paths): profile merge doesn't work This demonstrate the buggy behavior that profile merge on `trim-paths` doesn't work as expected. --- tests/testsuite/profile_trim_paths.rs | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index f264253c936..cabca20e7ab 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -165,6 +165,41 @@ fn multiple_options() { .run(); } +#[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] +fn profile_merge_works() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + + [profile.dev] + trim-paths = ["macro"] + + [profile.custom] + inherits = "dev" + trim-paths = ["diagnostics"] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -v -Ztrim-paths --profile custom") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([CWD]) +[RUNNING] `rustc [..]\ + -Zremap-path-scope=macro \ + --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ + --remap-path-prefix=[CWD]= [..] +[FINISHED] custom [..]", + ) + .run(); +} + #[cargo_test(nightly, reason = "-Zremap-path-scope is unstable")] fn registry_dependency() { Package::new("bar", "0.0.1") From 7535971d8b1d6b060796e6fb59d6964b9451adb7 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 1 Nov 2023 22:53:27 -0400 Subject: [PATCH 2/2] fix(trim-paths): merge `trim-paths` from different profiles In 4d29af1 we forgot to add trim-paths to `fn merge()`. This commit follows how `-Zprofile-rustflags` works --- overriding instead of merging array. --- src/cargo/util/toml/mod.rs | 4 ++++ tests/testsuite/profile_trim_paths.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index f6d6c5ea5e1..46f76f42a6e 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -3007,6 +3007,10 @@ impl TomlProfile { if let Some(v) = &profile.strip { self.strip = Some(v.clone()); } + + if let Some(v) = &profile.trim_paths { + self.trim_paths = Some(v.clone()) + } } } diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index cabca20e7ab..1d24c159be7 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -192,7 +192,7 @@ fn profile_merge_works() { "\ [COMPILING] foo v0.0.1 ([CWD]) [RUNNING] `rustc [..]\ - -Zremap-path-scope=macro \ + -Zremap-path-scope=diagnostics \ --remap-path-prefix=[..]/lib/rustlib/src/rust=/rustc/[..] \ --remap-path-prefix=[CWD]= [..] [FINISHED] custom [..]",