Skip to content

Commit b16514d

Browse files
committed
refactor(manifest): Fully qualify manifest env vars
This simplifies the macro and makes the content searchable
1 parent fbca21b commit b16514d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/cargo/core/manifest.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,21 @@ macro_rules! metadata_envs {
172172

173173
pub fn should_track(key: &str) -> bool {
174174
let keys = [$($key),*];
175-
key.strip_prefix("CARGO_PKG_")
176-
.map(|key| keys.iter().any(|k| *k == key))
177-
.unwrap_or_default()
175+
keys.iter().any(|k| *k == key)
178176
}
179177

180178
pub fn var<'a>(meta: &'a ManifestMetadata, key: &str) -> Option<Cow<'a, str>> {
181-
key.strip_prefix("CARGO_PKG_").and_then(|key| match key {
179+
match key {
182180
$($key => Some(Self::$field(meta)),)*
183181
_ => None,
184-
})
182+
}
185183
}
186184

187185
pub fn vars(meta: &ManifestMetadata) -> impl Iterator<Item = (&'static str, Cow<'_, str>)> {
188186
[
189187
$(
190188
(
191-
concat!("CARGO_PKG_", $key),
189+
$key,
192190
Self::$field(meta),
193191
),
194192
)*
@@ -202,14 +200,14 @@ macro_rules! metadata_envs {
202200
// If these change we need to trigger a rebuild.
203201
// NOTE: The env var name will be prefixed with `CARGO_PKG_`
204202
metadata_envs! {
205-
(description, "DESCRIPTION"),
206-
(homepage, "HOMEPAGE"),
207-
(repository, "REPOSITORY"),
208-
(license, "LICENSE"),
209-
(license_file, "LICENSE_FILE"),
210-
(authors, "AUTHORS", |m: &ManifestMetadata| m.authors.join(":")),
211-
(rust_version, "RUST_VERSION", |m: &ManifestMetadata| m.rust_version.as_ref().map(ToString::to_string).unwrap_or_default()),
212-
(readme, "README"),
203+
(description, "CARGO_PKG_DESCRIPTION"),
204+
(homepage, "CARGO_PKG_HOMEPAGE"),
205+
(repository, "CARGO_PKG_REPOSITORY"),
206+
(license, "CARGO_PKG_LICENSE"),
207+
(license_file, "CARGO_PKG_LICENSE_FILE"),
208+
(authors, "CARGO_PKG_AUTHORS", |m: &ManifestMetadata| m.authors.join(":")),
209+
(rust_version, "CARGO_PKG_RUST_VERSION", |m: &ManifestMetadata| m.rust_version.as_ref().map(ToString::to_string).unwrap_or_default()),
210+
(readme, "CARGO_PKG_README"),
213211
}
214212

215213
impl ManifestMetadata {

0 commit comments

Comments
 (0)