Skip to content

Commit

Permalink
Fix sdist build for optional path dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Sep 6, 2022
1 parent d1773fc commit eb909d5
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ fn rewrite_cargo_toml(
)
}
if !known_path_deps.contains_key(&dep_name) {
// Ignore optional indirect dependencies
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 ಠ_ಠ",
Expand Down Expand Up @@ -140,11 +131,17 @@ fn add_crate_to_source_distribution(
.args(&["package", "--list", "--allow-dirty", "--manifest-path"])
.arg(manifest_path)
.output()
.context("Failed to run `cargo package --list --allow-dirty`")?;
.with_context(|| {
format!(
"Failed to run `cargo package --list --allow-dirty --manifest-path {}`",
manifest_path.display()
)
})?;
if !output.status.success() {
bail!(
"Failed to query file list from cargo: {}\n--- Stdout:\n{}\n--- Stderr:\n{}",
"Failed to query file list from cargo: {}\n--- Manifest path: {}\n--- Stdout:\n{}\n--- Stderr:\n{}",
output.status,
manifest_path.display(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
Expand Down Expand Up @@ -213,20 +210,21 @@ fn find_path_deps(cargo_metadata: &Metadata) -> Result<HashMap<String, PathBuf>>
while let Some(top) = stack.pop() {
for dependency in &top.dependencies {
if let Some(path) = &dependency.path {
path_deps.insert(dependency.name.clone(), PathBuf::from(path));
// we search for the respective package by `manifest_path`, there seems
// to be no way to query the dependency graph given `dependency`
let dep_manifest_path = path.join("Cargo.toml");
let dep_package = cargo_metadata
path_deps.insert(
dependency.name.clone(),
PathBuf::from(dep_manifest_path.clone()),
);
if let Some(dep_package) = cargo_metadata
.packages
.iter()
.find(|package| package.manifest_path == dep_manifest_path)
.context(format!(
"Expected metadata to contain a package for path dependency {:?}",
path
))?;
// scan the dependencies of the path dependency
stack.push(dep_package)
{
// scan the dependencies of the path dependency
stack.push(dep_package)
}
}
}
}
Expand Down

0 comments on commit eb909d5

Please sign in to comment.