From 6427a1fe0dca4895740c657de0795a154bfa2075 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 19 Nov 2013 12:32:10 -0800 Subject: [PATCH] builder/virtualbox: use VBOX_INSTALL_PATH to find VBoxManage --- CHANGELOG.md | 2 ++ builder/virtualbox/builder.go | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a72ca12d..7b83c4f5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ IMPROVEMENTS: IDs to apply. [GH-499] * builder/amazon/all: AWS API requests are now retried when a temporary network error occurs as well as 500 errors. [GH-559] +* builder/virtualbox: Use VBOX\_INSTALL\_PATH env var on Windows to find + VBoxManage. [GH-628] * post-processor/vagrant: skips gzip compression when compression_level=0 * provisioner/chef-solo: Encrypted data bag support [GH-625] diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 5df6c30eb..31e265ad0 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "time" ) @@ -485,9 +486,29 @@ func (b *Builder) Cancel() { } func (b *Builder) newDriver() (Driver, error) { - vboxmanagePath, err := exec.LookPath("VBoxManage") - if err != nil { - return nil, err + var vboxmanagePath string + + if runtime.GOOS == "windows" { + // On Windows, we check VBOX_INSTALL_PATH env var for the path + if installPath := os.Getenv("VBOX_INSTALL_PATH"); installPath != "" { + log.Printf("[DEBUG] builder/virtualbox: VBOX_INSTALL_PATH: %s", + installPath) + for _, path := range strings.Split(installPath, ";") { + path = filepath.Join(path, "VBoxManage.exe") + if _, err := os.Stat(path); err == nil { + vboxmanagePath = path + break + } + } + } + } + + if vboxmanagePath == "" { + var err error + vboxmanagePath, err = exec.LookPath("VBoxManage") + if err != nil { + return nil, err + } } log.Printf("VBoxManage path: %s", vboxmanagePath)