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

vendor: Add --include-path-deps to include path dependencies #12858

Closed
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
2 changes: 2 additions & 0 deletions src/bin/cargo/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn cli() -> Command {
"versioned-dirs",
"Always include version in subdir name",
))
.arg(flag("include-path-deps", "Include path dependencies"))
.arg(unsupported("no-merge-sources"))
.arg(unsupported("relative-path"))
.arg(unsupported("only-git-deps"))
Expand Down Expand Up @@ -75,6 +76,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
no_delete: args.flag("no-delete"),
destination: &path,
versioned_dirs: args.flag("versioned-dirs"),
include_path_deps: args.flag("include-path-deps"),
extra: args
.get_many::<PathBuf>("tomls")
.unwrap_or_default()
Expand Down
24 changes: 21 additions & 3 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
pub struct VendorOptions<'a> {
pub no_delete: bool,
pub versioned_dirs: bool,
pub include_path_deps: bool,
pub destination: &'a Path,
pub extra: Vec<PathBuf>,
}
Expand Down Expand Up @@ -62,6 +63,8 @@ struct VendorConfig {
enum VendorSource {
Directory {
directory: String,
#[serde(rename = "replace-with", skip_serializing_if = "Option::is_none")]
replace_with: Option<String>,
},
Registry {
registry: Option<String>,
Expand Down Expand Up @@ -153,12 +156,21 @@ fn sync(
.get_many(resolve.iter())
.with_context(|| "failed to download packages")?;

let current = ws
.current()
.with_context(|| "using virtual manifest in workspace")?
.package_id();
for pkg in resolve.iter() {
// No need to vendor path crates since they're already in the
// repository
if pkg.source_id().is_path() {
// Since the target crate itself is also part of the packages,
// make sure we skip it.
if pkg == current {
continue;
}

if pkg.source_id().is_path() && !opts.include_path_deps {
continue;
}

ids.insert(
pkg,
packages
Expand Down Expand Up @@ -291,6 +303,11 @@ fn sync(
rev,
replace_with: merged_source_name.to_string(),
}
} else if source_id.is_path() && opts.include_path_deps {
VendorSource::Directory {
directory: source_id.url().to_string(),
replace_with: Some(merged_source_name.to_string()),
}
} else {
panic!("Invalid source ID: {}", source_id)
};
Expand All @@ -305,6 +322,7 @@ fn sync(
// This backslash normalization is for making output paths more
// cross-platform compatible.
directory: opts.destination.to_string_lossy().replace("\\", "/"),
replace_with: None,
},
);
} else if !dest_dir_already_exists {
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_vendor/help/stdout.log
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Options:
-s, --sync <TOML> Additional `Cargo.toml` to sync and vendor
--respect-source-config Respect `[source]` config in `.cargo/config`
--versioned-dirs Always include version in subdir name
--include-path-deps Include path dependencies
-q, --quiet Do not print cargo log messages
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
Expand Down
34 changes: 34 additions & 0 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,40 @@ fn git_crlf_preservation() {
assert_eq!(input, output);
}

#[cargo_test]
fn path_deps() {
let p = project()
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
"#,
)
.file("bar/src/lib.rs", "")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dependencies]
bar = { path = "bar" }
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("vendor --respect-source-config").run();
assert!(!p.root().join("vendor/bar").is_dir());

p.cargo("vendor --respect-source-config --include-path-deps")
.run();
assert!(p.root().join("vendor/bar").is_dir());
}

#[cargo_test]
#[cfg(unix)]
fn vendor_preserves_permissions() {
Expand Down