Use the stable path for brew installed qemu firmware in machine config

Previously, machine config had hard coded the homebrew cellar path with
the patch version of qemu available at the time of machine creation,
and was prone to breaking anytime qemu was updated and the machine is
restarted. This change replaces the firmware path to use the prefix as
reported by 'brew --prefix qemu' (e.g. /opt/homebrew/opt/qemu on M1)
which is a symlink the the latest installed version of qemu
(e.g. /opt/homebrew/Cellar/qemu/<x.y.z>)
pull/16853/head
Terry Moschou 2023-07-10 11:02:34 +09:30
parent f23e93b1c4
commit 98cf69588d
1 changed files with 2 additions and 16 deletions

View File

@ -21,7 +21,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
@ -80,27 +79,14 @@ func qemuFirmwarePath(customPath string) (string, error) {
arch := runtime.GOARCH
// For macOS, find the correct brew installation path for qemu firmware
if runtime.GOOS == "darwin" {
var p, fw string
switch arch {
case "amd64":
p = "/usr/local/Cellar/qemu"
fw = "share/qemu/edk2-x86_64-code.fd"
return "/usr/local/opt/qemu/share/qemu/edk2-x86_64-code.fd", nil
case "arm64":
p = "/opt/homebrew/Cellar/qemu"
fw = "share/qemu/edk2-aarch64-code.fd"
return "/opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd", nil
default:
return "", fmt.Errorf("unknown arch: %s", arch)
}
v, err := os.ReadDir(p)
if err != nil {
return "", fmt.Errorf("lookup qemu: %v", err)
}
for _, version := range v {
if version.IsDir() {
return path.Join(p, version.Name(), fw), nil
}
}
}
switch arch {