From 60f6a9f36d7e6bdb7d0a39f7c24e7cab8913f22f Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Tue, 3 Dec 2024 12:05:22 +0100 Subject: [PATCH] Always attach target arch to VM config --- test/test-manager/src/config.rs | 24 ++++++++++++++++++++---- test/test-manager/src/package.rs | 10 ++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/test/test-manager/src/config.rs b/test/test-manager/src/config.rs index 7379bd5ec625..b7c409aefeae 100644 --- a/test/test-manager/src/config.rs +++ b/test/test-manager/src/config.rs @@ -154,8 +154,11 @@ pub struct VmConfig { pub package_type: Option, /// CPU architecture - #[arg(long, required_if_eq("os_type", "linux"))] - pub architecture: Option, + /// + /// TODO: Remove default x86_64, do not assume the system we're virtualizing + #[arg(long)] + #[serde(default = "Architecture::host_arch")] + pub architecture: Architecture, /// Tool to use for provisioning #[arg(long, default_value = "noop")] @@ -203,8 +206,8 @@ impl VmConfig { pub fn get_default_runner_dir(&self) -> PathBuf { let target_dir = self.get_target_dir(); let subdir = match self.architecture { - None | Some(Architecture::X64) => self.get_x64_runner_subdir(), - Some(Architecture::Aarch64) => self.get_aarch64_runner_subdir(), + Architecture::X64 => self.get_x64_runner_subdir(), + Architecture::Aarch64 => self.get_aarch64_runner_subdir(), }; target_dir.join(subdir) @@ -288,6 +291,19 @@ impl Architecture { Architecture::Aarch64 => &["arm64", "aarch64"], } } + + /// Figure out the architecture of the host test-manager was compiled for + pub const fn host_arch() -> Architecture { + // Panic at compile time + const ARCH: Architecture = if cfg!(target_arch = "x86_64") { + Architecture::X64 + } else if cfg!(target_arch = "aarch64") { + Architecture::Aarch64 + } else { + panic!("Unsupported target arch") + }; + ARCH + } } #[derive(clap::ValueEnum, Default, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] diff --git a/test/test-manager/src/package.rs b/test/test-manager/src/package.rs index 47915563926b..feb66e97e8cb 100644 --- a/test/test-manager/src/package.rs +++ b/test/test-manager/src/package.rs @@ -86,7 +86,7 @@ pub fn get_version_from_path(app_package_path: &Path) -> Result, Option), + package_type: (OsType, Option, Architecture), package_dir: Option<&PathBuf>, ) -> Result { // If it's a path, use that path @@ -123,7 +123,7 @@ fn find_app( .filter(|(_path, u8_path)| !e2e_bin || u8_path.contains(get_os_name(package_type))) // Filter out irrelevant platforms .filter(|(_path, u8_path)| { let linux = e2e_bin || package_type.0 == OsType::Linux; - let matching_ident = package_type.2.map(|arch| arch.get_identifiers().iter().any(|id| u8_path.contains(id))).unwrap_or(true); + let matching_ident = package_type.2.get_identifiers().iter().any(|id| u8_path.contains(id)); // Skip for non-Linux, because there's only one package !linux || matching_ident }) // Skip file if it doesn't match the architecture @@ -143,7 +143,8 @@ fn find_app( }) } -fn get_ext(package_type: (OsType, Option, Option)) -> &'static str { +// TODO: Move to [`PackageType`] +fn get_ext(package_type: (OsType, Option, Architecture)) -> &'static str { match package_type.0 { OsType::Windows => "exe", OsType::Macos => "pkg", @@ -154,7 +155,8 @@ fn get_ext(package_type: (OsType, Option, Option)) -> } } -fn get_os_name(package_type: (OsType, Option, Option)) -> &'static str { +// TODO: Move to [`OsType`] +fn get_os_name(package_type: (OsType, Option, Architecture)) -> &'static str { match package_type.0 { OsType::Windows => "windows", OsType::Macos => "apple",