Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encourage tools writers to explicitly pin metadata version #3841

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/bin/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Options {
flag_color: Option<String>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_format_version: u32,
flag_format_version: Option<u32>,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_no_deps: bool,
Expand All @@ -34,7 +34,7 @@ Options:
--no-deps Output information only about the root package
and don't fetch dependencies.
--manifest-path PATH Path to the manifest
--format-version VERSION Format version [default: 1]
--format-version VERSION Format version
Valid values: 1
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
Expand All @@ -51,12 +51,17 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
options.flag_locked)?;
let manifest = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;

if options.flag_format_version.is_none() {
config.shell().warn("please specify `--format-version` flag explicitly to \
avoid compatibility problems")?
}

let options = OutputMetadataOptions {
features: options.flag_features,
all_features: options.flag_all_features,
no_default_features: options.flag_no_default_features,
no_deps: options.flag_no_deps,
version: options.flag_format_version,
version: options.flag_format_version.unwrap_or(1),
};

let ws = Workspace::new(&manifest, config)?;
Expand Down
19 changes: 17 additions & 2 deletions tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ fn cargo_metadata_simple() {
}"#));
}

#[test]
fn cargo_metadata_warns_on_implicit_version() {
let p = project("foo")
.file("src/foo.rs", "")
.file("Cargo.toml", &basic_bin_manifest("foo"));
p.build();

assert_that(p.cargo("metadata"),
execs().with_stderr("\
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems"));

assert_that(p.cargo("metadata").arg("--format-version").arg("1"),
execs().with_stderr(""));
}

#[test]
fn library_with_several_crate_types() {
let p = project("foo")
Expand Down Expand Up @@ -520,8 +535,8 @@ fn cargo_metadata_with_invalid_manifest() {
let p = project("foo")
.file("Cargo.toml", "");

assert_that(p.cargo_process("metadata"), execs().with_status(101)
.with_stderr("\
assert_that(p.cargo_process("metadata").arg("--format-version").arg("1"),
execs().with_status(101).with_stderr("\
[ERROR] failed to parse manifest at `[..]`

Caused by:
Expand Down