From 3904562fe755cbd9630c99e6968e07ce581bfd6e Mon Sep 17 00:00:00 2001 From: Alex McArther Date: Sun, 4 Mar 2018 22:04:27 -0800 Subject: [PATCH 1/2] Emit resolve.features in "cargo metadata" --- src/cargo/ops/cargo_output_metadata.rs | 2 + tests/testsuite/metadata.rs | 70 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 0e44252547c..8bcf56e9496 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -98,12 +98,14 @@ fn serialize_resolve(resolve: &Resolve, s: S) -> Result struct Node<'a> { id: &'a PackageId, dependencies: Vec<&'a PackageId>, + features: Vec<&'a str>, } resolve.iter().map(|id| { Node { id, dependencies: resolve.deps(id).collect(), + features: resolve.features_sorted(id), } }).collect::>().serialize(s) } diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 5cf01135501..c1a8b87ac80 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -128,6 +128,76 @@ crate-type = ["lib", "staticlib"] }"#)); } +#[test] +fn library_with_features() { + let p = project("foo") + .file("src/lib.rs", "") + .file("Cargo.toml", r#" +[package] +name = "foo" +version = "0.5.0" + +[features] +default = ["default_feat"] +default_feat = [] +optional_feat = [] + "#) + .build(); + + assert_that(p.cargo("metadata"), execs().with_json(r#" + { + "packages": [ + { + "name": "foo", + "version": "0.5.0", + "id": "foo[..]", + "source": null, + "dependencies": [], + "license": null, + "license_file": null, + "description": null, + "targets": [ + { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "foo", + "src_path": "[..][/]foo[/]src[/]lib.rs" + } + ], + "features": { + "default": [ + "default_feat" + ], + "default_feat": [], + "optional_feat": [] + }, + "manifest_path": "[..]Cargo.toml" + } + ], + "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"], + "resolve": { + "nodes": [ + { + "dependencies": [], + "features": [ + "default", + "default_feat" + ], + "id": "foo 0.5.0 (path+file:[..]foo)" + } + ], + "root": "foo 0.5.0 (path+file:[..]foo)" + }, + "target_directory": "[..]foo[/]target", + "version": 1, + "workspace_root": "[..][/]foo" + }"#)); +} + #[test] fn cargo_metadata_with_deps_and_version() { let p = project("foo") From 6a2b6468ca11bf31987956b22eb58f46727fbbfa Mon Sep 17 00:00:00 2001 From: Alex McArther Date: Mon, 5 Mar 2018 06:36:12 -0800 Subject: [PATCH 2/2] Repair the other metadata tests --- tests/testsuite/metadata.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index c1a8b87ac80..c5c11cea23c 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -42,6 +42,7 @@ fn cargo_metadata_simple() { "nodes": [ { "dependencies": [], + "features": [], "id": "foo 0.5.0 (path+file:[..]foo)" } ], @@ -117,6 +118,7 @@ crate-type = ["lib", "staticlib"] "nodes": [ { "dependencies": [], + "features": [], "id": "foo 0.5.0 (path+file:[..]foo)" } ], @@ -330,16 +332,19 @@ fn cargo_metadata_with_deps_and_version() { "dependencies": [ "bar 0.0.1 (registry+[..])" ], + "features": [], "id": "foo 0.5.0 (path+file:[..]foo)" }, { "dependencies": [ "baz 0.0.1 (registry+[..])" ], + "features": [], "id": "bar 0.0.1 (registry+[..])" }, { "dependencies": [], + "features": [], "id": "baz 0.0.1 (registry+[..])" } ], @@ -404,6 +409,7 @@ name = "ex" "nodes": [ { "id": "foo 0.1.0 (path+file:[..]foo)", + "features": [], "dependencies": [] } ] @@ -468,6 +474,7 @@ crate-type = ["rlib", "dylib"] "nodes": [ { "id": "foo 0.1.0 (path+file:[..]foo)", + "features": [], "dependencies": [] } ] @@ -540,10 +547,12 @@ fn workspace_metadata() { "nodes": [ { "dependencies": [], + "features": [], "id": "baz 0.5.0 (path+file:[..]baz)" }, { "dependencies": [], + "features": [], "id": "bar 0.5.0 (path+file:[..]bar)" } ],