Skip to content

Commit

Permalink
virtme-ng: auto-detect host architecture
Browse files Browse the repository at this point in the history
Instead of implicitly assuming amd64 as the host architecture, detect it
automatically so the user doesn't need to manually specify --arch on
non-amd64 systems.

This fixes issue #173.

Signed-off-by: Andrea Righi <[email protected]>
  • Loading branch information
arighi committed Oct 5, 2024
1 parent e5d641c commit a68aabc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions virtme_ng/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
import re
import os
import platform
import sys
import socket
import shutil
Expand Down Expand Up @@ -564,6 +565,20 @@ def create_root(destdir, arch, release):
os.chdir(prevdir)


def get_host_arch():
"""Translate host architecture to the corresponding virtme-ng arch name."""
arch = platform.machine()
arch_map = {
'x86_64': 'amd64',
'aarch64': 'arm64',
'armv7l': 'armhf',
'ppc64le': 'ppc64el',
'riscv64': 'riscv64',
's390x': 's390x',
}
return arch_map.get(arch, None)


class KernelSource:
"""Main class that implement actions to perform on a kernel source directory."""

Expand Down Expand Up @@ -829,7 +844,7 @@ def _get_virtme_arch(self, args):

def _get_virtme_root(self, args):
if args.root is not None:
create_root(args.root, args.arch or "amd64", args.root_release)
create_root(args.root, args.arch or get_host_arch(), args.root_release)
self.virtme_param["root"] = f"--root {args.root}"
else:
self.virtme_param["root"] = ""
Expand Down Expand Up @@ -880,7 +895,7 @@ def _get_virtme_run(self, args):
# repository.
if re.match(r'^v\d+(\.\d+)*(-rc\d+)?$', args.run):
if args.arch is None:
arch = 'amd64'
arch = get_host_arch()
else:
arch = args.arch
try:
Expand Down

0 comments on commit a68aabc

Please sign in to comment.