Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust] Fix local architecture discovery in Selenium Manager #11611

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions rust/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
// under the License.

use crate::config::OS::{LINUX, MACOS, WINDOWS};
use crate::REQUEST_TIMEOUT_SEC;
use crate::TTL_BROWSERS_SEC;
use crate::TTL_DRIVERS_SEC;

use std::env::consts::{ARCH, OS};
use crate::{
format_one_arg, run_shell_command, ENV_PROCESSOR_ARCHITECTURE, REQUEST_TIMEOUT_SEC,
UNAME_COMMAND,
};
use std::env;
use std::env::consts::{OS};

pub const ARM64_ARCH: &str = "arm64";

pub struct ManagerConfig {
pub browser_version: String,
Expand All @@ -36,11 +42,27 @@ pub struct ManagerConfig {

impl ManagerConfig {
pub fn default() -> ManagerConfig {
let self_os = OS;
let self_arch = if WINDOWS.is(self_os) {
env::var(ENV_PROCESSOR_ARCHITECTURE).unwrap_or_default()
} else {
let uname_a = format_one_arg(UNAME_COMMAND, "a");
if run_shell_command(self_os, uname_a)
.unwrap_or_default()
.to_ascii_lowercase()
.contains(ARM64_ARCH)
{
ARM64_ARCH.to_string()
} else {
let uname_m = format_one_arg(UNAME_COMMAND, "m");
run_shell_command(self_os, uname_m).unwrap_or_default()
}
};
ManagerConfig {
browser_version: "".to_string(),
driver_version: "".to_string(),
os: OS.to_string(),
arch: ARCH.to_string(),
os: self_os.to_string(),
arch: self_arch,
browser_path: "".to_string(),
proxy: "".to_string(),
timeout: REQUEST_TIMEOUT_SEC,
Expand Down Expand Up @@ -107,15 +129,16 @@ pub enum ARCH {
}

impl ARCH {
pub fn to_str(&self) -> &str {
pub fn to_str_vector(&self) -> Vec<&str> {
match self {
ARCH::X32 => "x86",
ARCH::X64 => "x86_64",
ARCH::ARM64 => "aarch64",
ARCH::X32 => vec!["x86", "i386"],
ARCH::X64 => vec!["x86_64", "x64", "i686", "amd64", "ia64"],
ARCH::ARM64 => vec![ARM64_ARCH, "aarch64", "arm"],
}
}

pub fn is(&self, arch: &str) -> bool {
self.to_str().eq_ignore_ascii_case(arch)
self.to_str_vector()
.contains(&arch.to_ascii_lowercase().as_str())
}
}
14 changes: 7 additions & 7 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ pub const DASH_DASH_VERSION: &str = "{} --version";
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
pub const ENV_LOCALAPPDATA: &str = "LOCALAPPDATA";
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
pub const FALLBACK_RETRIES: u32 = 5;
pub const WHERE_COMMAND: &str = "where {}";
pub const WHICH_COMMAND: &str = "which {}";
pub const TTL_BROWSERS_SEC: u64 = 0;
pub const TTL_DRIVERS_SEC: u64 = 86400;
pub const UNAME_COMMAND: &str = "uname -{}";

pub trait SeleniumManager {
// ----------------------------------------------------------
Expand Down Expand Up @@ -171,13 +173,11 @@ pub trait SeleniumManager {
break;
}
if !self.is_safari() {
metadata
.browsers
.push(create_browser_metadata(
browser_name,
&browser_version,
browser_ttl,
));
metadata.browsers.push(create_browser_metadata(
browser_name,
&browser_version,
browser_ttl,
));
write_metadata(&metadata, self.get_logger());
}
if !browser_version.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use exitcode::{DATAERR, UNAVAILABLE};

use selenium_manager::logger::Logger;
use selenium_manager::REQUEST_TIMEOUT_SEC;
use selenium_manager::TTL_DRIVERS_SEC;
use selenium_manager::TTL_BROWSERS_SEC;
use selenium_manager::TTL_DRIVERS_SEC;
use selenium_manager::{
clear_cache, get_manager_by_browser, get_manager_by_driver, SeleniumManager,
};
Expand Down