Skip to content

Commit 90753b6

Browse files
committed
fix: Nomarlize the relative path for all targets
1 parent f4f90c6 commit 90753b6

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/cargo/util/toml/mod.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ pub fn to_real_manifest(
12981298
// If we have no lib at all, use the inferred lib, if available.
12991299
// If we have a lib with a path, we're done.
13001300
// If we have a lib with no path, use the inferred lib or else the package name.
1301-
let targets = to_targets(
1301+
let mut targets = to_targets(
13021302
&features,
13031303
&original_toml,
13041304
&normalized_toml,
@@ -1308,6 +1308,13 @@ pub fn to_real_manifest(
13081308
warnings,
13091309
)?;
13101310

1311+
// Normalize the targets paths
1312+
for target in targets.iter_mut() {
1313+
if let TargetSourcePath::Path(path) = target.src_path() {
1314+
target.set_src_path(TargetSourcePath::Path(normalize_path(path)));
1315+
}
1316+
}
1317+
13111318
if targets.iter().all(|t| t.is_custom_build()) {
13121319
bail!(
13131320
"no targets specified in the manifest\n\
@@ -3016,8 +3023,12 @@ pub fn prepare_target_for_publish(
30163023
context: &str,
30173024
gctx: &GlobalContext,
30183025
) -> CargoResult<Option<manifest::TomlTarget>> {
3019-
let path = target.path.as_ref().expect("previously normalized");
3020-
let path = normalize_path(&path.0);
3026+
let path = target
3027+
.path
3028+
.as_ref()
3029+
.expect("previously normalized")
3030+
.0
3031+
.clone();
30213032
if let Some(packaged_files) = packaged_files {
30223033
if !packaged_files.contains(&path) {
30233034
let name = target.name.as_ref().expect("previously normalized");

tests/testsuite/binary_name.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fn targets_with_relative_path_in_workspace_members() {
414414
.with_stderr_data(str![[r#"
415415
[COMPILING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
416416
[WARNING] unused variable: `a`
417-
--> relative-bar/./build.rs:1:17
417+
--> relative-bar/build.rs:1:17
418418
|
419419
1 | fn main() { let a = 1; }
420420
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -423,7 +423,7 @@ fn targets_with_relative_path_in_workspace_members() {
423423
424424
[WARNING] `relative-bar` (build script) generated 1 warning
425425
[WARNING] function `a` is never used
426-
--> relative-bar/./src/lib.rs:1:4
426+
--> relative-bar/src/lib.rs:1:4
427427
|
428428
1 | fn a() {}
429429
| ^
@@ -432,7 +432,7 @@ fn targets_with_relative_path_in_workspace_members() {
432432
433433
[WARNING] `relative-bar` (lib) generated 1 warning
434434
[WARNING] unused variable: `a`
435-
--> relative-bar/./src/main.rs:1:17
435+
--> relative-bar/src/main.rs:1:17
436436
|
437437
1 | fn main() { let a = 1; }
438438
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -448,7 +448,7 @@ fn targets_with_relative_path_in_workspace_members() {
448448
p.cargo("check --example example")
449449
.with_stderr_data(str![[r#"
450450
[WARNING] unused variable: `a`
451-
--> relative-bar/./build.rs:1:17
451+
--> relative-bar/build.rs:1:17
452452
|
453453
1 | fn main() { let a = 1; }
454454
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -457,7 +457,7 @@ fn targets_with_relative_path_in_workspace_members() {
457457
458458
[WARNING] `relative-bar` (build script) generated 1 warning
459459
[WARNING] function `a` is never used
460-
--> relative-bar/./src/lib.rs:1:4
460+
--> relative-bar/src/lib.rs:1:4
461461
|
462462
1 | fn a() {}
463463
| ^
@@ -467,7 +467,7 @@ fn targets_with_relative_path_in_workspace_members() {
467467
[WARNING] `relative-bar` (lib) generated 1 warning
468468
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
469469
[WARNING] unused variable: `a`
470-
--> relative-bar/./example.rs:1:17
470+
--> relative-bar/example.rs:1:17
471471
|
472472
1 | fn main() { let a = 1; }
473473
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -482,7 +482,7 @@ fn targets_with_relative_path_in_workspace_members() {
482482

483483
p.cargo("check --test test").with_stderr_data(str![[r#"
484484
[WARNING] unused variable: `a`
485-
--> relative-bar/./build.rs:1:17
485+
--> relative-bar/build.rs:1:17
486486
|
487487
1 | fn main() { let a = 1; }
488488
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -491,7 +491,7 @@ fn targets_with_relative_path_in_workspace_members() {
491491
492492
[WARNING] `relative-bar` (build script) generated 1 warning
493493
[WARNING] function `a` is never used
494-
--> relative-bar/./src/lib.rs:1:4
494+
--> relative-bar/src/lib.rs:1:4
495495
|
496496
1 | fn a() {}
497497
| ^
@@ -501,7 +501,7 @@ fn targets_with_relative_path_in_workspace_members() {
501501
[WARNING] `relative-bar` (lib) generated 1 warning
502502
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
503503
[WARNING] unused variable: `a`
504-
--> relative-bar/./test.rs:5:35
504+
--> relative-bar/test.rs:5:35
505505
|
506506
5 | fn test_a() { let a = 1; }
507507
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -516,7 +516,7 @@ fn targets_with_relative_path_in_workspace_members() {
516516
if is_nightly() {
517517
p.cargo("check --bench bench").with_stderr_data(str![[r#"
518518
[WARNING] unused variable: `a`
519-
--> relative-bar/./build.rs:1:17
519+
--> relative-bar/build.rs:1:17
520520
|
521521
1 | fn main() { let a = 1; }
522522
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`
@@ -525,7 +525,7 @@ fn targets_with_relative_path_in_workspace_members() {
525525
526526
[WARNING] `relative-bar` (build script) generated 1 warning
527527
[WARNING] function `a` is never used
528-
--> relative-bar/./src/lib.rs:1:4
528+
--> relative-bar/src/lib.rs:1:4
529529
|
530530
1 | fn a() {}
531531
| ^
@@ -535,7 +535,7 @@ fn targets_with_relative_path_in_workspace_members() {
535535
[WARNING] `relative-bar` (lib) generated 1 warning
536536
[CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar)
537537
[WARNING] unused variable: `a`
538-
--> relative-bar/./bench.rs:7:58
538+
--> relative-bar/bench.rs:7:58
539539
|
540540
7 | fn bench_a(_b: &mut test::Bencher) { let a = 1; }
541541
| ^ [HELP] if this is intentional, prefix it with an underscore: `_a`

0 commit comments

Comments
 (0)