mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
cmd/gogio: support newer NDKs
Newer Windows NDKs add the "x86_64" platform suffix like other OS'es. Remove the special case. Newer NDKs are also installed in "ndk/x.y.z" versioned directories instead of in "ndk-bundle". Support that. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+46
-25
@@ -154,9 +154,9 @@ func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not find javac: %v", err)
|
return fmt.Errorf("could not find javac: %v", err)
|
||||||
}
|
}
|
||||||
ndkRoot := filepath.Join(androidHome, "ndk-bundle")
|
ndkRoot, err := findNDK(androidHome)
|
||||||
if _, err := os.Stat(ndkRoot); err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("no NDK found in $ANDROID_HOME/ndk-bundle (%s). Use `sdkmanager ndk-bundle` to install it", ndkRoot)
|
return err
|
||||||
}
|
}
|
||||||
tcRoot := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK())
|
tcRoot := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK())
|
||||||
var builds errgroup.Group
|
var builds errgroup.Group
|
||||||
@@ -568,6 +568,22 @@ func unzip(dir, zipfile string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findNDK(androidHome string) (string, error) {
|
||||||
|
ndks, err := filepath.Glob(filepath.Join(androidHome, "ndk", "*"))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if bestNDK, found := latestVersionPath(ndks); found {
|
||||||
|
return bestNDK, nil
|
||||||
|
}
|
||||||
|
// The old NDK path was $ANDROID_HOME/ndk-bundle.
|
||||||
|
ndkBundle := filepath.Join(androidHome, "ndk-bundle")
|
||||||
|
if _, err := os.Stat(ndkBundle); err == nil {
|
||||||
|
return ndkBundle, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("no NDK found in $ANDROID_HOME (%s). Use `sdkmanager ndk-bundle` to install it", androidHome)
|
||||||
|
}
|
||||||
|
|
||||||
func findKeytool() (string, error) {
|
func findKeytool() (string, error) {
|
||||||
keytool, err := exec.LookPath("keytool")
|
keytool, err := exec.LookPath("keytool")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -636,20 +652,16 @@ Created-By: 1.0 (Go)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func archNDK() string {
|
func archNDK() string {
|
||||||
if runtime.GOOS == "windows" {
|
var arch string
|
||||||
return "windows"
|
switch runtime.GOARCH {
|
||||||
} else {
|
case "386":
|
||||||
var arch string
|
arch = "x86"
|
||||||
switch runtime.GOARCH {
|
case "amd64":
|
||||||
case "386":
|
arch = "x86_64"
|
||||||
arch = "x86"
|
default:
|
||||||
case "amd64":
|
panic("unsupported GOARCH: " + runtime.GOARCH)
|
||||||
arch = "x86_64"
|
|
||||||
default:
|
|
||||||
panic("unsupported GOARCH: " + runtime.GOARCH)
|
|
||||||
}
|
|
||||||
return runtime.GOOS + "-" + arch
|
|
||||||
}
|
}
|
||||||
|
return runtime.GOOS + "-" + arch
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPermissions(ps []string) ([]string, []string) {
|
func getPermissions(ps []string) ([]string, []string) {
|
||||||
@@ -733,7 +745,7 @@ func latestCompiler(tcRoot, a string, minsdk int) (string, error) {
|
|||||||
bestCompiler = firstCompiler
|
bestCompiler = firstCompiler
|
||||||
}
|
}
|
||||||
if bestCompiler == "" {
|
if bestCompiler == "" {
|
||||||
return "", fmt.Errorf("no NDK compiler found for architecture %s", a)
|
return "", fmt.Errorf("no NDK compiler found for architecture %s in %s", a, tcRoot)
|
||||||
}
|
}
|
||||||
return bestCompiler, nil
|
return bestCompiler, nil
|
||||||
}
|
}
|
||||||
@@ -743,11 +755,23 @@ func latestTools(sdk string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
tools, found := latestVersionPath(allTools)
|
||||||
|
if !found {
|
||||||
|
return "", fmt.Errorf("no build-tools found in %q", sdk)
|
||||||
|
}
|
||||||
|
return tools, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// latestVersionFile finds the path with the highest version
|
||||||
|
// among paths on the form
|
||||||
|
//
|
||||||
|
// /some/path/major.minor.patch
|
||||||
|
func latestVersionPath(paths []string) (string, bool) {
|
||||||
var bestVer [3]int
|
var bestVer [3]int
|
||||||
var bestTools string
|
var bestDir string
|
||||||
loop:
|
loop:
|
||||||
for _, tools := range allTools {
|
for _, path := range paths {
|
||||||
_, name := filepath.Split(tools)
|
name := filepath.Base(path)
|
||||||
s := strings.SplitN(name, ".", 3)
|
s := strings.SplitN(name, ".", 3)
|
||||||
if len(s) != len(bestVer) {
|
if len(s) != len(bestVer) {
|
||||||
continue
|
continue
|
||||||
@@ -767,12 +791,9 @@ loop:
|
|||||||
version[i] = v
|
version[i] = v
|
||||||
}
|
}
|
||||||
bestVer = version
|
bestVer = version
|
||||||
bestTools = tools
|
bestDir = path
|
||||||
}
|
}
|
||||||
if bestTools == "" {
|
return bestDir, bestDir != ""
|
||||||
return "", fmt.Errorf("no build-tools found in %q", sdk)
|
|
||||||
}
|
|
||||||
return bestTools, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newZipWriter(w io.Writer) *zipWriter {
|
func newZipWriter(w io.Writer) *zipWriter {
|
||||||
|
|||||||
Reference in New Issue
Block a user