Skip to content

Commit

Permalink
Always attach target arch to VM config
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Dec 10, 2024
1 parent efa4585 commit edfab53
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 20 additions & 4 deletions test/test-manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ pub struct VmConfig {
pub package_type: Option<PackageType>,

/// CPU architecture
#[arg(long, required_if_eq("os_type", "linux"))]
pub architecture: Option<Architecture>,
///
/// 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")]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down
10 changes: 6 additions & 4 deletions test/test-manager/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn get_version_from_path(app_package_path: &Path) -> Result<String, anyhow::
fn find_app(
app: &str,
e2e_bin: bool,
package_type: (OsType, Option<PackageType>, Option<Architecture>),
package_type: (OsType, Option<PackageType>, Architecture),
package_dir: Option<&PathBuf>,
) -> Result<PathBuf> {
// If it's a path, use that path
Expand Down Expand Up @@ -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
Expand All @@ -143,7 +143,8 @@ fn find_app(
})
}

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

fn get_os_name(package_type: (OsType, Option<PackageType>, Option<Architecture>)) -> &'static str {
// TODO: Move to [`OsType`]
fn get_os_name(package_type: (OsType, Option<PackageType>, Architecture)) -> &'static str {
match package_type.0 {
OsType::Windows => "windows",
OsType::Macos => "apple",
Expand Down

0 comments on commit edfab53

Please sign in to comment.