Skip to content

Commit dba3035

Browse files
committed
[rust] Setup PROCESSOR_ARCHITECTURE env for Windows
1 parent 0088790 commit dba3035

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ test --test_env=JRUBY_OPTS="--dev"
105105

106106
test:windows --test_env=PATH
107107
test:windows --test_env=LOCALAPPDATA
108+
test:windows --test_env=PROCESSOR_ARCHITECTURE
108109
test:windows --test_env=PROGRAMFILES="C:\\Program Files"
109110
test:windows --test_env=PROGRAMFILES(X86)="C:\\Program Files (x86)"
110111

rust/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::config::OS::{LINUX, MACOS, WINDOWS};
1919
use crate::shell::{run_powershell_command, run_shell_command_by_os};
2020
use crate::{
21-
default_cache_folder, format_one_arg, path_to_string, Command, ENV_CPU_ARCHITECTURE,
21+
default_cache_folder, format_one_arg, path_to_string, Command, ENV_PROCESSOR_ARCHITECTURE,
2222
REQUEST_TIMEOUT_SEC, UNAME_COMMAND,
2323
};
2424
use crate::{ARCH_AMD64, ARCH_ARM64, ARCH_X86, PS_GET_OS_COMMAND, TTL_SEC};
@@ -69,14 +69,14 @@ impl ManagerConfig {
6969

7070
let self_os = OS;
7171
let self_arch = if WINDOWS.is(self_os) {
72-
let mut cpu_arch = env::var(ENV_CPU_ARCHITECTURE).unwrap_or_default();
73-
if cpu_arch.is_empty() {
72+
let mut architecture = env::var(ENV_PROCESSOR_ARCHITECTURE).unwrap_or_default();
73+
if architecture.is_empty() {
7474
let get_os_command = Command::new_single(PS_GET_OS_COMMAND.to_string());
75-
cpu_arch = run_powershell_command(get_os_command).unwrap_or_default();
75+
architecture = run_powershell_command(get_os_command).unwrap_or_default();
7676
}
77-
if cpu_arch.contains("32") {
77+
if architecture.contains("32") {
7878
ARCH_X86.to_string()
79-
} else if cpu_arch.contains("ARM") {
79+
} else if architecture.contains("ARM") {
8080
ARCH_ARM64.to_string()
8181
} else {
8282
ARCH_AMD64.to_string()

rust/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ pub const SINGLE_QUOTE: &str = "'";
9595
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
9696
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
9797
pub const ENV_LOCALAPPDATA: &str = "LOCALAPPDATA";
98-
pub const ENV_CPU_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
98+
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
9999
pub const ENV_X86: &str = " (x86)";
100100
pub const ARCH_X86: &str = "x86";
101101
pub const ARCH_AMD64: &str = "amd64";
102102
pub const ARCH_ARM64: &str = "arm64";
103-
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
104103
pub const TTL_SEC: u64 = 3600;
105104
pub const UNAME_COMMAND: &str = "uname -{}";
106105
pub const ESCAPE_COMMAND: &str = r#"printf %q "{}""#;

rust/src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Command {
6565
}
6666

6767
pub fn run_powershell_command_with_log(log: &Logger, command: Command) -> Result<String, Error> {
68-
log.debug(format!("Running command: {}", command.display()));
68+
log.debug(format!("Running ps command: {}", command.display()));
6969
let output = run_powershell_command(command)?;
7070
log.debug(format!("Output: {:?}", output));
7171
Ok(output)

0 commit comments

Comments
 (0)