Skip to content

Commit d5b25b8

Browse files
authored
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 #14961 ### How should we test and review this PR? ### Additional information
2 parents 2622e84 + 730348a commit d5b25b8

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

src/cargo/util/toml/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ pub use embedded::ScriptSource;
4545
/// See also `bin/cargo/commands/run.rs`s `is_manifest_command`
4646
pub fn is_embedded(path: &Path) -> bool {
4747
let ext = path.extension();
48-
ext == Some(OsStr::new("rs")) ||
48+
(ext == Some(OsStr::new("rs")) ||
4949
// Provide better errors by not considering directories to be embedded manifests
50-
(ext.is_none() && path.is_file())
50+
ext.is_none())
51+
&& path.is_file()
5152
}
5253

5354
/// Loads a `Cargo.toml` from a file on disk.

tests/testsuite/package.rs

+72
Original file line numberDiff line numberDiff line change
@@ -6596,6 +6596,78 @@ fn workspace_with_renamed_member() {
65966596
.run();
65976597
}
65986598

6599+
#[cargo_test]
6600+
fn workspace_with_dot_rs_dir() {
6601+
let reg = registry::init();
6602+
6603+
let p = project()
6604+
.file(
6605+
"Cargo.toml",
6606+
r#"
6607+
[workspace]
6608+
members = ["crates/*"]
6609+
"#,
6610+
)
6611+
.file(
6612+
"crates/foo.rs/Cargo.toml",
6613+
r#"
6614+
[package]
6615+
name = "foo"
6616+
version = "0.16.2"
6617+
edition = "2015"
6618+
authors = []
6619+
license = "MIT"
6620+
description = "main"
6621+
repository = "bar"
6622+
6623+
[dependencies]
6624+
"#,
6625+
)
6626+
.file("crates/foo.rs/src/lib.rs", "pub fn foo() {}")
6627+
.file(
6628+
"crates/bar.rs/Cargo.toml",
6629+
r#"
6630+
[package]
6631+
name = "bar"
6632+
version = "0.16.2"
6633+
edition = "2015"
6634+
authors = []
6635+
license = "MIT"
6636+
description = "main"
6637+
repository = "bar"
6638+
6639+
[dependencies]
6640+
foo = { path = "../foo.rs", version = "0.16.2" }
6641+
"#,
6642+
)
6643+
.file("crates/bar.rs/src/lib.rs", "pub fn foo() {}")
6644+
.build();
6645+
6646+
p.cargo("package -Zpackage-workspace")
6647+
.masquerade_as_nightly_cargo(&["package-workspace"])
6648+
.replace_crates_io(reg.index_url())
6649+
.with_stderr_data(
6650+
str![[r#"
6651+
[PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
6652+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6653+
[PACKAGING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
6654+
[UPDATING] crates.io index
6655+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6656+
[VERIFYING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
6657+
[COMPILING] foo v0.16.2 ([ROOT]/foo/target/package/foo-0.16.2)
6658+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6659+
[VERIFYING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
6660+
[UNPACKING] foo v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
6661+
[COMPILING] foo v0.16.2
6662+
[COMPILING] bar v0.16.2 ([ROOT]/foo/target/package/bar-0.16.2)
6663+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6664+
6665+
"#]]
6666+
.unordered(),
6667+
)
6668+
.run();
6669+
}
6670+
65996671
#[cargo_test]
66006672
fn registry_not_in_publish_list() {
66016673
let p = project()

tests/testsuite/script.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ fn cmd_check_with_missing_script_rs() {
13581358
.with_status(101)
13591359
.with_stdout_data("")
13601360
.with_stderr_data(str![[r#"
1361-
[ERROR] manifest path `script.rs` does not exist
1361+
[ERROR] the manifest-path must be a path to a Cargo.toml file
13621362
13631363
"#]])
13641364
.run();

0 commit comments

Comments
 (0)