Skip to content

Commit 3532cf7

Browse files
committed
Auto merge of #8013 - ehuss:beta-config-profile-fix, r=alexcrichton
Beta: Fix config profiles using "dev" in `cargo test`. Backport of #8012 (so the new feature doesn't launch with this bug).
2 parents 7b1e9f5 + a8fe057 commit 3532cf7

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/cargo/core/profiles.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -999,27 +999,33 @@ fn merge_config_profiles(
999999
Some(profiles) => profiles.get_all().clone(),
10001000
None => BTreeMap::new(),
10011001
};
1002-
// List of profile names to check if defined in config only.
1003-
let mut check_to_add = vec![requested_profile];
1002+
// Set of profile names to check if defined in config only.
1003+
let mut check_to_add = HashSet::new();
1004+
check_to_add.insert(requested_profile);
10041005
// Merge config onto manifest profiles.
10051006
for (name, profile) in &mut profiles {
10061007
if let Some(config_profile) = get_config_profile(name, config, features)? {
10071008
profile.merge(&config_profile);
10081009
}
10091010
if let Some(inherits) = &profile.inherits {
1010-
check_to_add.push(*inherits);
1011+
check_to_add.insert(*inherits);
10111012
}
10121013
}
1014+
// Add the built-in profiles. This is important for things like `cargo
1015+
// test` which implicitly use the "dev" profile for dependencies.
1016+
for name in &["dev", "release", "test", "bench"] {
1017+
check_to_add.insert(InternedString::new(name));
1018+
}
10131019
// Add config-only profiles.
10141020
// Need to iterate repeatedly to get all the inherits values.
1015-
let mut current = Vec::new();
1021+
let mut current = HashSet::new();
10161022
while !check_to_add.is_empty() {
10171023
std::mem::swap(&mut current, &mut check_to_add);
1018-
for name in current.drain(..) {
1024+
for name in current.drain() {
10191025
if !profiles.contains_key(&name) {
10201026
if let Some(config_profile) = get_config_profile(&name, config, features)? {
10211027
if let Some(inherits) = &config_profile.inherits {
1022-
check_to_add.push(*inherits);
1028+
check_to_add.insert(*inherits);
10231029
}
10241030
profiles.insert(name, config_profile);
10251031
}

tests/testsuite/profile_config.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for profiles defined in config files.
22
33
use cargo_test_support::paths::CargoPathExt;
4+
use cargo_test_support::registry::Package;
45
use cargo_test_support::{basic_lib_manifest, paths, project};
56

67
#[cargo_test]
@@ -454,3 +455,38 @@ fn named_env_profile() {
454455
.with_stderr_contains("[..]-C codegen-units=1 [..]")
455456
.run();
456457
}
458+
459+
#[cargo_test]
460+
fn test_with_dev_profile() {
461+
// `cargo test` uses "dev" profile for dependencies.
462+
Package::new("somedep", "1.0.0").publish();
463+
let p = project()
464+
.file(
465+
"Cargo.toml",
466+
r#"
467+
[package]
468+
name = "foo"
469+
version = "0.1.0"
470+
471+
[dependencies]
472+
somedep = "1.0"
473+
"#,
474+
)
475+
.file("src/lib.rs", "")
476+
.build();
477+
p.cargo("test --lib --no-run -v")
478+
.env("CARGO_PROFILE_DEV_DEBUG", "0")
479+
.with_stderr(
480+
"\
481+
[UPDATING] [..]
482+
[DOWNLOADING] [..]
483+
[DOWNLOADED] [..]
484+
[COMPILING] somedep v1.0.0
485+
[RUNNING] `rustc --crate-name somedep [..]-C debuginfo=0[..]
486+
[COMPILING] foo v0.1.0 [..]
487+
[RUNNING] `rustc --crate-name foo [..]-C debuginfo=2[..]
488+
[FINISHED] [..]
489+
",
490+
)
491+
.run();
492+
}

0 commit comments

Comments
 (0)