forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#2196 - matklad:metadata2, r=alexcrichton
Most of the work was done by @dan-t in rust-lang#1225 and by @winger in rust-lang#1434 Fixes rust-lang#2193 I failed to properly rebase previous attempts so I just salvaged this from bits and pieces. @alexcrichton are you sure that the default format should be TOML? I think that TOML is more suitable for humans, and JSON is better (at the moment at least) for tools. Maybe we should default to ~~TOML~~ JSON?
- Loading branch information
Showing
7 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
extern crate cargo; | ||
extern crate docopt; | ||
extern crate rustc_serialize; | ||
extern crate toml; | ||
|
||
use cargo::ops::{output_metadata, OutputMetadataOptions, ExportInfo}; | ||
use cargo::util::important_paths::find_root_manifest_for_wd; | ||
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_quiet: bool, | ||
flag_verbose: bool, | ||
} | ||
|
||
pub const USAGE: &'static str = " | ||
Output the resolved dependencies of a project, the concrete used versions | ||
including overrides, in machine-readable format. | ||
Usage: | ||
cargo metadata [options] | ||
Options: | ||
-h, --help Print this message | ||
--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<ExportInfo>> { | ||
try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet)); | ||
try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..]))); | ||
let manifest = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); | ||
|
||
let options = OutputMetadataOptions { | ||
features: options.flag_features, | ||
manifest_path: &manifest, | ||
no_default_features: options.flag_no_default_features, | ||
version: options.flag_format_version, | ||
}; | ||
|
||
let result = try!(output_metadata(options, config)); | ||
Ok(Some(result)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::path::Path; | ||
|
||
use core::resolver::Resolve; | ||
use core::{Source, Package}; | ||
use ops; | ||
use sources::PathSource; | ||
use util::config::Config; | ||
use util::CargoResult; | ||
|
||
const VERSION: u32 = 1; | ||
|
||
pub struct OutputMetadataOptions<'a> { | ||
pub features: Vec<String>, | ||
pub manifest_path: &'a Path, | ||
pub no_default_features: bool, | ||
pub version: u32, | ||
} | ||
|
||
/// Loads the manifest, resolves the dependencies of the project to the concrete | ||
/// used versions - considering overrides - and writes all dependencies in a JSON | ||
/// format to stdout. | ||
pub fn output_metadata<'a>(opt: OutputMetadataOptions, | ||
config: &'a Config) | ||
-> CargoResult<ExportInfo> { | ||
let deps = try!(resolve_dependencies(opt.manifest_path, | ||
config, | ||
opt.features, | ||
opt.no_default_features)); | ||
let (packages, resolve) = deps; | ||
|
||
assert_eq!(opt.version, VERSION); | ||
Ok(ExportInfo { | ||
packages: packages, | ||
resolve: resolve, | ||
version: VERSION, | ||
}) | ||
} | ||
|
||
#[derive(RustcEncodable)] | ||
pub struct ExportInfo { | ||
packages: Vec<Package>, | ||
resolve: Resolve, | ||
version: u32, | ||
} | ||
|
||
|
||
/// Loads the manifest and resolves the dependencies of the project to the | ||
/// concrete used versions. Afterwards available overrides of dependencies are applied. | ||
fn resolve_dependencies(manifest: &Path, | ||
config: &Config, | ||
features: Vec<String>, | ||
no_default_features: bool) | ||
-> CargoResult<(Vec<Package>, Resolve)> { | ||
let mut source = try!(PathSource::for_path(manifest.parent().unwrap(), config)); | ||
try!(source.update()); | ||
|
||
let package = try!(source.root_package()); | ||
|
||
let deps = try!(ops::resolve_dependencies(&package, | ||
config, | ||
Some(Box::new(source)), | ||
features, | ||
no_default_features)); | ||
|
||
let (packages, resolve_with_overrides, _) = deps; | ||
|
||
Ok((packages, resolve_with_overrides)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.