Skip to content

Commit bdccfd8

Browse files
committed
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
1 parent fcb465c commit bdccfd8

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
@@ -6430,6 +6430,78 @@ fn workspace_with_local_and_remote_deps() {
64306430
.run();
64316431
}
64326432

6433+
#[cargo_test]
6434+
fn workspace_with_dot_rs_dir() {
6435+
let reg = registry::init();
6436+
6437+
let p = project()
6438+
.file(
6439+
"Cargo.toml",
6440+
r#"
6441+
[workspace]
6442+
members = ["crates/*"]
6443+
"#,
6444+
)
6445+
.file(
6446+
"crates/foo.rs/Cargo.toml",
6447+
r#"
6448+
[package]
6449+
name = "foo"
6450+
version = "0.16.2"
6451+
edition = "2015"
6452+
authors = []
6453+
license = "MIT"
6454+
description = "main"
6455+
repository = "bar"
6456+
6457+
[dependencies]
6458+
"#,
6459+
)
6460+
.file("crates/foo.rs/src/lib.rs", "pub fn foo() {}")
6461+
.file(
6462+
"crates/bar.rs/Cargo.toml",
6463+
r#"
6464+
[package]
6465+
name = "bar"
6466+
version = "0.16.2"
6467+
edition = "2015"
6468+
authors = []
6469+
license = "MIT"
6470+
description = "main"
6471+
repository = "bar"
6472+
6473+
[dependencies]
6474+
foo = { path = "../foo.rs", version = "0.16.2" }
6475+
"#,
6476+
)
6477+
.file("crates/bar.rs/src/lib.rs", "pub fn foo() {}")
6478+
.build();
6479+
6480+
p.cargo("package -Zpackage-workspace")
6481+
.masquerade_as_nightly_cargo(&["package-workspace"])
6482+
.replace_crates_io(reg.index_url())
6483+
.with_stderr_data(
6484+
str![[r#"
6485+
[PACKAGING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
6486+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6487+
[PACKAGING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
6488+
[UPDATING] crates.io index
6489+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
6490+
[VERIFYING] foo v0.16.2 ([ROOT]/foo/crates/foo.rs)
6491+
[COMPILING] foo v0.16.2 ([ROOT]/foo/target/package/foo-0.16.2)
6492+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6493+
[VERIFYING] bar v0.16.2 ([ROOT]/foo/crates/bar.rs)
6494+
[UNPACKING] foo v0.16.2 (registry `[ROOT]/foo/target/package/tmp-registry`)
6495+
[COMPILING] foo v0.16.2
6496+
[COMPILING] bar v0.16.2 ([ROOT]/foo/target/package/bar-0.16.2)
6497+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
6498+
6499+
"#]]
6500+
.unordered(),
6501+
)
6502+
.run();
6503+
}
6504+
64336505
#[cargo_test]
64346506
fn registry_not_in_publish_list() {
64356507
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)