Skip to content

Commit f14e94a

Browse files
committed
don't repeat metadata section key
1 parent 0895449 commit f14e94a

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,29 @@ pub use runner::{
2929
};
3030
pub use workspace::Workspace;
3131

32-
use crate::cfg_eval::RustcCfgEvaluator;
33-
use crate::cli::cargo_subcommand;
34-
use crate::runner::print_feature_combination_error;
35-
use crate::target::{RustcTargetDetector, TargetDetector};
32+
use cfg_eval::RustcCfgEvaluator;
33+
use cli::cargo_subcommand;
34+
use runner::print_feature_combination_error;
35+
use target::{RustcTargetDetector, TargetDetector};
3636

3737
use color_eyre::eyre;
3838
use std::process;
3939

40+
/// Expands to the metadata key literal `"cargo-feature-combinations"`.
41+
macro_rules! metadata_key {
42+
() => {
43+
"cargo-feature-combinations"
44+
};
45+
}
46+
4047
/// Key used to look up this tool's configuration in Cargo metadata.
41-
pub(crate) const METADATA_KEY: &str = "cargo-feature-combinations";
48+
pub(crate) const METADATA_KEY: &str = metadata_key!();
49+
50+
/// TOML section header for per-package configuration.
51+
pub(crate) const PKG_METADATA_SECTION: &str = concat!("[package.metadata.", metadata_key!(), "]");
52+
53+
/// TOML section header for workspace-level configuration.
54+
pub(crate) const WS_METADATA_SECTION: &str = concat!("[workspace.metadata.", metadata_key!(), "]");
4255

4356
/// Run the cargo subcommand for all relevant feature combinations.
4457
///

src/package.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Package-level configuration, feature combination generation, and error types.
22
3-
use crate::METADATA_KEY;
43
use crate::config::Config;
4+
use crate::{METADATA_KEY, PKG_METADATA_SECTION};
55
use color_eyre::eyre;
66
use itertools::Itertools;
77
use std::collections::{BTreeMap, BTreeSet, HashSet};
@@ -37,13 +37,10 @@ impl fmt::Display for FeatureCombinationError {
3737
} => {
3838
write!(
3939
f,
40-
"too many configurations for package `{}`: {} feature(s) would produce {} combinations (limit: {})",
41-
package,
42-
num_features,
40+
"too many configurations for package `{package}`: {num_features} feature(s) would produce {} combinations (limit: {limit})",
4341
num_configurations
4442
.map(|v| v.to_string())
4543
.unwrap_or_else(|| "an unbounded number of".to_string()),
46-
limit
4744
)
4845
}
4946
}
@@ -93,21 +90,21 @@ impl Package for cargo_metadata::Package {
9390

9491
if !config.deprecated.skip_feature_sets.is_empty() {
9592
eprintln!(
96-
"warning: [package.metadata.cargo-feature-combinations].skip_feature_sets in package `{}` is deprecated; use exclude_feature_sets instead",
93+
"warning: {PKG_METADATA_SECTION}.skip_feature_sets in package `{}` is deprecated; use exclude_feature_sets instead",
9794
self.name,
9895
);
9996
}
10097

10198
if !config.deprecated.denylist.is_empty() {
10299
eprintln!(
103-
"warning: [package.metadata.cargo-feature-combinations].denylist in package `{}` is deprecated; use exclude_features instead",
100+
"warning: {PKG_METADATA_SECTION}.denylist in package `{}` is deprecated; use exclude_features instead",
104101
self.name,
105102
);
106103
}
107104

108105
if !config.deprecated.exact_combinations.is_empty() {
109106
eprintln!(
110-
"warning: [package.metadata.cargo-feature-combinations].exact_combinations in package `{}` is deprecated; use include_feature_sets instead",
107+
"warning: {PKG_METADATA_SECTION}.exact_combinations in package `{}` is deprecated; use include_feature_sets instead",
111108
self.name,
112109
);
113110
}

src/runner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Cargo command execution, output parsing, summary printing, and matrix output.
22
3+
use crate::PKG_METADATA_SECTION;
34
use crate::cfg_eval::RustcCfgEvaluator;
45
use crate::cli::{CargoSubcommand, Options, cargo_subcommand};
56
use crate::package::{FeatureCombinationError, Package};
@@ -133,7 +134,7 @@ pub(crate) fn print_feature_combination_error(err: &FeatureCombinationError) {
133134
let _ = stderr.reset();
134135
let _ = writeln!(
135136
&mut stderr,
136-
" Consider restricting the matrix using [package.metadata.cargo-feature-combinations].only_features"
137+
" Consider restricting the matrix using {PKG_METADATA_SECTION}.only_features",
137138
);
138139
let _ = writeln!(
139140
&mut stderr,

src/workspace.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Workspace-level configuration and package discovery.
22
3-
use crate::METADATA_KEY;
43
use crate::config::{Config, WorkspaceConfig};
54
use crate::package::Package;
5+
use crate::{METADATA_KEY, PKG_METADATA_SECTION, WS_METADATA_SECTION};
66
use color_eyre::eyre;
77

88
/// Abstraction over a Cargo workspace used by this crate.
@@ -47,7 +47,7 @@ impl Workspace for cargo_metadata::Metadata {
4747

4848
if !config.exclude_packages.is_empty() {
4949
eprintln!(
50-
"warning: [package.metadata.cargo-feature-combinations].exclude_packages in the workspace root package is deprecated; use [workspace.metadata.cargo-feature-combinations].exclude_packages instead",
50+
"warning: {PKG_METADATA_SECTION}.exclude_packages in the workspace root package is deprecated; use {WS_METADATA_SECTION}.exclude_packages instead",
5151
);
5252
}
5353

@@ -69,7 +69,7 @@ impl Workspace for cargo_metadata::Metadata {
6969
&& !config.exclude_packages.is_empty()
7070
{
7171
eprintln!(
72-
"warning: [package.metadata.cargo-feature-combinations].exclude_packages in package `{}` has no effect; this field is only read from the workspace root Cargo.toml",
72+
"warning: {PKG_METADATA_SECTION}.exclude_packages in package `{}` has no effect; this field is only read from the workspace root Cargo.toml",
7373
package.name,
7474
);
7575
}
@@ -89,7 +89,7 @@ impl Workspace for cargo_metadata::Metadata {
8989

9090
if has_values {
9191
eprintln!(
92-
"warning: [workspace.metadata.cargo-feature-combinations].exclude_packages in package `{}` has no effect; workspace metadata is only read from the workspace root Cargo.toml",
92+
"warning: {WS_METADATA_SECTION}.exclude_packages in package `{}` has no effect; workspace metadata is only read from the workspace root Cargo.toml",
9393
package.name,
9494
);
9595
}

0 commit comments

Comments
 (0)