Skip to content

Commit

Permalink
metadata: add version to format
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jan 25, 2016
1 parent 16e4d72 commit 874fe26
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
28 changes: 16 additions & 12 deletions src/bin/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ use cargo::util::{CliResult, Config};

#[derive(RustcDecodable)]
struct Options {
flag_color: Option<String>,
flag_features: Vec<String>,
flag_format_version: u32,
flag_manifest_path: Option<String>,
flag_no_default_features: bool,
flag_output_format: String,
flag_output_path: Option<String>,
flag_verbose: bool,
flag_quiet: bool,
flag_color: Option<String>,
flag_verbose: bool,
}

pub const USAGE: &'static str = "
Expand All @@ -29,16 +30,18 @@ Usage:
cargo metadata [options]
Options:
-h, --help Print this message
-o, --output-path PATH Path the output is written to, otherwise stdout is used
-f, --output-format FMT Output format [default: toml]
Valid values: toml, json
--features FEATURES Space-separated list of features
--no-default-features Do not include the `default` feature
--manifest-path PATH Path to the manifest
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
-h, --help Print this message
-o, --output-path PATH Path the output is written to, otherwise stdout is used
-f, --output-format FMT Output format [default: toml]
Valid values: toml, json
--features FEATURES Space-separated list of features
--no-default-features Do not include the `default` feature
--manifest-path PATH Path to the manifest
--format-version VERSION Format version [default: 1]
Valid values: 1
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
Expand All @@ -57,6 +60,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
no_default_features: options.flag_no_default_features,
output_format: options.flag_output_format,
output_to: output_to,
version: options.flag_format_version,
};

try!(output_metadata(options, config));
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use toml;
use util::config::Config;
use util::{paths, CargoResult};

const VERSION: u32 = 1;

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

pub struct OutputMetadataOptions<'a> {
pub features: Vec<String>,
pub output_format: String,
pub output_to: OutputTo,
pub manifest_path: &'a Path,
pub no_default_features: bool,
pub output_format: String,
pub output_to: OutputTo,
pub version: u32,
}

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

assert_eq!(opt.version, VERSION);
let output = ExportInfo {
packages: &packages,
resolve: &resolve,
version: VERSION,
};

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


Expand Down
6 changes: 4 additions & 2 deletions tests/test_cargo_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test!(cargo_metadata_simple {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"));

assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"
assert_that(p.cargo_process("metadata"), execs().with_stdout(r#"version = 1
[[packages]]
dependencies = []
id = "foo 0.5.0 [..]"
Expand Down Expand Up @@ -76,7 +77,8 @@ test!(cargo_metadata_simple_json {
"dependencies" : []
},
"metadata": null
}
},
"version": 1
}"#.split_whitespace().collect::<String>()));
});

Expand Down

0 comments on commit 874fe26

Please sign in to comment.