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 --skip-path-deps to skip path dependencies #10135

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
6 changes: 6 additions & 0 deletions src/bin/cargo/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ pub fn cli() -> App {
.long("versioned-dirs")
.help("Always include version in subdir name"),
)
.arg(
Arg::with_name("skip-path-deps")
.long("skip-path-deps")
.help("Skip path dependencies from vendoring"),
)
// Not supported.
.arg(
Arg::with_name("no-merge-sources")
Expand Down Expand Up @@ -107,6 +112,7 @@ https://github.com/rust-lang/cargo/issues/new
no_delete: args.is_present("no-delete"),
destination: &path,
versioned_dirs: args.is_present("versioned-dirs"),
skip_path_deps: args.is_present("skip-path-deps"),
extra: args
.values_of_os("tomls")
.unwrap_or_default()
Expand Down
27 changes: 24 additions & 3 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};
pub struct VendorOptions<'a> {
pub no_delete: bool,
pub versioned_dirs: bool,
pub skip_path_deps: bool,
pub destination: &'a Path,
pub extra: Vec<PathBuf>,
}
Expand Down Expand Up @@ -52,6 +53,8 @@ struct VendorConfig {
enum VendorSource {
Directory {
directory: PathBuf,
#[serde(rename = "replace-with", skip_serializing_if = "Option::is_none")]
replace_with: Option<String>,
},
Registry {
registry: Option<String>,
Expand Down Expand Up @@ -142,12 +145,24 @@ 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() {
continue;
// Since the target crate itself is also part of the packages,
// make sure we skip it.
if pkg == current {
continue;
}

// Otherwise only skip if configured to do so.
if opts.skip_path_deps {
continue;
}
}

ids.insert(
pkg,
packages
Expand Down Expand Up @@ -243,6 +258,7 @@ fn sync(
merged_source_name.to_string(),
VendorSource::Directory {
directory: opts.destination.to_path_buf(),
replace_with: None,
},
);

Expand Down Expand Up @@ -284,6 +300,11 @@ fn sync(
rev,
replace_with: merged_source_name.to_string(),
}
} else if source_id.is_path() {
VendorSource::Directory {
directory: source_id.url().to_file_path().unwrap(),
replace_with: Some(merged_source_name.to_string()),
}
} else {
panic!("Invalid source ID: {}", source_id)
};
Expand Down
37 changes: 36 additions & 1 deletion tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ fn depend_on_vendor_dir_not_deleted() {
"#,
);

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

Expand Down Expand Up @@ -721,6 +722,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 --skip-path-deps")
.run();
assert!(!p.root().join("vendor/bar").is_dir());
}

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