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

feat(cargo-vendor): vendor path dep if it is not in any given workspaces #55

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 21 additions & 6 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,24 @@ struct VendorConfig {
}

#[derive(Serialize)]
#[serde(rename_all = "lowercase", untagged)]
#[serde(rename_all = "kebab-case", rename_all_fields = "kebab-case", untagged)]
enum VendorSource {
Directory {
directory: String,
},
Registry {
registry: Option<String>,
#[serde(rename = "replace-with")]
replace_with: String,
},
Git {
git: String,
branch: Option<String>,
tag: Option<String>,
rev: Option<String>,
#[serde(rename = "replace-with")]
replace_with: String,
},
Path {
path: String,
replace_with: String,
},
}
Expand Down Expand Up @@ -143,6 +145,10 @@ fn sync(

// Next up let's actually download all crates and start storing internal
// tables about them.
let members: BTreeSet<_> = workspaces
.iter()
.flat_map(|ws| ws.members().map(|p| p.package_id()))
.collect();
for ws in workspaces {
let (packages, resolve) =
ops::resolve_ws(ws).with_context(|| "failed to load pkg lockfile")?;
Expand All @@ -152,9 +158,8 @@ fn sync(
.with_context(|| "failed to download packages")?;

for pkg in resolve.iter() {
// No need to vendor path crates since they're already in the
// repository
if pkg.source_id().is_path() {
// Don't vendor path deps unless it is outside any of the given workspaces.
if pkg.source_id().is_path() && !members.contains(&pkg) {
continue;
}
ids.insert(
Expand Down Expand Up @@ -289,6 +294,16 @@ fn sync(
rev,
replace_with: merged_source_name.to_string(),
}
} else if source_id.is_path() {
VendorSource::Path {
path: source_id
.url()
.to_file_path()
.unwrap()
.to_string_lossy()
.replace("\\", "/"),
replace_with: merged_source_name.to_string(),
}
} else {
panic!("Invalid source ID: {}", source_id)
};
Expand Down
6 changes: 6 additions & 0 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct SourceConfigMap<'gctx> {
struct SourceConfigDef {
/// Indicates this source should be replaced with another of the given name.
replace_with: OptValue<String>,
/// A path source.
path: Option<ConfigRelativePath>,
/// A directory source.
directory: Option<ConfigRelativePath>,
/// A registry source. Value is a URL.
Expand Down Expand Up @@ -249,6 +251,10 @@ restore the source replacement configuration to continue the build
let path = directory.resolve_path(self.gctx);
srcs.push(SourceId::for_directory(&path)?);
}
if let Some(path) = def.path {
let path = path.resolve_path(self.config);
srcs.push(SourceId::for_path(&path)?);
}
if let Some(git) = def.git {
let url = url(&git, &format!("source.{}.git", name))?;
let reference = match def.branch {
Expand Down
Loading