Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,12 @@ impl<'gctx> Workspace<'gctx> {
url,
deps.iter()
.map(|(name, dependency_cv)| {
crate::util::toml::to_dependency(
crate::util::toml::config_patch_to_dependency(
&dependency_cv.val,
name,
source,
self.gctx,
&mut warnings,
/* platform */ None,
// NOTE: Since we use ConfigRelativePath, this root isn't used as
// any relative paths are resolved before they'd be joined with root.
Path::new("unused-relative-path"),
/* kind */ None,
)
.map(|dep| Patch {
dep,
Expand Down
61 changes: 21 additions & 40 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2159,59 +2159,40 @@ fn patch(
Ok(patch)
}

pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
dep: &manifest::TomlDependency<P>,
/// Transforms a `patch` entry from Cargo config to a [`Dependency`].
pub(crate) fn config_patch_to_dependency<P: ResolveToPath + Clone>(
config_patch: &manifest::TomlDependency<P>,
name: &str,
source_id: SourceId,
gctx: &GlobalContext,
warnings: &mut Vec<String>,
platform: Option<Platform>,
file: &Path,
kind: Option<DepKind>,
) -> CargoResult<Dependency> {
dep_to_dependency(
dep,
name,
&mut ManifestContext {
deps: &mut Vec::new(),
source_id,
gctx,
warnings,
platform,
file,
},
kind,
)
let manifest_ctx = &mut ManifestContext {
deps: &mut Vec::new(),
source_id,
gctx,
warnings,
platform: None,
// config path doesn't have manifest file path, and doesn't use it.
file: Path::new("unused"),
};
dep_to_dependency(config_patch, name, manifest_ctx, None)
}

fn dep_to_dependency<P: ResolveToPath + Clone>(
orig: &manifest::TomlDependency<P>,
name: &str,
manifest_ctx: &mut ManifestContext<'_, '_>,
kind: Option<DepKind>,
) -> CargoResult<Dependency> {
match *orig {
manifest::TomlDependency::Simple(ref version) => detailed_dep_to_dependency(
&manifest::TomlDetailedDependency::<P> {
version: Some(version.clone()),
..Default::default()
},
name,
manifest_ctx,
kind,
),
manifest::TomlDependency::Detailed(ref details) => {
detailed_dep_to_dependency(details, name, manifest_ctx, kind)
}
}
}

fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
orig: &manifest::TomlDetailedDependency<P>,
name_in_toml: &str,
manifest_ctx: &mut ManifestContext<'_, '_>,
kind: Option<DepKind>,
) -> CargoResult<Dependency> {
let orig = match orig {
manifest::TomlDependency::Simple(version) => &manifest::TomlDetailedDependency::<P> {
version: Some(version.clone()),
..Default::default()
},
manifest::TomlDependency::Detailed(details) => details,
};

if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() {
anyhow::bail!(
"dependency ({name_in_toml}) specified without \
Expand Down