Skip to content

Commit 95f6d0b

Browse files
committed
feat: use full URL for embedded script paths
Signed-off-by: Rustin170506 <[email protected]>
1 parent d4c1eee commit 95f6d0b

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

src/cargo/core/workspace.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,11 @@ impl<'gctx> Packages<'gctx> {
17951795
match self.packages.entry(manifest_path.to_path_buf()) {
17961796
Entry::Occupied(e) => Ok(e.into_mut()),
17971797
Entry::Vacant(v) => {
1798-
let source_id = SourceId::for_path(manifest_path.parent().unwrap())?;
1798+
let source_id = if crate::util::toml::is_embedded(manifest_path) {
1799+
SourceId::for_path(manifest_path)?
1800+
} else {
1801+
SourceId::for_path(manifest_path.parent().unwrap())?
1802+
};
17991803
let manifest = read_manifest(manifest_path, source_id, self.gctx)?;
18001804
Ok(v.insert(match manifest {
18011805
EitherManifest::Real(manifest) => {

tests/testsuite/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,7 @@ fn main() {
24792479
.with_stderr_data(str![[r#"
24802480
[MIGRATING] foo.rs from 2021 edition to 2024
24812481
[FIXED] foo.rs (1 fix)
2482-
[CHECKING] foo v0.0.0 ([ROOT]/foo)
2482+
[CHECKING] foo v0.0.0 ([ROOT]/foo/foo.rs)
24832483
[MIGRATING] [ROOT]/home/.cargo/target/[HASH]/foo.rs from 2021 edition to 2024
24842484
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
24852485

tests/testsuite/open_namespaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn main() {}
289289
"edition": "2021",
290290
"features": {},
291291
"homepage": null,
292-
"id": "path+[ROOTURL]/foo#foo::[email protected]",
292+
"id": "path+[ROOTURL]/foo/foo::bar.rs#foo::[email protected]",
293293
"keywords": [],
294294
"license": null,
295295
"license_file": null,

tests/testsuite/script.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ args: []
4040
"#]])
4141
.with_stderr_data(str![[r#"
4242
[WARNING] `package.edition` is unspecified, defaulting to `2024`
43-
[COMPILING] echo v0.0.0 ([ROOT]/foo)
43+
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
4444
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
4545
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
4646
@@ -63,7 +63,7 @@ args: []
6363
"#]])
6464
.with_stderr_data(str![[r#"
6565
[WARNING] `package.edition` is unspecified, defaulting to `2024`
66-
[COMPILING] echo v0.0.0 ([ROOT]/foo)
66+
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo)
6767
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6868
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
6969
@@ -117,7 +117,7 @@ args: []
117117
"#]])
118118
.with_stderr_data(str![[r#"
119119
[WARNING] `package.edition` is unspecified, defaulting to `2024`
120-
[COMPILING] echo v0.0.0 ([ROOT]/foo)
120+
[COMPILING] echo v0.0.0 ([ROOT]/foo/echo.rs)
121121
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
122122
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/echo[EXE]`
123123
@@ -204,7 +204,7 @@ Hello world!
204204
205205
"#]])
206206
.with_stderr_data(str![[r#"
207-
[COMPILING] script v0.0.0 ([ROOT]/foo)
207+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
208208
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
209209
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
210210
@@ -234,7 +234,7 @@ Hello world!
234234
"#]])
235235
.with_stderr_data(str![[r#"
236236
[WARNING] `package.edition` is unspecified, defaulting to `2024`
237-
[COMPILING] script v0.0.0 ([ROOT]/foo)
237+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
238238
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
239239
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
240240
@@ -262,7 +262,7 @@ msg = undefined
262262
"#]])
263263
.with_stderr_data(str![[r#"
264264
[WARNING] `package.edition` is unspecified, defaulting to `2024`
265-
[COMPILING] script v0.0.0 ([ROOT]/foo)
265+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
266266
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
267267
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
268268
@@ -294,7 +294,7 @@ msg = hello
294294
"#]])
295295
.with_stderr_data(str![[r#"
296296
[WARNING] `package.edition` is unspecified, defaulting to `2024`
297-
[COMPILING] script v0.0.0 ([ROOT]/foo)
297+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
298298
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
299299
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
300300
@@ -422,7 +422,7 @@ line: 4
422422
"#]])
423423
.with_stderr_data(str![[r#"
424424
[WARNING] `package.edition` is unspecified, defaulting to `2024`
425-
[COMPILING] script v0.0.0 ([ROOT]/foo)
425+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
426426
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
427427
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
428428
@@ -446,7 +446,7 @@ args: ["-NotAnArg"]
446446
"#]])
447447
.with_stderr_data(str![[r#"
448448
[WARNING] `package.edition` is unspecified, defaulting to `2024`
449-
[COMPILING] script v0.0.0 ([ROOT]/foo)
449+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
450450
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
451451
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`
452452
@@ -470,7 +470,7 @@ args: ["-NotAnArg"]
470470
"#]])
471471
.with_stderr_data(str![[r#"
472472
[WARNING] `package.edition` is unspecified, defaulting to `2024`
473-
[COMPILING] script v0.0.0 ([ROOT]/foo)
473+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
474474
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
475475
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] -NotAnArg`
476476
@@ -494,7 +494,7 @@ args: ["--help"]
494494
"#]])
495495
.with_stderr_data(str![[r#"
496496
[WARNING] `package.edition` is unspecified, defaulting to `2024`
497-
[COMPILING] script v0.0.0 ([ROOT]/foo)
497+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
498498
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
499499
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
500500
@@ -518,7 +518,7 @@ args: []
518518
"#]])
519519
.with_stderr_data(str![[r#"
520520
[WARNING] `package.edition` is unspecified, defaulting to `2024`
521-
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo)
521+
[COMPILING] s-h-w-c- v0.0.0 ([ROOT]/foo/s-h.w§c!.rs)
522522
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
523523
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/s-h-w-c-[EXE]`
524524
@@ -542,7 +542,7 @@ args: []
542542
"#]])
543543
.with_stderr_data(str![[r#"
544544
[WARNING] `package.edition` is unspecified, defaulting to `2024`
545-
[COMPILING] answer v0.0.0 ([ROOT]/foo)
545+
[COMPILING] answer v0.0.0 ([ROOT]/foo/42answer.rs)
546546
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
547547
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/answer[EXE]`
548548
@@ -564,7 +564,7 @@ args: []
564564
"#]])
565565
.with_stderr_data(str![[r#"
566566
[WARNING] `package.edition` is unspecified, defaulting to `2024`
567-
[COMPILING] package v0.0.0 ([ROOT]/foo)
567+
[COMPILING] package v0.0.0 ([ROOT]/foo/42.rs)
568568
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
569569
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/package[EXE]`
570570
@@ -715,7 +715,7 @@ Hello world!
715715
[DOWNLOADING] crates ...
716716
[DOWNLOADED] script v1.0.0 (registry `dummy-registry`)
717717
[COMPILING] script v1.0.0
718-
[COMPILING] script v0.0.0 ([ROOT]/foo)
718+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
719719
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
720720
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
721721
@@ -751,7 +751,7 @@ Hello world!
751751
[WARNING] `package.edition` is unspecified, defaulting to `2024`
752752
[LOCKING] 1 package to latest Rust [..] compatible version
753753
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
754-
[COMPILING] script v0.0.0 ([ROOT]/foo)
754+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
755755
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
756756
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
757757
@@ -779,7 +779,7 @@ Hello world!
779779
"#]])
780780
.with_stderr_data(str![[r#"
781781
[WARNING] `package.edition` is unspecified, defaulting to `2024`
782-
[COMPILING] script v0.0.0 ([ROOT]/foo)
782+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
783783
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
784784
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
785785
@@ -807,7 +807,7 @@ Hello world!
807807
"#]])
808808
.with_stderr_data(str![[r#"
809809
[WARNING] `package.edition` is unspecified, defaulting to `2024`
810-
[COMPILING] script v0.0.0 ([ROOT]/foo)
810+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
811811
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
812812
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
813813
@@ -835,7 +835,7 @@ Hello world!
835835
"#]])
836836
.with_stderr_data(str![[r#"
837837
[WARNING] `package.edition` is unspecified, defaulting to `2024`
838-
[COMPILING] script v0.0.0 ([ROOT]/foo)
838+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
839839
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
840840
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE] --help`
841841
@@ -859,7 +859,7 @@ args: []
859859
"#]])
860860
.with_stderr_data(str![[r#"
861861
[WARNING] `package.edition` is unspecified, defaulting to `2024`
862-
[COMPILING] script v0.0.0 ([ROOT]/foo)
862+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
863863
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
864864
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
865865
@@ -886,7 +886,7 @@ args: []
886886
"#]])
887887
.with_stderr_data(str![[r#"
888888
[WARNING] `package.edition` is unspecified, defaulting to `2024`
889-
[COMPILING] script v0.0.0 ([ROOT]/foo)
889+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
890890
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
891891
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
892892
@@ -943,7 +943,7 @@ fn cmd_check_with_embedded() {
943943
.with_stdout_data("")
944944
.with_stderr_data(str![[r#"
945945
[WARNING] `package.edition` is unspecified, defaulting to `2024`
946-
[CHECKING] script v0.0.0 ([ROOT]/foo)
946+
[CHECKING] script v0.0.0 ([ROOT]/foo/script.rs)
947947
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
948948
949949
"#]])
@@ -992,7 +992,7 @@ fn cmd_build_with_embedded() {
992992
.with_stdout_data("")
993993
.with_stderr_data(str![[r#"
994994
[WARNING] `package.edition` is unspecified, defaulting to `2024`
995-
[COMPILING] script v0.0.0 ([ROOT]/foo)
995+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
996996
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
997997
998998
"#]])
@@ -1019,7 +1019,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
10191019
"#]])
10201020
.with_stderr_data(str![[r#"
10211021
[WARNING] `package.edition` is unspecified, defaulting to `2024`
1022-
[COMPILING] script v0.0.0 ([ROOT]/foo)
1022+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
10231023
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10241024
[RUNNING] unittests script.rs ([ROOT]/home/.cargo/target/[HASH]/debug/deps/script-[HASH][EXE])
10251025
@@ -1091,7 +1091,7 @@ fn cmd_metadata_with_embedded() {
10911091
"edition": "2024",
10921092
"features": {},
10931093
"homepage": null,
1094-
"id": "path+[ROOTURL]/foo#[email protected]",
1094+
"id": "path+[ROOTURL]/foo/script.rs#[email protected]",
10951095
"keywords": [],
10961096
"license": null,
10971097
"license_file": null,
@@ -1129,18 +1129,18 @@ fn cmd_metadata_with_embedded() {
11291129
"dependencies": [],
11301130
"deps": [],
11311131
"features": [],
1132-
"id": "path+[ROOTURL]/foo#[email protected]"
1132+
"id": "path+[ROOTURL]/foo/script.rs#[email protected]"
11331133
}
11341134
],
1135-
"root": "path+[ROOTURL]/foo#[email protected]"
1135+
"root": "path+[ROOTURL]/foo/script.rs#[email protected]"
11361136
},
11371137
"target_directory": "[ROOT]/home/.cargo/target/[HASH]",
11381138
"version": 1,
11391139
"workspace_default_members": [
1140-
"path+[ROOTURL]/foo#[email protected]"
1140+
"path+[ROOTURL]/foo/script.rs#[email protected]"
11411141
],
11421142
"workspace_members": [
1143-
"path+[ROOTURL]/foo#[email protected]"
1143+
"path+[ROOTURL]/foo/script.rs#[email protected]"
11441144
],
11451145
"workspace_root": "[ROOT]/foo"
11461146
}
@@ -1175,7 +1175,7 @@ fn cmd_read_manifest_with_embedded() {
11751175
"edition": "2024",
11761176
"features": {},
11771177
"homepage": null,
1178-
"id": "path+[ROOTURL]/foo#[email protected]",
1178+
"id": "path+[ROOTURL]/foo/script.rs#[email protected]",
11791179
"keywords": [],
11801180
"license": null,
11811181
"license_file": null,
@@ -1231,7 +1231,7 @@ args: []
12311231
"#]])
12321232
.with_stderr_data(str![[r#"
12331233
[WARNING] `package.edition` is unspecified, defaulting to `2024`
1234-
[COMPILING] script v0.0.0 ([ROOT]/foo)
1234+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
12351235
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
12361236
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
12371237
@@ -1248,7 +1248,7 @@ fn cmd_tree_with_embedded() {
12481248
p.cargo("-Zscript tree --manifest-path script.rs")
12491249
.masquerade_as_nightly_cargo(&["script"])
12501250
.with_stdout_data(str![[r#"
1251-
script v0.0.0 ([ROOT]/foo)
1251+
script v0.0.0 ([ROOT]/foo/script.rs)
12521252
12531253
"#]])
12541254
.with_stderr_data(str![[r#"
@@ -1307,11 +1307,10 @@ fn cmd_pkgid_with_embedded() {
13071307
.masquerade_as_nightly_cargo(&["script"])
13081308
.run();
13091309

1310-
// FIXME: It should be `path+[ROOTURL]/foo/script.rs#[email protected]`.
13111310
p.cargo("-Zscript pkgid --manifest-path script.rs")
13121311
.masquerade_as_nightly_cargo(&["script"])
13131312
.with_stdout_data(str![[r#"
1314-
path+[ROOTURL]/foo#[email protected]
1313+
path+[ROOTURL]/foo/script.rs#[email protected]
13151314
13161315
"#]])
13171316
.with_stderr_data(str![[r#"
@@ -1427,7 +1426,7 @@ CARGO_MANIFEST_PATH: [ROOT]/foo/script.rs
14271426
"#]])
14281427
.with_stderr_data(str![[r#"
14291428
[WARNING] `package.edition` is unspecified, defaulting to `2024`
1430-
[COMPILING] script v0.0.0 ([ROOT]/foo)
1429+
[COMPILING] script v0.0.0 ([ROOT]/foo/script.rs)
14311430
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
14321431
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]`
14331432

0 commit comments

Comments
 (0)