Skip to content

Commit 874fe26

Browse files
committed
metadata: add version to format
1 parent 16e4d72 commit 874fe26

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/bin/metadata.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ use cargo::util::{CliResult, Config};
1111

1212
#[derive(RustcDecodable)]
1313
struct Options {
14+
flag_color: Option<String>,
1415
flag_features: Vec<String>,
16+
flag_format_version: u32,
1517
flag_manifest_path: Option<String>,
1618
flag_no_default_features: bool,
1719
flag_output_format: String,
1820
flag_output_path: Option<String>,
19-
flag_verbose: bool,
2021
flag_quiet: bool,
21-
flag_color: Option<String>,
22+
flag_verbose: bool,
2223
}
2324

2425
pub const USAGE: &'static str = "
@@ -29,16 +30,18 @@ Usage:
2930
cargo metadata [options]
3031
3132
Options:
32-
-h, --help Print this message
33-
-o, --output-path PATH Path the output is written to, otherwise stdout is used
34-
-f, --output-format FMT Output format [default: toml]
35-
Valid values: toml, json
36-
--features FEATURES Space-separated list of features
37-
--no-default-features Do not include the `default` feature
38-
--manifest-path PATH Path to the manifest
39-
-v, --verbose Use verbose output
40-
-q, --quiet No output printed to stdout
41-
--color WHEN Coloring: auto, always, never
33+
-h, --help Print this message
34+
-o, --output-path PATH Path the output is written to, otherwise stdout is used
35+
-f, --output-format FMT Output format [default: toml]
36+
Valid values: toml, json
37+
--features FEATURES Space-separated list of features
38+
--no-default-features Do not include the `default` feature
39+
--manifest-path PATH Path to the manifest
40+
--format-version VERSION Format version [default: 1]
41+
Valid values: 1
42+
-v, --verbose Use verbose output
43+
-q, --quiet No output printed to stdout
44+
--color WHEN Coloring: auto, always, never
4245
";
4346

4447
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
@@ -57,6 +60,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
5760
no_default_features: options.flag_no_default_features,
5861
output_format: options.flag_output_format,
5962
output_to: output_to,
63+
version: options.flag_format_version,
6064
};
6165

6266
try!(output_metadata(options, config));

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use toml;
1010
use util::config::Config;
1111
use util::{paths, CargoResult};
1212

13+
const VERSION: u32 = 1;
1314

1415
/// Where the dependencies should be written to.
1516
pub enum OutputTo {
@@ -19,10 +20,11 @@ pub enum OutputTo {
1920

2021
pub struct OutputMetadataOptions<'a> {
2122
pub features: Vec<String>,
22-
pub output_format: String,
23-
pub output_to: OutputTo,
2423
pub manifest_path: &'a Path,
2524
pub no_default_features: bool,
25+
pub output_format: String,
26+
pub output_to: OutputTo,
27+
pub version: u32,
2628
}
2729

2830
/// Loads the manifest, resolves the dependencies of the project to the concrete
@@ -54,9 +56,11 @@ pub fn output_metadata(opt: OutputMetadataOptions, config: &Config) -> CargoResu
5456
opt.no_default_features));
5557
let (packages, resolve) = deps;
5658

59+
assert_eq!(opt.version, VERSION);
5760
let output = ExportInfo {
5861
packages: &packages,
5962
resolve: &resolve,
63+
version: VERSION,
6064
};
6165

6266
let serialized_str = match &opt.output_format.to_ascii_uppercase()[..] {
@@ -78,6 +82,7 @@ pub fn output_metadata(opt: OutputMetadataOptions, config: &Config) -> CargoResu
7882
struct ExportInfo<'a> {
7983
packages: &'a [Package],
8084
resolve: &'a Resolve,
85+
version: u32,
8186
}
8287

8388

tests/test_cargo_metadata.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test!(cargo_metadata_simple {
1414
let p = project("foo")
1515
.file("Cargo.toml", &basic_bin_manifest("foo"));
1616

17-
assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"
17+
assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"version = 1
18+
1819
[[packages]]
1920
dependencies = []
2021
id = "foo 0.5.0 [..]"
@@ -76,7 +77,8 @@ test!(cargo_metadata_simple_json {
7677
"dependencies" : []
7778
},
7879
"metadata": null
79-
}
80+
},
81+
"version": 1
8082
}"#.split_whitespace().collect::<String>()));
8183
});
8284

0 commit comments

Comments
 (0)