Supply manifest path for path dependencies

Fixes #7483.
This commit is contained in:
Jon Gjengset 2020-12-17 13:26:10 -08:00
parent 27dba04f40
commit 17b129afca
3 changed files with 17 additions and 1 deletions

View File

@ -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<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()),
manifest_path: self.source_id().manifest_path(),
}
.serialize(s)
}

View File

@ -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<PathBuf> {
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!(

View File

@ -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