Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/cargo/ops/vendor.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this change might be simple and straightforwards, our contributing guideline encourages starting from an issue and discussion first before posting a pull request: https://doc.crates.io/contrib/process/working-on-cargo.html#before-hacking-on-cargo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that i am still learning the workflow here. I'll make sure to start with an issue next time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a final status message to 'cargo vendor' showing the count of crates vendored and the destination directory. This improves consistency with other commands like 'cargo install'

I personally don't immediately see the value of consistency here. Other maintainers may have different opinions though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, count of binaries installed via cargo install is essentially as we might not want to accidentally install extra bins. But do people really know about how many dependencies they vendor? What is the actual summary people want to know when vendoring. This might be worthy some level of discussions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a final confirmation would be helpful for large workspaces, but I'm open to suggestions if you think the summary should be different or is unnecessary

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn vendor(ws: &Workspace<'_>, opts: &VendorOptions<'_>) -> CargoResult<()> {
}
let workspaces = extra_workspaces.iter().chain(Some(ws)).collect::<Vec<_>>();
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
let vendor_config = sync(gctx, &workspaces, opts).context("failed to sync")?;
let (vendor_config, count) = sync(gctx, &workspaces, opts).context("failed to sync")?;

if gctx.shell().verbosity() != Verbosity::Quiet {
if vendor_config.source.is_empty() {
Expand All @@ -55,6 +55,13 @@ pub fn vendor(ws: &Workspace<'_>, opts: &VendorOptions<'_>) -> CargoResult<()> {
}
}

if count > 0 {
gctx.shell().status(
"Vendored",
format!("{} crates into {}", count, opts.destination.display()),
)?;
}

Ok(())
}

Expand Down Expand Up @@ -121,7 +128,7 @@ fn sync(
gctx: &GlobalContext,
workspaces: &[&Workspace<'_>],
opts: &VendorOptions<'_>,
) -> CargoResult<VendorConfig> {
) -> CargoResult<(VendorConfig, usize)> {
let dry_run = false;
let vendor_dir = try_canonicalize(opts.destination);
let vendor_dir = vendor_dir.as_deref().unwrap_or(opts.destination);
Expand Down Expand Up @@ -419,7 +426,7 @@ fn sync(
paths::remove_dir(vendor_dir)?;
}

Ok(VendorConfig { source: config })
Ok((VendorConfig { source: config }, ids.len()))
}

fn cp_sources(
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/build_scripts_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ fn verify_vendor_multiple_build_scripts() {
[WARNING] ignoring `package.build` entry `build2.rs` as it is not included in the published package
To use vendored sources, add this to your .cargo/config.toml for this project:

Vendored 1 crates into vendor

"#]])
.run();
Expand Down
36 changes: 36 additions & 0 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ fn dont_delete_non_registry_sources_with_respect_source_config() {
Vendoring log v0.3.5 ([ROOT]/foo/vendor/log) to new-vendor-dir/log
To use vendored sources, add this to your .cargo/config.toml for this project:

Vendored 1 crates into new-vendor-dir

"#]])
.with_stdout_data(str![[r#"
Expand Down Expand Up @@ -2166,6 +2167,7 @@ fn vendor_local_registry() {
Vendoring bar v0.0.0 ([ROOT]/home/.cargo/registry/src/-[HASH]/bar-0.0.0) to vendor/bar
To use vendored sources, add this to your .cargo/config.toml for this project:

Vendored 1 crates into vendor

"#]])
.run();
Expand Down Expand Up @@ -2256,3 +2258,37 @@ fn vendor_filters_git_files_recursively() {
assert!(!p.root().join("vendor/bar/.gitattributes").exists());
assert!(p.root().join("vendor/bar/src/lib.rs").exists());
}

#[cargo_test]
fn vendor_summary_output() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

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

Package::new("bar", "0.1.0").publish();

p.cargo("vendor --respect-source-config")
.with_stderr_data(str![[r#"
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 (registry `[..]`)
Vendoring bar v0.1.0 ([..]bar-0.1.0) to vendor/bar
To use vendored sources, add this to your .cargo/config.toml for this project:

Vendored 1 crates into vendor

"#]])
.run();
}