Emit resolve.features in "cargo metadata"
authorAlex McArther <acmcarther@gmail.com>
Mon, 5 Mar 2018 06:04:27 +0000 (22:04 -0800)
committerAlex McArther <acmcarther@gmail.com>
Mon, 5 Mar 2018 06:04:27 +0000 (22:04 -0800)
src/cargo/ops/cargo_output_metadata.rs
tests/testsuite/metadata.rs

index 0e44252547c484a4619b4ea189a738705568e9a6..8bcf56e94961ce31863ed1e001fffcf7335406bd 100644 (file)
@@ -98,12 +98,14 @@ fn serialize_resolve<S>(resolve: &Resolve, s: S) -> Result<S::Ok, S::Error>
     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::<Vec<_>>().serialize(s)
 }
index 5cf01135501784b250e7f35b1494859a977c4271..c1a8b87ac8048aa20591e2482bdb952cf3d7a500 100644 (file)
@@ -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")