cmd/ebitenmobile: Bug fix: .exe was requried on Windows

On Windows, executable files must have .exe extension, or
exec.LookPath since exec.LookPath checks %PATHEXT%.

This fixes the issue that ebitenmobile didn't invoke the original
gobind wrapper and then didn't include and compile some Java files.

Fixes #1096
This commit is contained in:
Hajime Hoshi 2020-03-05 01:05:53 +09:00
parent b4a9538e1d
commit cebc203e6f

View File

@ -20,6 +20,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
) )
const gomobileHash = "2b26a4705d2481ef30846d291bd450445e2b5bdd" const gomobileHash = "2b26a4705d2481ef30846d291bd450445e2b5bdd"
@ -57,6 +58,15 @@ func runGo(args ...string) error {
return runCommand("go", args, env) return runCommand("go", args, env)
} }
// exe adds the .exe extension to the given filename.
// Without .exe, the executable won't be found by exec.LookPath on Windows (#1096).
func exe(filename string) string {
if runtime.GOOS == "windows" {
return filename + ".exe"
}
return filename
}
func prepareGomobileCommands() error { func prepareGomobileCommands() error {
tmp, err := ioutil.TempDir("", "ebitenmobile-") tmp, err := ioutil.TempDir("", "ebitenmobile-")
if err != nil { if err != nil {
@ -96,10 +106,10 @@ func prepareGomobileCommands() error {
if err := runGo("get", "golang.org/x/mobile@"+gomobileHash); err != nil { if err := runGo("get", "golang.org/x/mobile@"+gomobileHash); err != nil {
return err return err
} }
if err := runGo("build", "-o", filepath.Join("bin", "gomobile"), "golang.org/x/mobile/cmd/gomobile"); err != nil { if err := runGo("build", "-o", exe(filepath.Join("bin", "gomobile")), "golang.org/x/mobile/cmd/gomobile"); err != nil {
return err return err
} }
if err := runGo("build", "-o", filepath.Join("bin", "gobind-original"), "golang.org/x/mobile/cmd/gobind"); err != nil { if err := runGo("build", "-o", exe(filepath.Join("bin", "gobind-original")), "golang.org/x/mobile/cmd/gobind"); err != nil {
return err return err
} }
@ -110,7 +120,7 @@ func prepareGomobileCommands() error {
return err return err
} }
if err := runGo("build", "-o", filepath.Join("bin", "gobind"), "-tags", "ebitenmobilegobind", filepath.Join("src", "gobind.go")); err != nil { if err := runGo("build", "-o", exe(filepath.Join("bin", "gobind")), "-tags", "ebitenmobilegobind", filepath.Join("src", "gobind.go")); err != nil {
return err return err
} }