Skip to content

Commit d71aea5

Browse files
committed
fix: Nomarlize the relative path for all targets
1 parent 34f7e13 commit d71aea5

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ pub fn to_real_manifest(
13021302
// If we have no lib at all, use the inferred lib, if available.
13031303
// If we have a lib with a path, we're done.
13041304
// If we have a lib with no path, use the inferred lib or else the package name.
1305-
let targets = to_targets(
1305+
let mut targets = to_targets(
13061306
&features,
13071307
&original_toml,
13081308
&normalized_toml,
@@ -1312,6 +1312,13 @@ pub fn to_real_manifest(
13121312
warnings,
13131313
)?;
13141314

1315+
// Normalize the targets paths
1316+
for target in targets.iter_mut() {
1317+
if let TargetSourcePath::Path(path) = target.src_path() {
1318+
target.set_src_path(TargetSourcePath::Path(normalize_path(path)));
1319+
}
1320+
}
1321+
13151322
if targets.iter().all(|t| t.is_custom_build()) {
13161323
bail!(
13171324
"no targets specified in the manifest\n\
@@ -3020,8 +3027,12 @@ pub fn prepare_target_for_publish(
30203027
context: &str,
30213028
gctx: &GlobalContext,
30223029
) -> CargoResult<Option<manifest::TomlTarget>> {
3023-
let path = target.path.as_ref().expect("previously normalized");
3024-
let path = normalize_path(&path.0);
3030+
let path = target
3031+
.path
3032+
.as_ref()
3033+
.expect("previously normalized")
3034+
.0
3035+
.clone();
30253036
if let Some(packaged_files) = packaged_files {
30263037
if !packaged_files.contains(&path) {
30273038
let name = target.name.as_ref().expect("previously normalized");

tests/testsuite/binary_name.rs

Lines changed: 12 additions & 12 deletions
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`

tests/testsuite/metadata.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4295,7 +4295,10 @@ fn cargo_metadata_non_utf8() {
42954295
.arg("--format-version")
42964296
.arg("1")
42974297
.with_stderr_data(str![[r#"
4298-
[ERROR] path contains invalid UTF-8 characters
4298+
[ERROR] failed to parse manifest at `[ROOT]/foo/�/Cargo.toml`
4299+
4300+
Caused by:
4301+
non-UTF8 path for library
42994302
43004303
"#]])
43014304
.with_status(101)

0 commit comments

Comments
 (0)