Skip to content

Commit

Permalink
fix: Fix Windows environment
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Oct 22, 2023
1 parent 332c45d commit cf29809
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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
);
}
8 changes: 8 additions & 0 deletions src/env/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
6 changes: 3 additions & 3 deletions src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down

0 comments on commit cf29809

Please sign in to comment.