Skip to content

Commit a15bb7a

Browse files
committed
fix: Normalize targets path
1 parent 1c5427f commit a15bb7a

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::core::summary::MissingDependencyError;
99
use crate::AlreadyPrintedError;
1010
use anyhow::{anyhow, bail, Context as _};
1111
use cargo_platform::Platform;
12-
use cargo_util::paths::{self, normalize_path};
12+
use cargo_util::paths;
1313
use cargo_util_schemas::manifest::{
1414
self, PackageName, PathBaseName, TomlDependency, TomlDetailedDependency, TomlManifest,
1515
};
@@ -3016,8 +3016,12 @@ pub fn prepare_target_for_publish(
30163016
context: &str,
30173017
gctx: &GlobalContext,
30183018
) -> CargoResult<Option<manifest::TomlTarget>> {
3019-
let path = target.path.as_ref().expect("previously normalized");
3020-
let path = normalize_path(&path.0);
3019+
let path = target
3020+
.path
3021+
.as_ref()
3022+
.expect("previously normalized")
3023+
.0
3024+
.clone();
30213025
if let Some(packaged_files) = packaged_files {
30223026
if !packaged_files.contains(&path) {
30233027
let name = target.name.as_ref().expect("previously normalized");

src/cargo/util/toml/targets.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::fs::{self, DirEntry};
1515
use std::path::{Path, PathBuf};
1616

1717
use anyhow::Context as _;
18+
use cargo_util::paths;
1819
use cargo_util_schemas::manifest::{
1920
PathValue, StringOrBool, StringOrVec, TomlBenchTarget, TomlBinTarget, TomlExampleTarget,
2021
TomlLibTarget, TomlManifest, TomlTarget, TomlTestTarget,
@@ -96,11 +97,9 @@ pub(super) fn to_targets(
9697
.and_then(|s| s.to_str())
9798
.unwrap_or("")
9899
);
99-
targets.push(Target::custom_build_target(
100-
&name,
101-
package_root.join(custom_build),
102-
edition,
103-
));
100+
let path = package_root.join(custom_build);
101+
let path = paths::normalize_path(&path);
102+
targets.push(Target::custom_build_target(&name, path, edition));
104103
}
105104
if let Some(metabuild) = metabuild {
106105
// Verify names match available build deps.
@@ -169,6 +168,10 @@ pub fn normalize_lib(
169168
}
170169
}
171170
}
171+
if let Some(PathValue(path)) = lib.path {
172+
let path = paths::normalize_path(&path);
173+
lib.path = Some(PathValue(path));
174+
}
172175

173176
Ok(Some(lib))
174177
}
@@ -285,7 +288,7 @@ pub fn normalize_bins(
285288
}
286289
});
287290
let path = match path {
288-
Ok(path) => path,
291+
Ok(path) => paths::normalize_path(&path),
289292
Err(e) => anyhow::bail!("{}", e),
290293
};
291294
bin.path = Some(PathValue(path));
@@ -628,6 +631,7 @@ fn normalize_targets_with_legacy_path(
628631
continue;
629632
}
630633
};
634+
let path = paths::normalize_path(&path);
631635
target.path = Some(PathValue(path));
632636
result.push(target);
633637
}

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`

0 commit comments

Comments
 (0)