mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 22:13:47 +00:00
Auto merge of #8994 - jonhoo:manifest-in-local-deps-meta, r=ehuss
metadata: Supply local path for path dependencies This is potentially a simpler way to address #7483 than #8988. /cc https://github.com/rust-lang/rustfmt/issues/4247 Fixes #7483.
This commit is contained in:
commit
329895f5b5
|
@ -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 file system path for a local path dependency.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
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()),
|
||||
path: self.source_id().local_path(),
|
||||
}
|
||||
.serialize(s)
|
||||
}
|
||||
|
|
|
@ -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 local path if this is a path dependency.
|
||||
pub fn local_path(self) -> Option<PathBuf> {
|
||||
if self.inner.kind != SourceKind::Path {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(self.inner.url.to_file_path().unwrap())
|
||||
}
|
||||
|
||||
/// Returns `true` if this source is from a registry (either local or not).
|
||||
pub fn is_registry(self) -> bool {
|
||||
matches!(
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -1986,6 +1986,7 @@ fn deps_with_bin_only() {
|
|||
"rename": null,
|
||||
"optional": false,
|
||||
"uses_default_features": true,
|
||||
"path": "[..]/foo/bdep",
|
||||
"features": [],
|
||||
"target": null,
|
||||
"registry": null
|
||||
|
|
Loading…
Reference in a new issue