Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cargo pkgid support for cargo-script #14961

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 0 additions & 7 deletions src/bin/cargo/commands/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ pub fn cli() -> Command {

pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let ws = args.workspace(gctx)?;
if ws.root_maybe().is_embedded() {
return Err(anyhow::format_err!(
"{} is unsupported by `cargo pkgid`",
ws.root_manifest().display()
)
.into());
}
if args.is_present_with_zero_values("package") {
print_available_packages(&ws)?
}
Expand Down
5 changes: 4 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,10 @@ impl<'gctx> Packages<'gctx> {
match self.packages.entry(key.to_path_buf()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this will be ambiguous when we add workspace support and will be hard to find. By working around this now, we are laying a trap for ourselves in the future.

Maybe we should have a refactor commit before this one that changes the key from being the manifest-dir to being the manifest-path.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Totally argee this is a bit tricky. I will try to refactor it and change the key.

Entry::Occupied(e) => Ok(e.into_mut()),
Entry::Vacant(v) => {
let source_id = SourceId::for_path(key)?;
let source_id = match crate::util::toml::is_embedded(manifest_path) {
true => SourceId::for_path(manifest_path)?,
false => SourceId::for_path(key)?,
};
let manifest = read_manifest(manifest_path, source_id, self.gctx)?;
Ok(v.insert(match manifest {
EitherManifest::Real(manifest) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,7 @@ fn main() {
.with_stderr_data(str![[r#"
[MIGRATING] foo.rs from 2021 edition to 2024
[FIXED] foo.rs (1 fix)
[CHECKING] foo v0.0.0 ([ROOT]/foo)
[CHECKING] foo v0.0.0 ([ROOT]/foo/foo.rs)
[MIGRATING] [ROOT]/home/.cargo/target/[HASH]/foo.rs from 2021 edition to 2024
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/open_namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn main() {}
"edition": "2021",
"features": {},
"homepage": null,
"id": "path+[ROOTURL]/foo#foo::[email protected]",
"id": "path+[ROOTURL]/foo/foo::bar.rs#foo::[email protected]",
"keywords": [],
"license": null,
"license_file": null,
Expand Down
Loading
Loading