cmd/ebitenmobile: fix gomobile toolchain bug (#3129)

Closes #3128
This commit is contained in:
corfe83 2024-10-14 12:01:07 -07:00 committed by GitHub
parent 2c3c8cc1f5
commit d1ee7797c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"runtime/debug"
@ -164,7 +165,11 @@ import (
// runtime.Version() is the current executing Go version. For example, this is the version of the toolchain directive in go.mod.
// This might differ from the Go command version under the temporary directory.
// To avoid the version mismatch, set the toolchain explicitly (#3086).
if err := runGo("mod", "edit", "-toolchain="+runtime.Version()); err != nil {
t, err := toolchainParameter()
if err != nil {
return tmp, err
}
if err := runGo("mod", "edit", "-toolchain="+t); err != nil {
return tmp, err
}
if err := runGo("mod", "tidy"); err != nil {
@ -212,6 +217,16 @@ import (
return tmp, nil
}
func toolchainParameter() (string, error) {
pattern := regexp.MustCompile(`\bgo\d+\.\d+(\.\d+)?`)
rawVersion := runtime.Version()
m := pattern.FindStringSubmatch(rawVersion)
if len(m) == 0 {
return "", fmt.Errorf("ebitenmobile: unexpected version: %s", rawVersion)
}
return m[0], nil
}
func gomobileHash() (string, error) {
info, ok := debug.ReadBuildInfo()
if !ok {