Skip to content

Commit 1e764db

Browse files
committed
Auto merge of #7504 - ehuss:rename-package-overrides, r=alexcrichton
Rename `overrides` to `package` in profiles. Renaming per the discussion at rust-lang/rust#48683 (comment). I left backwards-compatibility in case anyone is using it, since it required very little effort. cc @da-x, FYI.
2 parents 78ba630 + fcfe0b8 commit 1e764db

File tree

7 files changed

+128
-66
lines changed

7 files changed

+128
-66
lines changed

src/cargo/core/profiles.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@ impl Profiles {
433433
}
434434
}
435435

436-
/// An object used for handling the profile override hierarchy.
436+
/// An object used for handling the profile hierarchy.
437437
///
438438
/// The precedence of profiles are (first one wins):
439439
/// - Profiles in `.cargo/config` files (using same order as below).
440-
/// - [profile.dev.overrides.name] -- a named package.
441-
/// - [profile.dev.overrides."*"] -- this cannot apply to workspace members.
440+
/// - [profile.dev.package.name] -- a named package.
441+
/// - [profile.dev.package."*"] -- this cannot apply to workspace members.
442442
/// - [profile.dev.build-override] -- this can only apply to `build.rs` scripts
443443
/// and their dependencies.
444444
/// - [profile.dev]
@@ -511,8 +511,8 @@ impl ProfileMaker {
511511
Some(ref toml) => toml,
512512
None => return Ok(()),
513513
};
514-
let overrides = match toml.overrides {
515-
Some(ref overrides) => overrides,
514+
let overrides = match toml.package.as_ref().or(toml.overrides.as_ref()) {
515+
Some(overrides) => overrides,
516516
None => return Ok(()),
517517
};
518518
// Verify that a package doesn't match multiple spec overrides.
@@ -543,8 +543,8 @@ impl ProfileMaker {
543543
.collect::<Vec<_>>()
544544
.join(", ");
545545
failure::bail!(
546-
"multiple profile overrides in profile `{}` match package `{}`\n\
547-
found profile override specs: {}",
546+
"multiple package overrides in profile `{}` match package `{}`\n\
547+
found package specs: {}",
548548
self.default.name,
549549
pkg_id,
550550
specs
@@ -581,12 +581,12 @@ impl ProfileMaker {
581581
let suggestion =
582582
closest_msg(&spec.name(), packages.package_ids(), |p| p.name().as_str());
583583
shell.warn(format!(
584-
"profile override spec `{}` did not match any packages{}",
584+
"package profile spec `{}` did not match any packages{}",
585585
spec, suggestion
586586
))?;
587587
} else {
588588
shell.warn(format!(
589-
"version or URL in profile override spec `{}` does not \
589+
"version or URL in package profile spec `{}` does not \
590590
match any of the packages: {}",
591591
spec,
592592
name_matches.join(", ")
@@ -609,7 +609,7 @@ fn merge_toml_overrides(
609609
merge_profile(profile, build_override);
610610
}
611611
}
612-
if let Some(ref overrides) = toml.overrides {
612+
if let Some(overrides) = toml.package.as_ref().or(toml.overrides.as_ref()) {
613613
if !is_member {
614614
if let Some(all) = overrides.get(&ProfilePackageSpec::All) {
615615
merge_profile(profile, all);
@@ -634,7 +634,7 @@ fn merge_toml_overrides(
634634
// no additional matches.
635635
assert!(
636636
matches.next().is_none(),
637-
"package `{}` matched multiple profile overrides",
637+
"package `{}` matched multiple package profile overrides",
638638
pkg_id
639639
);
640640
}

src/cargo/util/toml/mod.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ pub struct TomlProfile {
408408
pub panic: Option<String>,
409409
pub overflow_checks: Option<bool>,
410410
pub incremental: Option<bool>,
411+
// `overrides` has been renamed to `package`, this should be removed when
412+
// stabilized.
411413
pub overrides: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
414+
pub package: Option<BTreeMap<ProfilePackageSpec, TomlProfile>>,
412415
pub build_override: Option<Box<TomlProfile>>,
413416
pub dir_name: Option<String>,
414417
pub inherits: Option<String>,
@@ -457,12 +460,23 @@ impl TomlProfile {
457460
) -> CargoResult<()> {
458461
if let Some(ref profile) = self.build_override {
459462
features.require(Feature::profile_overrides())?;
460-
profile.validate_override()?;
463+
profile.validate_override("build-override")?;
461464
}
462465
if let Some(ref override_map) = self.overrides {
466+
warnings.push(
467+
"profile key `overrides` has been renamed to `package`, \
468+
please update the manifest to the new key name"
469+
.to_string(),
470+
);
463471
features.require(Feature::profile_overrides())?;
464472
for profile in override_map.values() {
465-
profile.validate_override()?;
473+
profile.validate_override("package")?;
474+
}
475+
}
476+
if let Some(ref packages) = self.package {
477+
features.require(Feature::profile_overrides())?;
478+
for profile in packages.values() {
479+
profile.validate_override("package")?;
466480
}
467481
}
468482

@@ -555,18 +569,21 @@ impl TomlProfile {
555569
Ok(())
556570
}
557571

558-
fn validate_override(&self) -> CargoResult<()> {
559-
if self.overrides.is_some() || self.build_override.is_some() {
560-
bail!("Profile overrides cannot be nested.");
572+
fn validate_override(&self, which: &str) -> CargoResult<()> {
573+
if self.overrides.is_some() || self.package.is_some() {
574+
bail!("package-specific profiles cannot be nested");
575+
}
576+
if self.build_override.is_some() {
577+
bail!("build-override profiles cannot be nested");
561578
}
562579
if self.panic.is_some() {
563-
bail!("`panic` may not be specified in a profile override.")
580+
bail!("`panic` may not be specified in a `{}` profile", which)
564581
}
565582
if self.lto.is_some() {
566-
bail!("`lto` may not be specified in a profile override.")
583+
bail!("`lto` may not be specified in a `{}` profile", which)
567584
}
568585
if self.rpath.is_some() {
569-
bail!("`rpath` may not be specified in a profile override.")
586+
bail!("`rpath` may not be specified in a `{}` profile", which)
570587
}
571588
Ok(())
572589
}
@@ -612,6 +629,10 @@ impl TomlProfile {
612629
self.overrides = Some(v.clone());
613630
}
614631

632+
if let Some(v) = &profile.package {
633+
self.package = Some(v.clone());
634+
}
635+
615636
if let Some(v) = &profile.build_override {
616637
self.build_override = Some(v.clone());
617638
}

src/doc/src/reference/unstable.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ opt-level = 0
104104
debug = true
105105

106106
# the `image` crate will be compiled with -Copt-level=3
107-
[profile.dev.overrides.image]
107+
[profile.dev.package.image]
108108
opt-level = 3
109109

110110
# All dependencies (but not this crate itself or any workspace member)
111111
# will be compiled with -Copt-level=2 . This includes build dependencies.
112-
[profile.dev.overrides."*"]
112+
[profile.dev.package."*"]
113113
opt-level = 2
114114

115115
# Build scripts or proc-macros and their dependencies will be compiled with

tests/testsuite/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ incremental = true
302302
[profile.dev.build-override]
303303
opt-level = 1
304304
305-
[profile.dev.overrides.bar]
305+
[profile.dev.package.bar]
306306
codegen-units = 9
307307
308308
[profile.no-lto]
@@ -315,26 +315,26 @@ lto = false
315315
let config = new_config(&[
316316
("CARGO_PROFILE_DEV_CODEGEN_UNITS", "5"),
317317
("CARGO_PROFILE_DEV_BUILD_OVERRIDE_CODEGEN_UNITS", "11"),
318-
("CARGO_PROFILE_DEV_OVERRIDES_env_CODEGEN_UNITS", "13"),
319-
("CARGO_PROFILE_DEV_OVERRIDES_bar_OPT_LEVEL", "2"),
318+
("CARGO_PROFILE_DEV_PACKAGE_env_CODEGEN_UNITS", "13"),
319+
("CARGO_PROFILE_DEV_PACKAGE_bar_OPT_LEVEL", "2"),
320320
]);
321321

322322
// TODO: don't use actual `tomlprofile`.
323323
let p: toml::TomlProfile = config.get("profile.dev").unwrap();
324-
let mut overrides = collections::BTreeMap::new();
324+
let mut packages = collections::BTreeMap::new();
325325
let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("bar").unwrap());
326326
let o_profile = toml::TomlProfile {
327327
opt_level: Some(toml::TomlOptLevel("2".to_string())),
328328
codegen_units: Some(9),
329329
..Default::default()
330330
};
331-
overrides.insert(key, o_profile);
331+
packages.insert(key, o_profile);
332332
let key = toml::ProfilePackageSpec::Spec(::cargo::core::PackageIdSpec::parse("env").unwrap());
333333
let o_profile = toml::TomlProfile {
334334
codegen_units: Some(13),
335335
..Default::default()
336336
};
337-
overrides.insert(key, o_profile);
337+
packages.insert(key, o_profile);
338338

339339
assert_eq!(
340340
p,
@@ -348,7 +348,7 @@ lto = false
348348
panic: Some("abort".to_string()),
349349
overflow_checks: Some(true),
350350
incremental: Some(true),
351-
overrides: Some(overrides),
351+
package: Some(packages),
352352
build_override: Some(Box::new(toml::TomlProfile {
353353
opt_level: Some(toml::TomlOptLevel("1".to_string())),
354354
codegen_units: Some(11),

tests/testsuite/profile_config.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn profile_config_validate_warnings() {
5353
[profile.dev.build-override]
5454
bad-key-bo = true
5555
56-
[profile.dev.overrides.bar]
56+
[profile.dev.package.bar]
5757
bad-key-bar = true
5858
"#,
5959
)
@@ -66,7 +66,7 @@ fn profile_config_validate_warnings() {
6666
[WARNING] unused key `profile.asdf` in config file `[..].cargo/config`
6767
[WARNING] unused key `profile.test` in config file `[..].cargo/config`
6868
[WARNING] unused key `profile.dev.bad-key` in config file `[..].cargo/config`
69-
[WARNING] unused key `profile.dev.overrides.bar.bad-key-bar` in config file `[..].cargo/config`
69+
[WARNING] unused key `profile.dev.package.bar.bad-key-bar` in config file `[..].cargo/config`
7070
[WARNING] unused key `profile.dev.build-override.bad-key-bo` in config file `[..].cargo/config`
7171
[COMPILING] foo [..]
7272
[FINISHED] [..]
@@ -127,7 +127,7 @@ fn profile_config_validate_errors() {
127127
.file(
128128
".cargo/config",
129129
r#"
130-
[profile.dev.overrides.foo]
130+
[profile.dev.package.foo]
131131
panic = "abort"
132132
"#,
133133
)
@@ -141,7 +141,7 @@ fn profile_config_validate_errors() {
141141
[ERROR] config profile `profile.dev` is not valid
142142
143143
Caused by:
144-
`panic` may not be specified in a profile override.
144+
`panic` may not be specified in a `package` profile
145145
",
146146
)
147147
.run();
@@ -194,10 +194,10 @@ fn profile_config_override_spec_multiple() {
194194
.file(
195195
".cargo/config",
196196
r#"
197-
[profile.dev.overrides.bar]
197+
[profile.dev.package.bar]
198198
opt-level = 3
199199
200-
[profile.dev.overrides."bar:0.5.0"]
200+
[profile.dev.package."bar:0.5.0"]
201201
opt-level = 3
202202
"#,
203203
)
@@ -222,8 +222,8 @@ fn profile_config_override_spec_multiple() {
222222
.with_status(101)
223223
.with_stderr(
224224
"\
225-
[ERROR] multiple profile overrides in profile `dev` match package `bar v0.5.0 ([..])`
226-
found profile override specs: bar, bar:0.5.0",
225+
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
226+
found package specs: bar, bar:0.5.0",
227227
)
228228
.run();
229229
}
@@ -291,7 +291,7 @@ fn profile_config_override_precedence() {
291291
[profile.dev]
292292
codegen-units = 2
293293
294-
[profile.dev.overrides.bar]
294+
[profile.dev.package.bar]
295295
opt-level = 3
296296
"#,
297297
)
@@ -310,7 +310,7 @@ fn profile_config_override_precedence() {
310310
.file(
311311
".cargo/config",
312312
r#"
313-
[profile.dev.overrides.bar]
313+
[profile.dev.package.bar]
314314
opt-level = 2
315315
"#,
316316
)
@@ -346,7 +346,7 @@ fn profile_config_no_warn_unknown_override() {
346346
.file(
347347
".cargo/config",
348348
r#"
349-
[profile.dev.overrides.bar]
349+
[profile.dev.package.bar]
350350
codegen-units = 4
351351
"#,
352352
)

tests/testsuite/profile_custom.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@ fn overrides_with_custom() {
296296
[profile.dev]
297297
codegen-units = 7
298298
299-
[profile.dev.overrides.xxx]
299+
[profile.dev.package.xxx]
300300
codegen-units = 5
301-
[profile.dev.overrides.yyy]
301+
[profile.dev.package.yyy]
302302
codegen-units = 3
303303
304304
[profile.other]
305305
inherits = "dev"
306306
codegen-units = 2
307307
308-
[profile.other.overrides.yyy]
308+
[profile.other.package.yyy]
309309
codegen-units = 6
310310
"#,
311311
)

0 commit comments

Comments
 (0)