Skip to content

Commit

Permalink
fix(package): Ensure we can package directories ending with '.rs' (#1…
Browse files Browse the repository at this point in the history
…5240)

### 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
  • Loading branch information
weihanglo committed Mar 1, 2025
1 parent fcb465c commit bdccfd8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 72 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bdccfd8

Please sign in to comment.