Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sdist build when multiple workspaces are involved #1137

Merged
merged 1 commit into from
Sep 26, 2022
Merged
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
32 changes: 30 additions & 2 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::module_writer::{add_data, ModuleWriter};
use crate::{BuildContext, PyProjectToml, SDistWriter};
use anyhow::{bail, Context, Result};
use cargo_metadata::Metadata;
use cargo_metadata::{Metadata, MetadataCommand};
use fs_err as fs;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -411,12 +411,40 @@ pub fn source_distribution(
));

// Add local path dependencies
let mut path_dep_workspace_manifests = HashMap::new();
for (name, path_dep) in known_path_deps.iter() {
// Path dependencies may not be in the same workspace as the root crate,
// thus we need to find out its workspace root from `cargo metadata`
let path_dep_metadata = MetadataCommand::new()
.manifest_path(path_dep)
// We don't need to resolve the dependency graph
.no_deps()
.exec()
.with_context(|| {
format!(
"Cargo metadata failed for {} at '{}'",
name,
path_dep.display()
)
})?;
let path_dep_workspace_manifest =
if path_dep_metadata.workspace_root == build_context.cargo_metadata.workspace_root {
&workspace_manifest
} else {
if !path_dep_workspace_manifests.contains_key(&path_dep_metadata.workspace_root) {
let manifest: toml_edit::Document =
fs::read_to_string(&path_dep_metadata.workspace_root.join("Cargo.toml"))?
.parse()?;
path_dep_workspace_manifests
.insert(path_dep_metadata.workspace_root.clone(), manifest);
}
&path_dep_workspace_manifests[&path_dep_metadata.workspace_root]
};
add_crate_to_source_distribution(
&mut writer,
&pyproject_toml_path,
&path_dep,
&workspace_manifest,
path_dep_workspace_manifest,
&root_dir.join(LOCAL_DEPENDENCIES_FOLDER).join(name),
&known_path_deps,
false,
Expand Down