Skip to content

Commit

Permalink
Auto merge of #13318 - weihanglo:1.76.0-backport, r=epage
Browse files Browse the repository at this point in the history
[beta-1.76.0] fix(`--package`): accept `?` if it's a valid pkgid spec

Beta backports:

- <#13315>

In order to make CI pass, the following PRs are also cherry-picked:

-
  • Loading branch information
bors committed Jan 18, 2024
2 parents ddec308 + 268795b commit e8232ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_compile/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn opt_patterns_and_names(
let mut opt_patterns = Vec::new();
let mut opt_names = BTreeSet::new();
for x in opt.iter() {
if is_glob_pattern(x) {
if PackageIdSpec::parse(x).is_err() && is_glob_pattern(x) {
opt_patterns.push((build_glob(x)?, false));
} else {
opt_names.insert(String::as_str(x));
Expand Down
41 changes: 41 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::fmt::{self, Write};

use crate::messages::raw_rustc_output;
use cargo_test_support::compare;
use cargo_test_support::install::exe;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
Expand Down Expand Up @@ -1519,3 +1520,43 @@ fn versionless_package() {
)
.run();
}

#[cargo_test]
fn pkgid_querystring_works() {
let git_project = git::new("gitdep", |p| {
p.file("Cargo.toml", &basic_manifest("gitdep", "1.0.0"))
.file("src/lib.rs", "")
});
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
[dependencies]
gitdep = {{ git = "{}", branch = "master" }}
"#,
git_project.url()
),
)
.file("src/lib.rs", "")
.build();

p.cargo("generate-lockfile").run();

let output = p.cargo("pkgid").arg("gitdep").exec_with_output().unwrap();
let gitdep_pkgid = String::from_utf8(output.stdout).unwrap();
let gitdep_pkgid = gitdep_pkgid.trim();
compare::assert_match_exact("git+file://[..]/gitdep?branch=master#1.0.0", &gitdep_pkgid);

p.cargo("build -p")
.arg(gitdep_pkgid)
.with_stderr(
"\
[COMPILING] gitdep v1.0.0 (file:///[..]/gitdep?branch=master#[..])
[FINISHED] dev [..]",
)
.run();
}

0 comments on commit e8232ae

Please sign in to comment.