From 17b129afca47f01d1325b797fd8c5ed739c9a7ec Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 17 Dec 2020 13:26:10 -0800 Subject: [PATCH 1/4] Supply manifest path for path dependencies Fixes #7483. --- src/cargo/core/dependency.rs | 6 ++++++ src/cargo/core/source/source_id.rs | 11 ++++++++++- tests/testsuite/metadata.rs | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index 61795936dc2..e3a33a88e53 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -4,6 +4,7 @@ use semver::ReqParseError; use semver::VersionReq; use serde::ser; use serde::Serialize; +use std::path::PathBuf; use std::rc::Rc; use crate::core::{PackageId, SourceId, Summary}; @@ -61,6 +62,10 @@ struct SerializedDependency<'a> { /// The registry URL this dependency is from. /// If None, then it comes from the default registry (crates.io). registry: Option<&'a str>, + + /// The path to the manifest for a local path dependency. + #[serde(skip_serializing_if = "Option::is_none")] + manifest_path: Option, } impl ser::Serialize for Dependency { @@ -80,6 +85,7 @@ impl ser::Serialize for Dependency { target: self.platform(), rename: self.explicit_name_in_toml().map(|s| s.as_str()), registry: registry_id.as_ref().map(|sid| sid.url().as_str()), + manifest_path: self.source_id().manifest_path(), } .serialize(s) } diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index 5e6322d9e9c..52297a33ecf 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -9,7 +9,7 @@ use std::cmp::{self, Ordering}; use std::collections::HashSet; use std::fmt::{self, Formatter}; use std::hash::{self, Hash}; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::ptr; use std::sync::Mutex; use url::Url; @@ -237,6 +237,15 @@ impl SourceId { self.inner.kind == SourceKind::Path } + /// Returns the manifest path if this is a path dependency. + pub fn manifest_path(self) -> Option { + if self.inner.kind != SourceKind::Path { + return None; + } + + Some(self.inner.url.to_file_path().unwrap().join("Cargo.toml")) + } + /// Returns `true` if this source is from a registry (either local or not). pub fn is_registry(self) -> bool { matches!( diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 3c4ba6bf59b..25d91c3df40 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1984,6 +1984,7 @@ fn deps_with_bin_only() { "rename": null, "optional": false, "uses_default_features": true, + "manifest_path": "[..]/bdep/Cargo.toml", "features": [], "target": null, "registry": null From 525c5b6239eba82a03ab560402cfb48bbc2b7794 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Dec 2020 13:12:03 -0800 Subject: [PATCH 2/4] Switch to path and document --- src/cargo/core/dependency.rs | 6 +++--- src/cargo/core/source/source_id.rs | 6 +++--- src/doc/man/cargo-metadata.md | 4 ++++ src/doc/man/generated_txt/cargo-metadata.txt | 4 ++++ src/doc/src/commands/cargo-metadata.md | 4 ++++ src/etc/man/cargo-metadata.1 | 4 ++++ 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index e3a33a88e53..483ecef75bf 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -63,9 +63,9 @@ struct SerializedDependency<'a> { /// If None, then it comes from the default registry (crates.io). registry: Option<&'a str>, - /// The path to the manifest for a local path dependency. + /// The file system path for a local path dependency. #[serde(skip_serializing_if = "Option::is_none")] - manifest_path: Option, + path: Option, } impl ser::Serialize for Dependency { @@ -85,7 +85,7 @@ impl ser::Serialize for Dependency { target: self.platform(), rename: self.explicit_name_in_toml().map(|s| s.as_str()), registry: registry_id.as_ref().map(|sid| sid.url().as_str()), - manifest_path: self.source_id().manifest_path(), + path: self.source_id().local_path(), } .serialize(s) } diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index 52297a33ecf..a1183f39670 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -237,13 +237,13 @@ impl SourceId { self.inner.kind == SourceKind::Path } - /// Returns the manifest path if this is a path dependency. - pub fn manifest_path(self) -> Option { + /// Returns the local path if this is a path dependency. + pub fn local_path(self) -> Option { if self.inner.kind != SourceKind::Path { return None; } - Some(self.inner.url.to_file_path().unwrap().join("Cargo.toml")) + Some(self.inner.url.to_file_path().unwrap()) } /// Returns `true` if this source is from a registry (either local or not). diff --git a/src/doc/man/cargo-metadata.md b/src/doc/man/cargo-metadata.md index 811aa094a59..01feab34509 100644 --- a/src/doc/man/cargo-metadata.md +++ b/src/doc/man/cargo-metadata.md @@ -83,6 +83,10 @@ The output has the following format: null if not a target dependency. */ "target": "cfg(windows)", + /* The file system path for a local path dependency. + not present if not a path dependency. + */ + "path": "path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/doc/man/generated_txt/cargo-metadata.txt b/src/doc/man/generated_txt/cargo-metadata.txt index e48aa431a34..4b2dc49d8c4 100644 --- a/src/doc/man/generated_txt/cargo-metadata.txt +++ b/src/doc/man/generated_txt/cargo-metadata.txt @@ -78,6 +78,10 @@ OUTPUT FORMAT null if not a target dependency. */ "target": "cfg(windows)", + /* The file system path for a local path dependency. + not present if not a path dependency. + */ + "path": "path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/doc/src/commands/cargo-metadata.md b/src/doc/src/commands/cargo-metadata.md index 7acf4f52e53..fe780cc3653 100644 --- a/src/doc/src/commands/cargo-metadata.md +++ b/src/doc/src/commands/cargo-metadata.md @@ -83,6 +83,10 @@ The output has the following format: null if not a target dependency. */ "target": "cfg(windows)", + /* The file system path for a local path dependency. + not present if not a path dependency. + */ + "path": "path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/etc/man/cargo-metadata.1 b/src/etc/man/cargo-metadata.1 index aad4cdd571b..0016b578ed0 100644 --- a/src/etc/man/cargo-metadata.1 +++ b/src/etc/man/cargo-metadata.1 @@ -80,6 +80,10 @@ The output has the following format: null if not a target dependency. */ "target": "cfg(windows)", + /* The file system path for a local path dependency. + not present if not a path dependency. + */ + "path": "path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). From 25671d3495dc822459e805cb0b3a4dedff439e7a Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Dec 2020 13:39:52 -0800 Subject: [PATCH 3/4] path is absolute path --- src/doc/man/cargo-metadata.md | 2 +- src/doc/man/generated_txt/cargo-metadata.txt | 2 +- src/doc/src/commands/cargo-metadata.md | 2 +- src/etc/man/cargo-metadata.1 | 2 +- tests/testsuite/metadata.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/man/cargo-metadata.md b/src/doc/man/cargo-metadata.md index 01feab34509..33951fddd69 100644 --- a/src/doc/man/cargo-metadata.md +++ b/src/doc/man/cargo-metadata.md @@ -86,7 +86,7 @@ The output has the following format: /* The file system path for a local path dependency. not present if not a path dependency. */ - "path": "path/to/dep", + "path": "/path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/doc/man/generated_txt/cargo-metadata.txt b/src/doc/man/generated_txt/cargo-metadata.txt index 4b2dc49d8c4..8db6cc03a89 100644 --- a/src/doc/man/generated_txt/cargo-metadata.txt +++ b/src/doc/man/generated_txt/cargo-metadata.txt @@ -81,7 +81,7 @@ OUTPUT FORMAT /* The file system path for a local path dependency. not present if not a path dependency. */ - "path": "path/to/dep", + "path": "/path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/doc/src/commands/cargo-metadata.md b/src/doc/src/commands/cargo-metadata.md index fe780cc3653..5aa7d2f63e7 100644 --- a/src/doc/src/commands/cargo-metadata.md +++ b/src/doc/src/commands/cargo-metadata.md @@ -86,7 +86,7 @@ The output has the following format: /* The file system path for a local path dependency. not present if not a path dependency. */ - "path": "path/to/dep", + "path": "/path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/src/etc/man/cargo-metadata.1 b/src/etc/man/cargo-metadata.1 index 0016b578ed0..7a8809b495b 100644 --- a/src/etc/man/cargo-metadata.1 +++ b/src/etc/man/cargo-metadata.1 @@ -83,7 +83,7 @@ The output has the following format: /* The file system path for a local path dependency. not present if not a path dependency. */ - "path": "path/to/dep", + "path": "/path/to/dep", /* A string of the URL of the registry this dependency is from. If not specified or null, the dependency is from the default registry (crates.io). diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 25d91c3df40..02d5590b8ae 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1984,7 +1984,7 @@ fn deps_with_bin_only() { "rename": null, "optional": false, "uses_default_features": true, - "manifest_path": "[..]/bdep/Cargo.toml", + "manifest_path": "[..]/bdep", "features": [], "target": null, "registry": null From fd25f93693f7321f691e9a82e626cab2a21ebf47 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Dec 2020 14:53:29 -0800 Subject: [PATCH 4/4] Oops --- tests/testsuite/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 02d5590b8ae..9ea6bf99a08 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1984,7 +1984,7 @@ fn deps_with_bin_only() { "rename": null, "optional": false, "uses_default_features": true, - "manifest_path": "[..]/bdep", + "path": "[..]/foo/bdep", "features": [], "target": null, "registry": null