From cf29809d95ad050d965c9ac3316fa06c152bfab1 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Sun, 22 Oct 2023 19:10:16 +0200 Subject: [PATCH] fix: Fix Windows environment --- src/env/mod.rs | 18 ++++++++++-------- src/env/windows.rs | 8 ++++++++ src/toolchain/mod.rs | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/env/mod.rs b/src/env/mod.rs index 14644602..29ab387c 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -12,17 +12,19 @@ pub mod unix; pub mod windows; /// Instructions to export the environment variables. -pub fn set_env(toolchain_dir: &Path) -> Result<(), Error> { +pub fn set_env(toolchain_dir: &Path, no_modify_env: bool) -> Result<(), Error> { #[cfg(windows)] - if cfg!(windows) { - windows::write_env_files(toolchain_dir)?; - windows::update_env()?; - } + windows::write_env_files(toolchain_dir)?; #[cfg(unix)] - if cfg!(unix) { - unix::write_env_files(toolchain_dir)?; + unix::write_env_files(toolchain_dir)?; + + if !no_modify_env { + #[cfg(windows)] + windows::update_env()?; + #[cfg(unix)] unix::update_env(toolchain_dir)?; } + Ok(()) } @@ -54,7 +56,7 @@ pub fn print_post_install_msg(toolchain_dir: &str, no_modify_env: bool) { ); #[cfg(windows)] println!( - "\t'. {}\\env.ps1' or '{}\\env.bat dependeing on your shell'", + "\t'. {}\\env.ps1' or '{}\\env.bat' depending on your shell'", toolchain_dir, toolchain_dir ); } diff --git a/src/env/windows.rs b/src/env/windows.rs index 64b196b2..949a1842 100644 --- a/src/env/windows.rs +++ b/src/env/windows.rs @@ -77,12 +77,20 @@ pub(super) fn update_env() -> Result<(), Error> { set_env_variable("LIBCLANG_PATH", &libclang_path)?; } + if let Ok(libclang_bin_path) = env::var("LIBCLANG_BIN_PATH") { + let libclang_bin_path: &str = &libclang_bin_path; + if !path.contains(libclang_bin_path) { + path = format!("{};{}", libclang_bin_path, path); + } + } + if let Ok(clang_path) = env::var("CLANG_PATH") { let clang_path: &str = &clang_path; if !path.contains(clang_path) { path = format!("{};{}", clang_path, path); } } + set_env_variable("PATH", &path)?; remove_legacy_export_file()?; diff --git a/src/toolchain/mod.rs b/src/toolchain/mod.rs index 70cd26ba..50c91823 100644 --- a/src/toolchain/mod.rs +++ b/src/toolchain/mod.rs @@ -245,9 +245,9 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> InstallMode::Install => info!("Installation successfully completed!"), InstallMode::Update => info!("Update successfully completed!"), } - if !args.no_modify_env { - set_env(&toolchain_dir)?; - } + + set_env(&toolchain_dir, args.no_modify_env)?; + print_post_install_msg(&toolchain_dir.display().to_string(), args.no_modify_env); Ok(())