From db6a1df07b487e13d0de3cadee666564dc420443 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 6 Sep 2022 11:37:15 +0800 Subject: [PATCH] Fix sdist build for optional path dependencies --- src/source_distribution.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/source_distribution.rs b/src/source_distribution.rs index 12bffaf6e..534852f17 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -58,15 +58,16 @@ fn rewrite_cargo_toml( dep_name ) } - // This is the location of the targeted crate in the source distribution - table[&dep_name]["path"] = if root_crate { - toml_edit::value(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name)) - } else { - // Cargo.toml contains relative paths, and we're already in LOCAL_DEPENDENCIES_FOLDER - toml_edit::value(format!("../{}", dep_name)) - }; - rewritten = true; if !known_path_deps.contains_key(&dep_name) { + // Ignore optional indirect depencencies + if !root_crate + && table[&dep_name] + .get("optional") + .and_then(|x| x.as_bool()) + .unwrap_or_default() + { + continue; + } bail!( "cargo metadata does not know about the path for {}.{} present in {}, \ which should never happen ಠ_ಠ", @@ -75,6 +76,14 @@ fn rewrite_cargo_toml( manifest_path.as_ref().display() ); } + // This is the location of the targeted crate in the source distribution + table[&dep_name]["path"] = if root_crate { + toml_edit::value(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name)) + } else { + // Cargo.toml contains relative paths, and we're already in LOCAL_DEPENDENCIES_FOLDER + toml_edit::value(format!("../{}", dep_name)) + }; + rewritten = true; } } }