Merge pull request #9954 from rgl/run-cygwin-msys2-cd-creation-tool

add support for running cygwin/msys2 based cd/iso creation tool (e.g.…
This commit is contained in:
Megan Marsh 2020-09-23 11:39:44 -07:00 committed by GitHub
commit 96a8e827ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"github.com/hashicorp/packer/helper/builder/localexec" "github.com/hashicorp/packer/helper/builder/localexec"
@ -167,12 +168,34 @@ var supportedCDISOCreationCommands []cdISOCreationCommand = []cdISOCreationComma
}, },
} }
func isCygwinExecutable(path string) bool {
return runtime.GOOS == "windows" && strings.Contains(path, "\\usr\\bin\\")
}
func toCygwinPath(path string) (string, error) {
c := exec.Command("cygpath", path)
cygwinPath, err := c.Output()
return strings.TrimSpace(string(cygwinPath)), err
}
func retrieveCDISOCreationCommand(label string, source string, dest string) (*exec.Cmd, error) { func retrieveCDISOCreationCommand(label string, source string, dest string) (*exec.Cmd, error) {
for _, c := range supportedCDISOCreationCommands { for _, c := range supportedCDISOCreationCommands {
path, err := exec.LookPath(c.Name) path, err := exec.LookPath(c.Name)
if err != nil { if err != nil {
continue continue
} }
// if we are running a cygwin/msys2 executable we must convert the
// native win32 path to a cygwin/msys2/unix style path.
if isCygwinExecutable(path) {
source, err = toCygwinPath(source)
if err != nil {
return nil, err
}
dest, err = toCygwinPath(dest)
if err != nil {
return nil, err
}
}
return c.Command(path, label, source, dest), nil return c.Command(path, label, source, dest), nil
} }
var commands = make([]string, 0, len(supportedCDISOCreationCommands)) var commands = make([]string, 0, len(supportedCDISOCreationCommands))