Skip to content

Commit f05ca4f

Browse files
committed
Auto merge of #12135 - eval-exec:fix-check_for_file_and_add, r=weihanglo
Fix `check_for_file_and_add`'s check for conflict file ### What does this PR try to resolve? Fixes #12127 ### How should we test and review this PR? - [x] two unit tests
2 parents 628b81e + e906797 commit f05ca4f

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ fn check_for_file_and_add(
332332
Err(_) => {
333333
// The file exists somewhere outside of the package.
334334
let file_name = file_path.file_name().unwrap();
335-
if result
336-
.iter()
337-
.any(|ar| ar.rel_path.file_name().unwrap() == file_name)
338-
{
335+
if result.iter().any(|ar| ar.rel_path == file_name) {
339336
ws.config().shell().warn(&format!(
340337
"{} `{}` appears to be a path outside of the package, \
341338
but there is already a file named `{}` in the root of the package. \

tests/testsuite/package.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,91 @@ See [..]
25352535
assert!(p.root().join("target/package/bar-0.0.1.crate").is_file());
25362536
}
25372537

2538+
#[cargo_test]
2539+
fn workspace_noconflict_readme() {
2540+
let p = project()
2541+
.file(
2542+
"Cargo.toml",
2543+
r#"
2544+
[workspace]
2545+
members = ["bar"]
2546+
"#,
2547+
)
2548+
.file("README.md", "workspace readme")
2549+
.file(
2550+
"bar/Cargo.toml",
2551+
r#"
2552+
[package]
2553+
name = "bar"
2554+
version = "0.0.1"
2555+
repository = "https://github.com/bar/bar"
2556+
authors = []
2557+
license = "MIT"
2558+
description = "bar"
2559+
readme = "../README.md"
2560+
workspace = ".."
2561+
"#,
2562+
)
2563+
.file("bar/src/main.rs", "fn main() {}")
2564+
.file("bar/example/README.md", "# example readmdBar")
2565+
.build();
2566+
2567+
p.cargo("package")
2568+
.with_stderr(
2569+
"\
2570+
[PACKAGING] bar v0.0.1 ([CWD]/bar)
2571+
[VERIFYING] bar v0.0.1 ([CWD]/bar)
2572+
[COMPILING] bar v0.0.1 ([CWD]/[..])
2573+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2574+
[PACKAGED] [..] files, [..] ([..] compressed)
2575+
",
2576+
)
2577+
.run();
2578+
}
2579+
2580+
#[cargo_test]
2581+
fn workspace_conflict_readme() {
2582+
let p = project()
2583+
.file(
2584+
"Cargo.toml",
2585+
r#"
2586+
[workspace]
2587+
members = ["bar"]
2588+
"#,
2589+
)
2590+
.file("README.md", "workspace readme")
2591+
.file(
2592+
"bar/Cargo.toml",
2593+
r#"
2594+
[package]
2595+
name = "bar"
2596+
version = "0.0.1"
2597+
repository = "https://github.com/bar/bar"
2598+
authors = []
2599+
license = "MIT"
2600+
description = "bar"
2601+
readme = "../README.md"
2602+
workspace = ".."
2603+
"#,
2604+
)
2605+
.file("bar/src/main.rs", "fn main() {}")
2606+
.file("bar/README.md", "# workspace member: Bar")
2607+
.build();
2608+
2609+
p.cargo("package")
2610+
.with_stderr(
2611+
"\
2612+
warning: readme `../README.md` appears to be a path outside of the package, but there is already a file named `README.md` in the root of the package. The archived crate will contain the copy in the root of the package. Update the readme to point to the path relative to the root of the package to remove this warning.
2613+
[PACKAGING] bar v0.0.1 ([CWD]/bar)
2614+
[VERIFYING] bar v0.0.1 ([CWD]/bar)
2615+
[COMPILING] bar v0.0.1 ([CWD]/[..])
2616+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2617+
[PACKAGED] [..] files, [..] ([..] compressed)
2618+
",
2619+
)
2620+
.run();
2621+
}
2622+
25382623
#[cargo_test]
25392624
fn workspace_overrides_resolver() {
25402625
let p = project()

0 commit comments

Comments
 (0)