diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index eb48c5c4197..6764e596151 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -77,7 +77,6 @@ use crate::sources::CRATES_IO_REGISTRY; use crate::util::errors::CargoResult; use crate::util::network::http::configure_http_handle; use crate::util::network::http::http_handle; -use crate::util::try_canonicalize; use crate::util::{internal, CanonicalUrl}; use crate::util::{Filesystem, IntoUrl, IntoUrlWithBase, Rustc}; use anyhow::{anyhow, bail, format_err, Context as _}; @@ -457,11 +456,10 @@ impl GlobalContext { // commands that use Cargo as a library to inherit (via `cargo `) // or set (by setting `$CARGO`) a correct path to `cargo` when the current exe // is not actually cargo (e.g., `cargo-*` binaries, Valgrind, `ld.so`, etc.). - let exe = try_canonicalize( - self.get_env_os(crate::CARGO_ENV) - .map(PathBuf::from) - .ok_or_else(|| anyhow!("$CARGO not set"))?, - )?; + let exe = self + .get_env_os(crate::CARGO_ENV) + .map(PathBuf::from) + .ok_or_else(|| anyhow!("$CARGO not set"))?; Ok(exe) }; @@ -470,7 +468,7 @@ impl GlobalContext { // The method varies per operating system and might fail; in particular, // it depends on `/proc` being mounted on Linux, and some environments // (like containers or chroots) may not have that available. - let exe = try_canonicalize(env::current_exe()?)?; + let exe = env::current_exe()?; Ok(exe) } @@ -481,8 +479,6 @@ impl GlobalContext { // Otherwise, it has multiple components and is either: // - a relative path (e.g., `./cargo`, `target/debug/cargo`), or // - an absolute path (e.g., `/usr/local/bin/cargo`). - // In either case, `Path::canonicalize` will return the full absolute path - // to the target if it exists. let argv0 = env::args_os() .map(PathBuf::from) .next() diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index a072d567f2d..f93cbe04ed3 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -181,12 +181,9 @@ fn custom_build_env_vars() { ) .file("bar/src/lib.rs", "pub fn hello() {}"); - let cargo = cargo_exe().canonicalize().unwrap(); + let cargo = cargo_exe(); let cargo = cargo.to_str().unwrap(); - let rustc = paths::resolve_executable("rustc".as_ref()) - .unwrap() - .canonicalize() - .unwrap(); + let rustc = paths::resolve_executable("rustc".as_ref()).unwrap(); let rustc = rustc.to_str().unwrap(); let file_content = format!( r##" diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index 77d02fe80c0..0208eb7c42b 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -375,7 +375,7 @@ fn cargo_subcommand_env() { p.cargo("build").run(); assert!(p.bin("cargo-envtest").is_file()); - let cargo = cargo_exe().canonicalize().unwrap(); + let cargo = cargo_exe(); let mut path = path(); path.push(target_dir.clone()); let path = env::join_paths(path.iter()).unwrap(); @@ -388,9 +388,7 @@ fn cargo_subcommand_env() { // Check that subcommands inherit an overridden $CARGO let envtest_bin = target_dir .join("cargo-envtest") - .with_extension(std::env::consts::EXE_EXTENSION) - .canonicalize() - .unwrap(); + .with_extension(std::env::consts::EXE_EXTENSION); let envtest_bin = envtest_bin.to_str().unwrap(); // Previously, `$CARGO` would be left at `envtest_bin`. However, with the // fix for #15099, `$CARGO` is now overwritten with the path to the current @@ -623,8 +621,6 @@ fn overwrite_cargo_environment_variable() { let stderr_cargo = format!( "{}[EXE]\n", cargo_exe - .canonicalize() - .unwrap() .with_extension("") .to_str() .unwrap() @@ -648,8 +644,6 @@ fn overwrite_cargo_environment_variable() { let stderr_other_cargo = format!( "{}[EXE]\n", other_cargo_path - .canonicalize() - .unwrap() .with_extension("") .to_str() .unwrap() diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 7d29f52bef0..ea065ffc8f6 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -3890,8 +3890,6 @@ fn cargo_test_env() { let cargo = format!( "{}[EXE]", cargo_exe() - .canonicalize() - .unwrap() .with_extension("") .to_str() .unwrap() @@ -3913,8 +3911,6 @@ test env_test ... ok let stderr_other_cargo = format!( "{}[EXE]", other_cargo_path - .canonicalize() - .unwrap() .with_extension("") .to_str() .unwrap()