Skip to content

Commit edfab53

Browse files
Always attach target arch to VM config
1 parent efa4585 commit edfab53

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

test/test-manager/src/config.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ pub struct VmConfig {
154154
pub package_type: Option<PackageType>,
155155

156156
/// CPU architecture
157-
#[arg(long, required_if_eq("os_type", "linux"))]
158-
pub architecture: Option<Architecture>,
157+
///
158+
/// TODO: Remove default x86_64, do not assume the system we're virtualizing
159+
#[arg(long)]
160+
#[serde(default = "Architecture::host_arch")]
161+
pub architecture: Architecture,
159162

160163
/// Tool to use for provisioning
161164
#[arg(long, default_value = "noop")]
@@ -203,8 +206,8 @@ impl VmConfig {
203206
pub fn get_default_runner_dir(&self) -> PathBuf {
204207
let target_dir = self.get_target_dir();
205208
let subdir = match self.architecture {
206-
None | Some(Architecture::X64) => self.get_x64_runner_subdir(),
207-
Some(Architecture::Aarch64) => self.get_aarch64_runner_subdir(),
209+
Architecture::X64 => self.get_x64_runner_subdir(),
210+
Architecture::Aarch64 => self.get_aarch64_runner_subdir(),
208211
};
209212

210213
target_dir.join(subdir)
@@ -288,6 +291,19 @@ impl Architecture {
288291
Architecture::Aarch64 => &["arm64", "aarch64"],
289292
}
290293
}
294+
295+
/// Figure out the architecture of the host test-manager was compiled for
296+
pub const fn host_arch() -> Architecture {
297+
// Panic at compile time
298+
const ARCH: Architecture = if cfg!(target_arch = "x86_64") {
299+
Architecture::X64
300+
} else if cfg!(target_arch = "aarch64") {
301+
Architecture::Aarch64
302+
} else {
303+
panic!("Unsupported target arch")
304+
};
305+
ARCH
306+
}
291307
}
292308

293309
#[derive(clap::ValueEnum, Default, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]

test/test-manager/src/package.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn get_version_from_path(app_package_path: &Path) -> Result<String, anyhow::
8686
fn find_app(
8787
app: &str,
8888
e2e_bin: bool,
89-
package_type: (OsType, Option<PackageType>, Option<Architecture>),
89+
package_type: (OsType, Option<PackageType>, Architecture),
9090
package_dir: Option<&PathBuf>,
9191
) -> Result<PathBuf> {
9292
// If it's a path, use that path
@@ -123,7 +123,7 @@ fn find_app(
123123
.filter(|(_path, u8_path)| !e2e_bin || u8_path.contains(get_os_name(package_type))) // Filter out irrelevant platforms
124124
.filter(|(_path, u8_path)| {
125125
let linux = e2e_bin || package_type.0 == OsType::Linux;
126-
let matching_ident = package_type.2.map(|arch| arch.get_identifiers().iter().any(|id| u8_path.contains(id))).unwrap_or(true);
126+
let matching_ident = package_type.2.get_identifiers().iter().any(|id| u8_path.contains(id));
127127
// Skip for non-Linux, because there's only one package
128128
!linux || matching_ident
129129
}) // Skip file if it doesn't match the architecture
@@ -143,7 +143,8 @@ fn find_app(
143143
})
144144
}
145145

146-
fn get_ext(package_type: (OsType, Option<PackageType>, Option<Architecture>)) -> &'static str {
146+
// TODO: Move to [`PackageType`]
147+
fn get_ext(package_type: (OsType, Option<PackageType>, Architecture)) -> &'static str {
147148
match package_type.0 {
148149
OsType::Windows => "exe",
149150
OsType::Macos => "pkg",
@@ -154,7 +155,8 @@ fn get_ext(package_type: (OsType, Option<PackageType>, Option<Architecture>)) ->
154155
}
155156
}
156157

157-
fn get_os_name(package_type: (OsType, Option<PackageType>, Option<Architecture>)) -> &'static str {
158+
// TODO: Move to [`OsType`]
159+
fn get_os_name(package_type: (OsType, Option<PackageType>, Architecture)) -> &'static str {
158160
match package_type.0 {
159161
OsType::Windows => "windows",
160162
OsType::Macos => "apple",

0 commit comments

Comments
 (0)