Skip to content

Commit b816d82

Browse files
committed
Auto merge of #10448 - aeikum:fix_vendor_sync, r=weihanglo
vendor: Don't allow multiple values for --sync The --sync argument to cargo vendor currently takes a list, which makes it easy for it to eat the final path argument: ```` cargo vendor --manifest-path foo/Cargo.toml -s bar/Cargo.toml ./test_vendor/ error: failed to read ./test_vendor/ Caused by: No such file or directory (os error 2) ```` Per discussion on #10441, this behavior is undesirable and hopefully used infrequently enough that we can change the UI for it. This patch will now only allow one value per --sync argument. I didn't regenerate other doc files as it's not clear to me how/when that should be done.
2 parents f955ddc + d41f5cc commit b816d82

File tree

6 files changed

+76
-10
lines changed

6 files changed

+76
-10
lines changed

src/bin/cargo/commands/vendor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub fn cli() -> App {
2424
.help("Additional `Cargo.toml` to sync and vendor")
2525
.value_name("TOML")
2626
.allow_invalid_utf8(true)
27-
.multiple_occurrences(true)
28-
.multiple_values(true),
27+
.multiple_occurrences(true),
2928
)
3029
.arg(
3130
Arg::new("respect-source-config")

src/doc/man/cargo-vendor.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ to use the vendored sources, which you will need to add to `.cargo/config.toml`.
2626
{{#options}}
2727

2828
{{#option "`-s` _manifest_" "`--sync` _manifest_" }}
29-
Specify extra `Cargo.toml` manifests to workspaces which should also be
30-
vendored and synced to the output.
29+
Specify an extra `Cargo.toml` manifest to workspaces which should also be
30+
vendored and synced to the output. May be specified multiple times.
3131
{{/option}}
3232

3333
{{#option "`--no-delete`" }}

src/doc/man/generated_txt/cargo-vendor.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ DESCRIPTION
2020
OPTIONS
2121
Vendor Options
2222
-s manifest, --sync manifest
23-
Specify extra Cargo.toml manifests to workspaces which should also
24-
be vendored and synced to the output.
23+
Specify an extra Cargo.toml manifest to workspaces which should also
24+
be vendored and synced to the output. May be specified multiple
25+
times.
2526

2627
--no-delete
2728
Don't delete the "vendor" directory when vendoring, but rather keep

src/doc/src/commands/cargo-vendor.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ to use the vendored sources, which you will need to add to `.cargo/config.toml`.
2727

2828
<dt class="option-term" id="option-cargo-vendor--s"><a class="option-anchor" href="#option-cargo-vendor--s"></a><code>-s</code> <em>manifest</em></dt>
2929
<dt class="option-term" id="option-cargo-vendor---sync"><a class="option-anchor" href="#option-cargo-vendor---sync"></a><code>--sync</code> <em>manifest</em></dt>
30-
<dd class="option-desc">Specify extra <code>Cargo.toml</code> manifests to workspaces which should also be
31-
vendored and synced to the output.</dd>
30+
<dd class="option-desc">Specify an extra <code>Cargo.toml</code> manifest to workspaces which should also be
31+
vendored and synced to the output. May be specified multiple times.</dd>
3232

3333

3434
<dt class="option-term" id="option-cargo-vendor---no-delete"><a class="option-anchor" href="#option-cargo-vendor---no-delete"></a><code>--no-delete</code></dt>

src/etc/man/cargo-vendor.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ to use the vendored sources, which you will need to add to \fB\&.cargo/config.to
2222
\fB\-s\fR \fImanifest\fR,
2323
\fB\-\-sync\fR \fImanifest\fR
2424
.RS 4
25-
Specify extra \fBCargo.toml\fR manifests to workspaces which should also be
26-
vendored and synced to the output.
25+
Specify an extra \fBCargo.toml\fR manifest to workspaces which should also be
26+
vendored and synced to the output. May be specified multiple times.
2727
.RE
2828
.sp
2929
\fB\-\-no\-delete\fR

tests/testsuite/vendor.rs

+66
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,72 @@ fn two_lockfiles() {
309309
p.cargo("build").cwd("bar").run();
310310
}
311311

312+
#[cargo_test]
313+
fn test_sync_argument() {
314+
let p = project()
315+
.no_manifest()
316+
.file(
317+
"foo/Cargo.toml",
318+
r#"
319+
[package]
320+
name = "foo"
321+
version = "0.1.0"
322+
323+
[dependencies]
324+
bitflags = "=0.7.0"
325+
"#,
326+
)
327+
.file("foo/src/lib.rs", "")
328+
.file(
329+
"bar/Cargo.toml",
330+
r#"
331+
[package]
332+
name = "bar"
333+
version = "0.1.0"
334+
335+
[dependencies]
336+
bitflags = "=0.8.0"
337+
"#,
338+
)
339+
.file("bar/src/lib.rs", "")
340+
.file(
341+
"baz/Cargo.toml",
342+
r#"
343+
[package]
344+
name = "baz"
345+
version = "0.1.0"
346+
347+
[dependencies]
348+
bitflags = "=0.8.0"
349+
"#,
350+
)
351+
.file("baz/src/lib.rs", "")
352+
.build();
353+
354+
Package::new("bitflags", "0.7.0").publish();
355+
Package::new("bitflags", "0.8.0").publish();
356+
357+
p.cargo("vendor --respect-source-config --manifest-path foo/Cargo.toml -s bar/Cargo.toml baz/Cargo.toml test_vendor")
358+
.with_stderr("\
359+
error: Found argument 'test_vendor' which wasn't expected, or isn't valid in this context
360+
361+
USAGE:
362+
cargo[EXE] vendor [OPTIONS] [path]
363+
364+
For more information try --help",
365+
)
366+
.with_status(1)
367+
.run();
368+
369+
p.cargo("vendor --respect-source-config --manifest-path foo/Cargo.toml -s bar/Cargo.toml -s baz/Cargo.toml test_vendor")
370+
.run();
371+
372+
let lock = p.read_file("test_vendor/bitflags/Cargo.toml");
373+
assert!(lock.contains("version = \"0.8.0\""));
374+
let lock = p.read_file("test_vendor/bitflags-0.7.0/Cargo.toml");
375+
assert!(lock.contains("version = \"0.7.0\""));
376+
}
377+
312378
#[cargo_test]
313379
fn delete_old_crates() {
314380
let p = project()

0 commit comments

Comments
 (0)