Skip to content

Commit c9d5cb3

Browse files
committed
Auto merge of #13315 - weihanglo:pkg-selection, r=epage
fix(`--package`): accept `?` if it's a valid pkgid spec
2 parents 1ae6310 + 637b5d1 commit c9d5cb3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/cargo/ops/cargo_compile/packages.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn opt_patterns_and_names(
195195
let mut opt_patterns = Vec::new();
196196
let mut opt_names = BTreeSet::new();
197197
for x in opt.iter() {
198-
if is_glob_pattern(x) {
198+
if PackageIdSpec::parse(x).is_err() && is_glob_pattern(x) {
199199
opt_patterns.push((build_glob(x)?, false));
200200
} else {
201201
opt_names.insert(String::as_str(x));

tests/testsuite/check.rs

+41
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::fmt::{self, Write};
44

55
use crate::messages::raw_rustc_output;
6+
use cargo_test_support::compare;
67
use cargo_test_support::install::exe;
78
use cargo_test_support::paths::CargoPathExt;
89
use cargo_test_support::registry::Package;
@@ -1519,3 +1520,43 @@ fn versionless_package() {
15191520
)
15201521
.run();
15211522
}
1523+
1524+
#[cargo_test]
1525+
fn pkgid_querystring_works() {
1526+
let git_project = git::new("gitdep", |p| {
1527+
p.file("Cargo.toml", &basic_manifest("gitdep", "1.0.0"))
1528+
.file("src/lib.rs", "")
1529+
});
1530+
let p = project()
1531+
.file(
1532+
"Cargo.toml",
1533+
&format!(
1534+
r#"
1535+
[package]
1536+
name = "foo"
1537+
1538+
[dependencies]
1539+
gitdep = {{ git = "{}", branch = "master" }}
1540+
"#,
1541+
git_project.url()
1542+
),
1543+
)
1544+
.file("src/lib.rs", "")
1545+
.build();
1546+
1547+
p.cargo("generate-lockfile").run();
1548+
1549+
let output = p.cargo("pkgid").arg("gitdep").exec_with_output().unwrap();
1550+
let gitdep_pkgid = String::from_utf8(output.stdout).unwrap();
1551+
let gitdep_pkgid = gitdep_pkgid.trim();
1552+
compare::assert_match_exact("git+file://[..]/gitdep?branch=master#1.0.0", &gitdep_pkgid);
1553+
1554+
p.cargo("build -p")
1555+
.arg(gitdep_pkgid)
1556+
.with_stderr(
1557+
"\
1558+
[COMPILING] gitdep v1.0.0 (file:///[..]/gitdep?branch=master#[..])
1559+
[FINISHED] dev [..]",
1560+
)
1561+
.run();
1562+
}

0 commit comments

Comments
 (0)