cmd/ebitenmobile: Bug fix: Specifying arches did not work

-target value should have been parsed correctly.

Fixes #1142
This commit is contained in:
Hajime Hoshi 2020-04-23 12:37:08 +09:00
parent 9b8c547342
commit edc58a2c9d

View File

@ -109,9 +109,14 @@ func main() {
flagset.Parse(args[1:]) flagset.Parse(args[1:])
os, err := osFromBuildTarget(buildTarget)
if err != nil {
log.Fatal(err)
}
// Add ldflags to suppress linker errors (#932). // Add ldflags to suppress linker errors (#932).
// See https://github.com/golang/go/issues/17807 // See https://github.com/golang/go/issues/17807
if buildTarget == "android" { if os == "android" {
if buildLdflags != "" { if buildLdflags != "" {
buildLdflags += " " buildLdflags += " "
} }
@ -124,7 +129,7 @@ func main() {
switch args[0] { switch args[0] {
case "bind": case "bind":
if err := doBind(args, &flagset); err != nil { if err := doBind(args, &flagset, os); err != nil {
log.Fatal(err) log.Fatal(err)
} }
default: default:
@ -132,14 +137,28 @@ func main() {
} }
} }
func doBind(args []string, flagset *flag.FlagSet) error { func osFromBuildTarget(buildTarget string) (string, error) {
var os string
for i, pair := range strings.Split(buildTarget, ",") {
osarch := strings.SplitN(pair, "/", 2)
if i == 0 {
os = osarch[0]
}
if os != osarch[0] {
return "", fmt.Errorf("ebitenmobile: cannot target different OSes")
}
}
if os == "ios" {
os = "darwin"
}
return os, nil
}
func doBind(args []string, flagset *flag.FlagSet, buildOS string) error {
tags := buildTags tags := buildTags
cfg := &packages.Config{} cfg := &packages.Config{}
switch buildTarget { cfg.Env = append(os.Environ(), "GOOS="+buildOS)
case "android": if buildOS == "darwin" {
cfg.Env = append(os.Environ(), "GOOS=android")
case "ios":
cfg.Env = append(os.Environ(), "GOOS=darwin")
if tags != "" { if tags != "" {
tags += " " tags += " "
} }
@ -185,10 +204,7 @@ func doBind(args []string, flagset *flag.FlagSet) error {
return content return content
} }
switch buildTarget { if buildOS == "darwin" {
case "android":
// Do nothing.
case "ios":
dir := filepath.Join(buildO, "Versions", "A") dir := filepath.Join(buildO, "Versions", "A")
if err := ioutil.WriteFile(filepath.Join(dir, "Headers", prefixUpper+"EbitenViewController.h"), []byte(replacePrefixes(objcH)), 0644); err != nil { if err := ioutil.WriteFile(filepath.Join(dir, "Headers", prefixUpper+"EbitenViewController.h"), []byte(replacePrefixes(objcH)), 0644); err != nil {