Skip to content

Commit 83a955b

Browse files
authoredJun 12, 2016
Auto merge of #2668 - alexcrichton:dont-warn-about-metadata, r=brson
Don't warn about `metadata` keys in the manifest External tools may want to store metadata in `Cargo.toml` that they read but Cargo itself doesn't read. For example `cargo-apk` uses this for pieces of configuration. Cargo unfortunately, however, warns about these keys as "unused keys in the manifest" This commit instead whitelists the `package.metadata` key to not warn about any data inside.
2 parents ffa147d + ebd630d commit 83a955b

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 

‎src/cargo/util/toml.rs

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ pub fn to_manifest(contents: &[u8],
134134
return Ok((manifest, paths));
135135

136136
fn add_unused_keys(m: &mut Manifest, toml: &toml::Value, key: String) {
137+
if key == "package.metadata" {
138+
return
139+
}
137140
match *toml {
138141
toml::Value::Table(ref table) => {
139142
for (k, v) in table.iter() {

‎src/doc/manifest.md

+19
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ provide useful information to users of the registry and also influence the
126126
search ranking of a crate. It is highly discouraged to omit everything in a
127127
published crate.
128128

129+
## The `metadata` Table (optional)
130+
131+
Cargo by default will warn about unused keys in `Cargo.toml` to assist in
132+
detecting typos and such. The `package.metadata` table, however, is completely
133+
ignored by Cargo and will not be warned about. This section can be used for
134+
tools which would like to store project configuration in `Cargo.toml`. For
135+
example:
136+
137+
```toml
138+
[package]
139+
name = "..."
140+
# ...
141+
142+
# Metadata used when generating an Android APK, for example.
143+
[package.metadata.android]
144+
package-name = "my-awesome-android-app"
145+
assets = "path/to/static"
146+
```
147+
129148
# Dependency Sections
130149

131150
See the [specifying dependencies page](specifying-dependencies.html) for

‎tests/build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -2240,3 +2240,26 @@ fn explicit_color_config_is_propagated_to_rustc() {
22402240
-L dependency=[..]target[..]debug[..]deps`
22412241
"));
22422242
}
2243+
2244+
#[test]
2245+
fn no_warn_about_package_metadata() {
2246+
let p = project("foo")
2247+
.file("Cargo.toml", r#"
2248+
[package]
2249+
name = "foo"
2250+
version = "0.0.1"
2251+
authors = []
2252+
2253+
[package.metadata]
2254+
foo = "bar"
2255+
a = true
2256+
b = 3
2257+
2258+
[package.metadata.another]
2259+
bar = 3
2260+
"#)
2261+
.file("src/lib.rs", "");
2262+
assert_that(p.cargo_process("build"),
2263+
execs().with_status(0)
2264+
.with_stderr("[..] foo v0.0.1 ([..])\n"));
2265+
}

0 commit comments

Comments
 (0)
Please sign in to comment.