From 45da135dba102c8c1cfd6df2ea631faaf4a7500c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 27 Feb 2025 14:46:05 -0600 Subject: [PATCH 1/2] test(package): Show cargo script mistaken identity --- tests/testsuite/package.rs | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 0263607449c..0c8a6c1ae51 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6596,6 +6596,74 @@ fn workspace_with_renamed_member() { .run(); } +#[cargo_test] +fn workspace_with_dot_rs_dir() { + let reg = registry::init(); + + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["crates/*"] + "#, + ) + .file( + "crates/foo.rs/Cargo.toml", + r#" + [package] + name = "foo" + version = "0.16.2" + edition = "2015" + authors = [] + license = "MIT" + description = "main" + repository = "bar" + + [dependencies] + "#, + ) + .file("crates/foo.rs/src/lib.rs", "pub fn foo() {}") + .file( + "crates/bar.rs/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.16.2" + edition = "2015" + authors = [] + license = "MIT" + description = "main" + repository = "bar" + + [dependencies] + foo = { path = "../foo.rs", version = "0.16.2" } + "#, + ) + .file("crates/bar.rs/src/lib.rs", "pub fn foo() {}") + .build(); + + p.cargo("package -Zpackage-workspace") + .masquerade_as_nightly_cargo(&["package-workspace"]) + .replace_crates_io(reg.index_url()) + .with_status(101) + .with_stderr_data( + str![[r#" +[PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs) +[ERROR] failed to prepare local package for uploading + +Caused by: + Unable to update [ROOT]/foo/crates/foo.rs + +Caused by: + Single file packages cannot be used as dependencies + +"#]] + .unordered(), + ) + .run(); +} + #[cargo_test] fn registry_not_in_publish_list() { let p = project() From 730348ada92a10c2a055284d835244267ceeebab Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 27 Feb 2025 14:50:56 -0600 Subject: [PATCH 2/2] fix(package): Ensure we can package directories ending with '.rs' This might have also broken dependencies whose path ends with `.rs` as well This broke in #14961 --- src/cargo/util/toml/mod.rs | 5 +++-- tests/testsuite/package.rs | 20 ++++++++++++-------- tests/testsuite/script.rs | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 85aeb8697a7..9459fc6c37b 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -45,9 +45,10 @@ pub use embedded::ScriptSource; /// See also `bin/cargo/commands/run.rs`s `is_manifest_command` pub fn is_embedded(path: &Path) -> bool { let ext = path.extension(); - ext == Some(OsStr::new("rs")) || + (ext == Some(OsStr::new("rs")) || // Provide better errors by not considering directories to be embedded manifests - (ext.is_none() && path.is_file()) + ext.is_none()) + && path.is_file() } /// Loads a `Cargo.toml` from a file on disk. diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 0c8a6c1ae51..0d2244234c1 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6646,17 +6646,21 @@ fn workspace_with_dot_rs_dir() { p.cargo("package -Zpackage-workspace") .masquerade_as_nightly_cargo(&["package-workspace"]) .replace_crates_io(reg.index_url()) - .with_status(101) .with_stderr_data( str![[r#" [PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs) -[ERROR] failed to prepare local package for uploading - -Caused by: - Unable to update [ROOT]/foo/crates/foo.rs - -Caused by: - Single file packages cannot be used as dependencies +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[PACKAGING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs) +[UPDATING] crates.io index +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs) +[COMPILING] foo v0.16.2 ([ROOT]/foo/target/package/foo-0.16.2) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[VERIFYING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs) +[UNPACKING] foo v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`) +[COMPILING] foo v0.16.2 +[COMPILING] bar v0.16.2 ([ROOT]/foo/target/package/bar-0.16.2) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]] .unordered(), diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index 5c6a46bb271..20fa7bcb3fb 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -1358,7 +1358,7 @@ fn cmd_check_with_missing_script_rs() { .with_status(101) .with_stdout_data("") .with_stderr_data(str![[r#" -[ERROR] manifest path `script.rs` does not exist +[ERROR] the manifest-path must be a path to a Cargo.toml file "#]]) .run();