Skip to content

Commit 0483c12

Browse files
committed
feat(ops): add vendored crates summary to cargo vendor
1 parent 230e325 commit 0483c12

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

src/cargo/ops/vendor.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn vendor(ws: &Workspace<'_>, opts: &VendorOptions<'_>) -> CargoResult<()> {
4141
}
4242
let workspaces = extra_workspaces.iter().chain(Some(ws)).collect::<Vec<_>>();
4343
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
44-
let vendor_config = sync(gctx, &workspaces, opts).context("failed to sync")?;
44+
let (vendor_config, count) = sync(gctx, &workspaces, opts).context("failed to sync")?;
4545

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

58+
if count > 0 {
59+
gctx.shell().status(
60+
"Vendored",
61+
format!("{} crates into {}", count, opts.destination.display()),
62+
)?;
63+
}
64+
5865
Ok(())
5966
}
6067

@@ -121,7 +128,7 @@ fn sync(
121128
gctx: &GlobalContext,
122129
workspaces: &[&Workspace<'_>],
123130
opts: &VendorOptions<'_>,
124-
) -> CargoResult<VendorConfig> {
131+
) -> CargoResult<(VendorConfig, usize)> {
125132
let dry_run = false;
126133
let vendor_dir = try_canonicalize(opts.destination);
127134
let vendor_dir = vendor_dir.as_deref().unwrap_or(opts.destination);
@@ -419,7 +426,7 @@ fn sync(
419426
paths::remove_dir(vendor_dir)?;
420427
}
421428

422-
Ok(VendorConfig { source: config })
429+
Ok((VendorConfig { source: config }, ids.len()))
423430
}
424431

425432
fn cp_sources(

tests/testsuite/build_scripts_multiple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ fn verify_vendor_multiple_build_scripts() {
357357
[WARNING] ignoring `package.build` entry `build2.rs` as it is not included in the published package
358358
To use vendored sources, add this to your .cargo/config.toml for this project:
359359
360+
Vendored 1 crates into vendor
360361
361362
"#]])
362363
.run();

tests/testsuite/vendor.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,7 @@ fn dont_delete_non_registry_sources_with_respect_source_config() {
19891989
Vendoring log v0.3.5 ([ROOT]/foo/vendor/log) to new-vendor-dir/log
19901990
To use vendored sources, add this to your .cargo/config.toml for this project:
19911991
1992+
Vendored 1 crates into new-vendor-dir
19921993
19931994
"#]])
19941995
.with_stdout_data(str![[r#"
@@ -2166,6 +2167,7 @@ fn vendor_local_registry() {
21662167
Vendoring bar v0.0.0 ([ROOT]/home/.cargo/registry/src/-[HASH]/bar-0.0.0) to vendor/bar
21672168
To use vendored sources, add this to your .cargo/config.toml for this project:
21682169
2170+
Vendored 1 crates into vendor
21692171
21702172
"#]])
21712173
.run();
@@ -2256,3 +2258,45 @@ fn vendor_filters_git_files_recursively() {
22562258
assert!(!p.root().join("vendor/bar/.gitattributes").exists());
22572259
assert!(p.root().join("vendor/bar/src/lib.rs").exists());
22582260
}
2261+
2262+
#[cargo_test]
2263+
fn vendor_summary_output() {
2264+
let p = project()
2265+
.file(
2266+
"Cargo.toml",
2267+
r#"
2268+
[package]
2269+
name = "foo"
2270+
version = "0.1.0"
2271+
2272+
[dependencies]
2273+
bar = "0.1.0"
2274+
baz = "0.1.0"
2275+
qux = "0.1.0"
2276+
"#,
2277+
)
2278+
.file("src/lib.rs", "")
2279+
.build();
2280+
2281+
Package::new("bar", "0.1.0").publish();
2282+
Package::new("baz", "0.1.0").publish();
2283+
Package::new("qux", "0.1.0").publish();
2284+
2285+
p.cargo("vendor --respect-source-config")
2286+
.with_stderr_data(str![[r#"
2287+
[UPDATING] `[..]` index
2288+
[LOCKING] 3 packages to latest compatible versions
2289+
[DOWNLOADING] crates ...
2290+
[DOWNLOADED] bar v0.1.0 (registry `[..]`)
2291+
[DOWNLOADED] baz v0.1.0 (registry `[..]`)
2292+
[DOWNLOADED] qux v0.1.0 (registry `[..]`)
2293+
Vendoring bar v0.1.0 ([..]bar-0.1.0) to vendor/bar
2294+
Vendoring baz v0.1.0 ([..]baz-0.1.0) to vendor/baz
2295+
Vendoring qux v0.1.0 ([..]qux-0.1.0) to vendor/qux
2296+
To use vendored sources, add this to your .cargo/config.toml for this project:
2297+
2298+
Vendored 3 crates into vendor
2299+
2300+
"#]])
2301+
.run();
2302+
}

0 commit comments

Comments
 (0)