diff --git a/src/bin/cargo/commands/pkgid.rs b/src/bin/cargo/commands/pkgid.rs index 5fcf85b8fd9..aa98dc5c335 100644 --- a/src/bin/cargo/commands/pkgid.rs +++ b/src/bin/cargo/commands/pkgid.rs @@ -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)? } diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index a81c6b9304e..f5e95604385 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -269,10 +269,11 @@ impl<'gctx> Workspace<'gctx> { let mut ws = Workspace::new_default(package.manifest_path().to_path_buf(), gctx); ws.is_ephemeral = true; ws.require_optional_deps = require_optional_deps; - let key = ws.current_manifest.parent().unwrap(); let id = package.package_id(); let package = MaybePackage::Package(package); - ws.packages.packages.insert(key.to_path_buf(), package); + ws.packages + .packages + .insert(ws.current_manifest.clone(), package); ws.target_dir = if let Some(dir) = target_dir { Some(dir) } else { @@ -538,11 +539,7 @@ impl<'gctx> Workspace<'gctx> { /// Returns a mutable iterator over all packages in this workspace pub fn members_mut(&mut self) -> impl Iterator { let packages = &mut self.packages.packages; - let members: HashSet<_> = self - .members - .iter() - .map(|path| path.parent().unwrap().to_owned()) - .collect(); + let members: HashSet<_> = self.members.iter().map(|path| path).collect(); packages.iter_mut().filter_map(move |(path, package)| { if members.contains(path) { @@ -1159,7 +1156,6 @@ impl<'gctx> Workspace<'gctx> { pub fn emit_warnings(&self) -> CargoResult<()> { for (path, maybe_pkg) in &self.packages.packages { - let path = path.join("Cargo.toml"); if let MaybePackage::Package(pkg) = maybe_pkg { if self.gctx.cli_unstable().cargo_lints { self.emit_lints(pkg, &path)? @@ -1788,19 +1784,22 @@ impl<'gctx> Packages<'gctx> { } fn maybe_get(&self, manifest_path: &Path) -> Option<&MaybePackage> { - self.packages.get(manifest_path.parent().unwrap()) + self.packages.get(manifest_path) } fn maybe_get_mut(&mut self, manifest_path: &Path) -> Option<&mut MaybePackage> { - self.packages.get_mut(manifest_path.parent().unwrap()) + self.packages.get_mut(manifest_path) } fn load(&mut self, manifest_path: &Path) -> CargoResult<&MaybePackage> { - let key = manifest_path.parent().unwrap(); - match self.packages.entry(key.to_path_buf()) { + 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(key)?; + 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) => { diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 7765906977f..a38661ff9ad 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -124,6 +124,9 @@ impl<'gctx> PathSource<'gctx> { } fn read_package(&self) -> CargoResult { + if crate::util::toml::is_embedded(&self.path) { + anyhow::bail!("The embedded script cannot be used as a dependency"); + } let path = self.path.join("Cargo.toml"); let pkg = ops::read_package(&path, self.source_id, self.gctx)?; Ok(pkg) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index b001da4f85b..c61c902053b 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -182,8 +182,8 @@ fn depend_on_alt_registry_depends_on_crates_io() { [DOWNLOADED] bar v0.0.1 (registry `alternative`) [CHECKING] baz v0.0.1 [CHECKING] bar v0.0.1 (registry `alternative`) -[CHECKING] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[CHECKING] foo v0.0.1 ([ROOT]/foo) "#]] .unordered(), @@ -441,8 +441,8 @@ fn alt_registry_and_crates_io_deps() { [DOWNLOADED] alt_reg_dep v0.1.0 (registry `alternative`) [CHECKING] crates_io_dep v0.0.1 [CHECKING] alt_reg_dep v0.1.0 (registry `alternative`) -[CHECKING] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[CHECKING] foo v0.0.1 ([ROOT]/foo) "#]] .unordered(), diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 1912d61e859..fc4b8f63e4a 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -602,9 +602,9 @@ fn build_script_with_bin_artifacts() { .with_stderr_data( str![[r#" [LOCKING] 1 package to latest compatible version -[COMPILING] foo v0.0.0 ([ROOT]/foo) [COMPILING] bar v0.5.0 ([ROOT]/foo/bar) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[COMPILING] foo v0.0.0 ([ROOT]/foo) "#]] .unordered(), @@ -1433,7 +1433,6 @@ fn profile_override_basic() { str![[r#" [LOCKING] 1 package to latest compatible version [COMPILING] bar v0.5.0 ([ROOT]/foo/bar) -[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc --crate-name build_script_build [..] -C opt-level=1 [..]` [RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=3 [..]` [RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..] -C opt-level=1 [..]` @@ -1442,6 +1441,7 @@ fn profile_override_basic() { [RUNNING] `rustc --crate-name foo [..] -C opt-level=3 [..]` [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` [FINISHED] `dev` profile [optimized + debuginfo] target(s) in [ELAPSED]s +[COMPILING] foo v0.0.1 ([ROOT]/foo) "#]] .unordered(), @@ -1870,8 +1870,8 @@ fn allow_dep_renames_with_multiple_versions() { [DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) [COMPILING] bar v1.0.0 [COMPILING] bar v0.5.0 ([ROOT]/foo/bar) -[COMPILING] foo v0.0.0 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[COMPILING] foo v0.0.0 ([ROOT]/foo) "#]] .unordered(), @@ -2835,13 +2835,13 @@ fn with_assumed_host_target_and_optional_build_dep() { .with_stderr_data( str![[r#" [LOCKING] 1 package to latest compatible version -[COMPILING] foo v0.0.1 ([ROOT]/foo) [COMPILING] d1 v0.0.1 ([ROOT]/foo/d1) [RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..] [RUNNING] `rustc --crate-name d1 --edition=2021 [..]--crate-type bin[..] [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` [RUNNING] `rustc --crate-name foo --edition=2021 [..]--cfg[..]d1[..] [FINISHED] `dev` profile [..] +[COMPILING] foo v0.0.1 ([ROOT]/foo) "#]] .unordered(), @@ -3199,8 +3199,8 @@ fn decouple_same_target_transitive_dep_from_artifact_dep_and_proc_macro() { [COMPILING] b v0.1.0 ([ROOT]/foo/b) [COMPILING] c v0.1.0 ([ROOT]/foo/c) [COMPILING] bar v0.1.0 ([ROOT]/foo/bar) -[COMPILING] foo v0.1.0 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] +[COMPILING] foo v0.1.0 ([ROOT]/foo) "#]] .unordered(), diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index bf1b0da2a34..13b3a492d96 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1814,13 +1814,13 @@ fn workspace_default_features2() { p.cargo("check") .with_stderr_data( str![[r#" -[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition (in the `dep_workspace_only` dependency) [CHECKING] dep_package_only v0.1.0 ([ROOT]/foo/dep_package_only) [CHECKING] dep_workspace_only v0.1.0 ([ROOT]/foo/dep_workspace_only) [CHECKING] package_only v0.1.0 ([ROOT]/foo/package_only) [CHECKING] workspace_only v0.1.0 ([ROOT]/foo/workspace_only) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition "#]] .unordered(), diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index f475fe5ba21..f5635528a0a 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -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 diff --git a/tests/testsuite/open_namespaces.rs b/tests/testsuite/open_namespaces.rs index 6fc018f111e..c7506dfae65 100644 --- a/tests/testsuite/open_namespaces.rs +++ b/tests/testsuite/open_namespaces.rs @@ -289,7 +289,7 @@ fn main() {} "edition": "2021", "features": {}, "homepage": null, - "id": "path+[ROOTURL]/foo#foo::bar@0.0.0", + "id": "path+[ROOTURL]/foo/foo::bar.rs#foo::bar@0.0.0", "keywords": [], "license": null, "license_file": null, diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index 3c31c77f360..742315877d5 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -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]` @@ -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]` @@ -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]` @@ -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]` @@ -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]` @@ -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]` @@ -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]` @@ -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]` @@ -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` @@ -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` @@ -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` @@ -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]` @@ -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]` @@ -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]` @@ -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` @@ -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` @@ -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` @@ -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` @@ -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` @@ -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]` @@ -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]` @@ -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 "#]]) @@ -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 "#]]) @@ -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]) @@ -1091,7 +1091,7 @@ fn cmd_metadata_with_embedded() { "edition": "2024", "features": {}, "homepage": null, - "id": "path+[ROOTURL]/foo#script@0.0.0", + "id": "path+[ROOTURL]/foo/script.rs#script@0.0.0", "keywords": [], "license": null, "license_file": null, @@ -1129,18 +1129,18 @@ fn cmd_metadata_with_embedded() { "dependencies": [], "deps": [], "features": [], - "id": "path+[ROOTURL]/foo#script@0.0.0" + "id": "path+[ROOTURL]/foo/script.rs#script@0.0.0" } ], - "root": "path+[ROOTURL]/foo#script@0.0.0" + "root": "path+[ROOTURL]/foo/script.rs#script@0.0.0" }, "target_directory": "[ROOT]/home/.cargo/target/[HASH]", "version": 1, "workspace_default_members": [ - "path+[ROOTURL]/foo#script@0.0.0" + "path+[ROOTURL]/foo/script.rs#script@0.0.0" ], "workspace_members": [ - "path+[ROOTURL]/foo#script@0.0.0" + "path+[ROOTURL]/foo/script.rs#script@0.0.0" ], "workspace_root": "[ROOT]/foo" } @@ -1175,7 +1175,7 @@ fn cmd_read_manifest_with_embedded() { "edition": "2024", "features": {}, "homepage": null, - "id": "path+[ROOTURL]/foo#script@0.0.0", + "id": "path+[ROOTURL]/foo/script.rs#script@0.0.0", "keywords": [], "license": null, "license_file": null, @@ -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]` @@ -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#" @@ -1297,18 +1297,112 @@ fn cmd_verify_project_with_embedded() { .run(); } -#[cargo_test] +#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")] fn cmd_pkgid_with_embedded() { let p = cargo_test_support::project() .file("script.rs", ECHO_SCRIPT) .build(); + p.cargo("-Zscript script.rs") + .masquerade_as_nightly_cargo(&["script"]) + .run(); + + p.cargo("-Zscript pkgid --manifest-path script.rs") + .masquerade_as_nightly_cargo(&["script"]) + .with_stdout_data(str![[r#" +path+[ROOTURL]/foo/script.rs#script@0.0.0 + +"#]]) + .with_stderr_data(str![[r#" +[WARNING] `package.edition` is unspecified, defaulting to `2024` + +"#]]) + .run(); +} + +#[cargo_test] +fn cmd_pkgid_with_embedded_no_lock_file() { + let p = cargo_test_support::project() + .file("script.rs", ECHO_SCRIPT) + .build(); + p.cargo("-Zscript pkgid --manifest-path script.rs") .masquerade_as_nightly_cargo(&["script"]) .with_status(101) .with_stderr_data(str![[r#" [WARNING] `package.edition` is unspecified, defaulting to `2024` -[ERROR] [ROOT]/foo/script.rs is unsupported by `cargo pkgid` +[ERROR] a Cargo.lock must exist for this command + +"#]]) + .run(); +} + +#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")] +fn cmd_pkgid_with_embedded_dep() { + Package::new("dep", "1.0.0").publish(); + let script = r#"#!/usr/bin/env cargo +--- +[dependencies] +dep = "1.0.0" +--- + +fn main() { + println!("Hello world!"); +}"#; + let p = cargo_test_support::project() + .file("script.rs", script) + .build(); + + p.cargo("-Zscript script.rs") + .masquerade_as_nightly_cargo(&["script"]) + .run(); + + p.cargo("-Zscript pkgid --manifest-path script.rs -p dep") + .masquerade_as_nightly_cargo(&["script"]) + .with_stdout_data(str![[r#" +registry+https://github.com/rust-lang/crates.io-index#dep@1.0.0 + +"#]]) + .with_stderr_data(str![[r#" +[WARNING] `package.edition` is unspecified, defaulting to `2024` + +"#]]) + .run(); +} + +#[cargo_test(nightly, reason = "edition2024 hasn't hit stable yet")] +fn script_as_dep() { + let p = cargo_test_support::project() + .file("script.rs", ECHO_SCRIPT) + .file("src/lib.rs", "pub fn foo() {}") + .file( + "Cargo.toml", + r#" +[package] +name = "foo" +version = "0.1.0" + +[dependencies] +script.path = "script.rs" +"#, + ) + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo(&["script"]) + .with_status(101) + .with_stderr_data(str![[r#" +[WARNING] no edition set: defaulting to the 2015 edition while the latest is 2024 +[ERROR] failed to get `script` as a dependency of package `foo v0.1.0 ([ROOT]/foo)` + +Caused by: + failed to load source for dependency `script` + +Caused by: + Unable to update [ROOT]/foo/script.rs + +Caused by: + The embedded script cannot be used as a dependency "#]]) .run(); @@ -1370,7 +1464,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]`