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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ impl<'gctx> Workspace<'gctx> {
ws.require_optional_deps = require_optional_deps;
let id = package.package_id();
let package = MaybePackage::Package(package);
ws.packages.packages.insert(ws.current_manifest.clone(), package);
ws.packages
.packages
.insert(ws.current_manifest.clone(), package);
ws.target_dir = if let Some(dir) = target_dir {
Comment on lines +274 to 277
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this reformatting belong on the previous commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. I squashed it into the wrong commit.

Some(dir)
} else {
Expand Down Expand Up @@ -1793,7 +1795,11 @@ impl<'gctx> Packages<'gctx> {
match self.packages.entry(manifest_path.to_path_buf()) {
Entry::Occupied(e) => Ok(e.into_mut()),
Entry::Vacant(v) => {
let source_id = SourceId::for_path(manifest_path.parent().unwrap())?;
let source_id = if crate::util::toml::is_embedded(manifest_path) {
SourceId::for_path(manifest_path)?
} else {
SourceId::for_path(manifest_path.parent().unwrap())?
};
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
69 changes: 34 additions & 35 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`

Expand All @@ -63,7 +63,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`

Expand Down Expand Up @@ -117,7 +117,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] echo v0.0.0 ([ROOT]/foo)
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`

Expand Down Expand Up @@ -204,7 +204,7 @@ Hello world!

"#]])
.with_stderr_data(str![[r#"
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down Expand Up @@ -234,7 +234,7 @@ Hello world!
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down Expand Up @@ -262,7 +262,7 @@ msg = undefined
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down Expand Up @@ -294,7 +294,7 @@ msg = hello
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down Expand Up @@ -422,7 +422,7 @@ line: 4
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand All @@ -446,7 +446,7 @@ args: ["-NotAnArg"]
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`

Expand All @@ -470,7 +470,7 @@ args: ["-NotAnArg"]
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`

Expand All @@ -494,7 +494,7 @@ args: ["--help"]
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand All @@ -518,7 +518,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo)
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo/s-h.w§c!.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/s-h-w-c-[EXE]`

Expand All @@ -542,7 +542,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] answer v0.0.0 ([ROOT]/foo)
[COMPILING] answer v0.0.0 ([ROOT]/foo/42answer.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/answer[EXE]`

Expand All @@ -564,7 +564,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] package v0.0.0 ([ROOT]/foo)
[COMPILING] package v0.0.0 ([ROOT]/foo/42.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/package[EXE]`

Expand Down Expand Up @@ -715,7 +715,7 @@ Hello world!
[DOWNLOADING] crates ...
[DOWNLOADED] script v1.0.0 (registry `dummy-registry`)
[COMPILING] script v1.0.0
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand Down Expand Up @@ -751,7 +751,7 @@ Hello world!
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[LOCKING] 1 package to latest Rust [..] compatible version
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand Down Expand Up @@ -779,7 +779,7 @@ Hello world!
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand Down Expand Up @@ -807,7 +807,7 @@ Hello world!
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand Down Expand Up @@ -835,7 +835,7 @@ Hello world!
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`

Expand All @@ -859,7 +859,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand All @@ -886,7 +886,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down Expand Up @@ -943,7 +943,7 @@ fn cmd_check_with_embedded() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[CHECKING] script v0.0.0 ([ROOT]/foo)
[CHECKING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
Expand Down Expand Up @@ -992,7 +992,7 @@ fn cmd_build_with_embedded() {
.with_stdout_data("")
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
Expand All @@ -1019,7 +1019,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests script.rs ([ROOT]/home/.cargo/target/[HASH]/debug/deps/script-[HASH][EXE])

Expand Down Expand Up @@ -1091,7 +1091,7 @@ fn cmd_metadata_with_embedded() {
"edition": "2024",
"features": {},
"homepage": null,
"id": "path+[ROOTURL]/foo#[email protected]",
"id": "path+[ROOTURL]/foo/script.rs#[email protected]",
"keywords": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -1129,18 +1129,18 @@ fn cmd_metadata_with_embedded() {
"dependencies": [],
"deps": [],
"features": [],
"id": "path+[ROOTURL]/foo#[email protected]"
"id": "path+[ROOTURL]/foo/script.rs#[email protected]"
}
],
"root": "path+[ROOTURL]/foo#[email protected]"
"root": "path+[ROOTURL]/foo/script.rs#[email protected]"
},
"target_directory": "[ROOT]/home/.cargo/target/[HASH]",
"version": 1,
"workspace_default_members": [
"path+[ROOTURL]/foo#[email protected]"
"path+[ROOTURL]/foo/script.rs#[email protected]"
],
"workspace_members": [
"path+[ROOTURL]/foo#[email protected]"
"path+[ROOTURL]/foo/script.rs#[email protected]"
],
"workspace_root": "[ROOT]/foo"
}
Expand Down Expand Up @@ -1175,7 +1175,7 @@ fn cmd_read_manifest_with_embedded() {
"edition": "2024",
"features": {},
"homepage": null,
"id": "path+[ROOTURL]/foo#[email protected]",
"id": "path+[ROOTURL]/foo/script.rs#[email protected]",
"keywords": [],
"license": null,
"license_file": null,
Expand Down Expand Up @@ -1231,7 +1231,7 @@ args: []
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand All @@ -1248,7 +1248,7 @@ fn cmd_tree_with_embedded() {
p.cargo("-Zscript tree --manifest-path script.rs")
.masquerade_as_nightly_cargo(&["script"])
.with_stdout_data(str![[r#"
script v0.0.0 ([ROOT]/foo)
script v0.0.0 ([ROOT]/foo/script.rs)

"#]])
.with_stderr_data(str![[r#"
Expand Down Expand Up @@ -1307,11 +1307,10 @@ fn cmd_pkgid_with_embedded() {
.masquerade_as_nightly_cargo(&["script"])
.run();

// FIXME: It should be `path+[ROOTURL]/foo/script.rs#[email protected]`.
p.cargo("-Zscript pkgid --manifest-path script.rs")
.masquerade_as_nightly_cargo(&["script"])
.with_stdout_data(str![[r#"
path+[ROOTURL]/foo#[email protected]
path+[ROOTURL]/foo/script.rs#[email protected]

"#]])
.with_stderr_data(str![[r#"
Expand Down Expand Up @@ -1427,7 +1426,7 @@ CARGO_MANIFEST_PATH: [ROOT]/foo/script.rs
"#]])
.with_stderr_data(str![[r#"
[WARNING] `package.edition` is unspecified, defaulting to `2024`
[COMPILING] script v0.0.0 ([ROOT]/foo)
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`

Expand Down