Skip to content

Commit

Permalink
feat: use full URL for embedded script paths
Browse files Browse the repository at this point in the history
Signed-off-by: Rustin170506 <[email protected]>
  • Loading branch information
Rustin170506 committed Jan 5, 2025
1 parent 0c2bb4e commit 4ce72a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
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()) {
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
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

0 comments on commit 4ce72a6

Please sign in to comment.