diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 6f74ff6e8b22..c7d67a44e24b 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -9,7 +9,7 @@ use crate::core::summary::MissingDependencyError; use crate::AlreadyPrintedError; use anyhow::{anyhow, bail, Context as _}; use cargo_platform::Platform; -use cargo_util::paths::{self, normalize_path}; +use cargo_util::paths; use cargo_util_schemas::manifest::{ self, PackageName, PathBaseName, TomlDependency, TomlDetailedDependency, TomlManifest, }; @@ -3016,8 +3016,12 @@ pub fn prepare_target_for_publish( context: &str, gctx: &GlobalContext, ) -> CargoResult> { - let path = target.path.as_ref().expect("previously normalized"); - let path = normalize_path(&path.0); + let path = target + .path + .as_ref() + .expect("previously normalized") + .0 + .clone(); if let Some(packaged_files) = packaged_files { if !packaged_files.contains(&path) { let name = target.name.as_ref().expect("previously normalized"); @@ -3030,7 +3034,6 @@ pub fn prepare_target_for_publish( } let mut target = target.clone(); - let path = normalize_path_sep(path, context)?; target.path = Some(manifest::PathValue(path.into())); Ok(Some(target)) diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index c80b31dba613..967c25e9115d 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -10,6 +10,7 @@ //! It is a bit tricky because we need match explicit information from `Cargo.toml` //! with implicit info in directory layout. +use cargo_util::paths::normalize_path; use std::collections::HashSet; use std::fs::{self, DirEntry}; use std::path::{Path, PathBuf}; @@ -27,6 +28,8 @@ use crate::util::errors::CargoResult; use crate::util::restricted_names; use crate::util::toml::deprecated_underscore; +use super::normalize_path_sep; + const DEFAULT_TEST_DIR_NAME: &'static str = "tests"; const DEFAULT_BENCH_DIR_NAME: &'static str = "benches"; const DEFAULT_EXAMPLE_DIR_NAME: &'static str = "examples"; @@ -96,6 +99,8 @@ pub(super) fn to_targets( .and_then(|s| s.to_str()) .unwrap_or("") ); + let custom_build = normalize_path(package_root); + let custom_build = normalize_path_sep(custom_build, "custom-build")?; targets.push(Target::custom_build_target( &name, package_root.join(custom_build), @@ -170,6 +175,12 @@ pub fn normalize_lib( } } + if let Some(PathValue(p)) = lib.path { + let path = normalize_path(&p); + let path = normalize_path_sep(path, "library")?; + lib.path = Some(PathValue(path)); + } + Ok(Some(lib)) } @@ -288,6 +299,8 @@ pub fn normalize_bins( Ok(path) => path, Err(e) => anyhow::bail!("{}", e), }; + let path = normalize_path(&path); + let path = normalize_path_sep(path, "binary")?; bin.path = Some(PathValue(path)); } @@ -628,6 +641,8 @@ fn normalize_targets_with_legacy_path( continue; } }; + let path = normalize_path(&path); + let path = super::normalize_path_sep(path, target_kind_human)?; target.path = Some(PathValue(path)); result.push(target); } diff --git a/tests/testsuite/binary_name.rs b/tests/testsuite/binary_name.rs index cda38e23f50e..6639840b1523 100644 --- a/tests/testsuite/binary_name.rs +++ b/tests/testsuite/binary_name.rs @@ -414,7 +414,7 @@ fn targets_with_relative_path_in_workspace_members() { .with_stderr_data(str![[r#" [COMPILING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar) [WARNING] unused variable: `a` - --> relative-bar/./build.rs:1:17 + --> relative-bar/build.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -423,7 +423,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (build script) generated 1 warning [WARNING] function `a` is never used - --> relative-bar/./src/lib.rs:1:4 + --> relative-bar/src/lib.rs:1:4 | 1 | fn a() {} | ^ @@ -432,7 +432,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (lib) generated 1 warning [WARNING] unused variable: `a` - --> relative-bar/./src/main.rs:1:17 + --> relative-bar/src/main.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -448,7 +448,7 @@ fn targets_with_relative_path_in_workspace_members() { p.cargo("check --example example") .with_stderr_data(str![[r#" [WARNING] unused variable: `a` - --> relative-bar/./build.rs:1:17 + --> relative-bar/build.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -457,7 +457,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (build script) generated 1 warning [WARNING] function `a` is never used - --> relative-bar/./src/lib.rs:1:4 + --> relative-bar/src/lib.rs:1:4 | 1 | fn a() {} | ^ @@ -467,7 +467,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (lib) generated 1 warning [CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar) [WARNING] unused variable: `a` - --> relative-bar/./example.rs:1:17 + --> relative-bar/example.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -482,7 +482,7 @@ fn targets_with_relative_path_in_workspace_members() { p.cargo("check --test test").with_stderr_data(str![[r#" [WARNING] unused variable: `a` - --> relative-bar/./build.rs:1:17 + --> relative-bar/build.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -491,7 +491,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (build script) generated 1 warning [WARNING] function `a` is never used - --> relative-bar/./src/lib.rs:1:4 + --> relative-bar/src/lib.rs:1:4 | 1 | fn a() {} | ^ @@ -501,7 +501,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (lib) generated 1 warning [CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar) [WARNING] unused variable: `a` - --> relative-bar/./test.rs:5:35 + --> relative-bar/test.rs:5:35 | 5 | fn test_a() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -516,7 +516,7 @@ fn targets_with_relative_path_in_workspace_members() { if is_nightly() { p.cargo("check --bench bench").with_stderr_data(str![[r#" [WARNING] unused variable: `a` - --> relative-bar/./build.rs:1:17 + --> relative-bar/build.rs:1:17 | 1 | fn main() { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a` @@ -525,7 +525,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (build script) generated 1 warning [WARNING] function `a` is never used - --> relative-bar/./src/lib.rs:1:4 + --> relative-bar/src/lib.rs:1:4 | 1 | fn a() {} | ^ @@ -535,7 +535,7 @@ fn targets_with_relative_path_in_workspace_members() { [WARNING] `relative-bar` (lib) generated 1 warning [CHECKING] relative-bar v0.1.0 ([ROOT]/foo/relative-bar) [WARNING] unused variable: `a` - --> relative-bar/./bench.rs:7:58 + --> relative-bar/bench.rs:7:58 | 7 | fn bench_a(_b: &mut test::Bencher) { let a = 1; } | ^ [HELP] if this is intentional, prefix it with an underscore: `_a`