From bdccfd802174ba043e172cf8192e1fca70a6a91c Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 28 Feb 2025 13:17:40 +0000 Subject: [PATCH] fix(package): Ensure we can package directories ending with '.rs' (#15240) ### What does this PR try to resolve? This likely only affects `-Zpackage-workspace` but it might have also broken dependencies whose path ends with `.rs` as well This broke in https://github.com/rust-lang/cargo/pull/14961 ### How should we test and review this PR? ### Additional information --- src/cargo/util/toml/mod.rs | 5 +-- tests/testsuite/package.rs | 72 ++++++++++++++++++++++++++++++++++++++ tests/testsuite/script.rs | 2 +- 3 files changed, 76 insertions(+), 3 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 ae1c5d71024..ae4de6e2938 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6430,6 +6430,78 @@ fn workspace_with_local_and_remote_deps() { .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_stderr_data( + str![[r#" +[PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs) +[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(), + ) + .run(); +} + #[cargo_test] fn registry_not_in_publish_list() { let p = project() 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();