2015-02-05 21:33:48 +00:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-02-16 13:47:49 -05:00
|
|
|
"bytes"
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
"errors"
|
2015-02-05 21:33:48 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2015-06-30 14:05:08 -04:00
|
|
|
"time"
|
2015-02-05 21:33:48 +00:00
|
|
|
)
|
|
|
|
|
2015-02-16 13:47:49 -05:00
|
|
|
var (
|
2018-03-15 17:30:30 +01:00
|
|
|
goos = runtime.GOOS
|
|
|
|
goarch = runtime.GOARCH
|
2015-02-16 13:47:49 -05:00
|
|
|
)
|
|
|
|
|
2015-02-05 21:33:48 +00:00
|
|
|
var cmdInit = &command{
|
|
|
|
run: runInit,
|
|
|
|
Name: "init",
|
2019-02-22 11:41:06 +01:00
|
|
|
Usage: "[-openal dir]",
|
|
|
|
Short: "build OpenAL for Android",
|
2015-02-05 21:33:48 +00:00
|
|
|
Long: `
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
If a OpenAL source directory is specified with -openal, init will
|
2018-03-15 17:30:30 +01:00
|
|
|
build an Android version of OpenAL for use with gomobile build
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
and gomobile install.
|
2015-02-05 21:33:48 +00:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
2019-02-22 11:41:06 +01:00
|
|
|
var initOpenAL string // -openal
|
2015-02-18 01:45:11 -05:00
|
|
|
|
|
|
|
func init() {
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
cmdInit.flag.StringVar(&initOpenAL, "openal", "", "OpenAL source path")
|
2015-02-18 01:45:11 -05:00
|
|
|
}
|
|
|
|
|
2015-02-05 21:33:48 +00:00
|
|
|
func runInit(cmd *command) error {
|
2015-02-11 13:53:52 -05:00
|
|
|
gopaths := filepath.SplitList(goEnv("GOPATH"))
|
|
|
|
if len(gopaths) == 0 {
|
|
|
|
return fmt.Errorf("GOPATH is not set")
|
|
|
|
}
|
2015-05-03 10:50:35 -04:00
|
|
|
gomobilepath = filepath.Join(gopaths[0], "pkg/gomobile")
|
2015-12-10 15:52:40 -05:00
|
|
|
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-05-03 10:50:35 -04:00
|
|
|
fmt.Fprintln(xout, "GOMOBILE="+gomobilepath)
|
2015-02-12 08:23:25 -05:00
|
|
|
}
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
removeAll(gomobilepath)
|
2015-02-11 13:53:52 -05:00
|
|
|
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
if err := mkdir(gomobilepath); err != nil {
|
2015-05-03 10:50:35 -04:00
|
|
|
return err
|
2015-02-05 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 08:23:25 -05:00
|
|
|
if buildN {
|
2015-05-03 10:50:35 -04:00
|
|
|
tmpdir = filepath.Join(gomobilepath, "work")
|
2015-02-12 08:23:25 -05:00
|
|
|
} else {
|
|
|
|
var err error
|
2015-05-03 10:50:35 -04:00
|
|
|
tmpdir, err = ioutil.TempDir(gomobilepath, "work-")
|
2015-02-12 08:23:25 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-02-16 13:47:49 -05:00
|
|
|
fmt.Fprintln(xout, "WORK="+tmpdir)
|
2015-02-05 21:33:48 +00:00
|
|
|
}
|
2015-07-27 16:33:08 -04:00
|
|
|
defer func() {
|
|
|
|
if buildWork {
|
|
|
|
fmt.Printf("WORK=%s\n", tmpdir)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
removeAll(tmpdir)
|
|
|
|
}()
|
2015-02-05 21:33:48 +00:00
|
|
|
|
2018-03-16 08:34:03 +01:00
|
|
|
// Make sure gobind is up to date.
|
|
|
|
if err := goInstall([]string{"golang.org/x/mobile/cmd/gobind"}, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
if buildN {
|
|
|
|
initOpenAL = "$OPENAL_PATH"
|
|
|
|
} else {
|
|
|
|
if initOpenAL != "" {
|
|
|
|
var err error
|
|
|
|
if initOpenAL, err = filepath.Abs(initOpenAL); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 21:33:48 +00:00
|
|
|
}
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
if err := envInit(); err != nil {
|
2015-07-16 13:32:51 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-30 14:05:08 -04:00
|
|
|
start := time.Now()
|
2015-12-11 17:19:23 -05:00
|
|
|
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
if err := installOpenAL(gomobilepath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-30 14:05:08 -04:00
|
|
|
if buildV {
|
|
|
|
took := time.Since(start) / time.Second * time.Second
|
|
|
|
fmt.Fprintf(os.Stderr, "\nDone, build took %s.\n", took)
|
|
|
|
}
|
2015-06-29 14:37:57 -04:00
|
|
|
return nil
|
|
|
|
}
|
2015-02-18 01:45:11 -05:00
|
|
|
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
func installOpenAL(gomobilepath string) error {
|
2018-03-16 11:40:31 +01:00
|
|
|
if initOpenAL == "" {
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
return nil
|
|
|
|
}
|
2019-02-22 11:41:06 +01:00
|
|
|
ndkRoot, err := ndkRoot()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-16 11:40:31 +01:00
|
|
|
}
|
|
|
|
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
var cmake string
|
|
|
|
if buildN {
|
|
|
|
cmake = "cmake"
|
|
|
|
} else {
|
2017-02-21 22:37:37 +01:00
|
|
|
sdkRoot := os.Getenv("ANDROID_HOME")
|
|
|
|
if sdkRoot == "" {
|
|
|
|
return nil
|
|
|
|
}
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
var err error
|
|
|
|
cmake, err = exec.LookPath("cmake")
|
|
|
|
if err != nil {
|
|
|
|
cmakePath := filepath.Join(sdkRoot, "cmake")
|
|
|
|
cmakeDir, err := os.Open(cmakePath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
// Skip OpenAL install if the cmake package is not installed.
|
|
|
|
return errors.New("cmake was not found in the PATH. Please install it through the Android SDK manager.")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer cmakeDir.Close()
|
|
|
|
// There might be multiple versions of CMake installed. Use any one for now.
|
|
|
|
cmakeVers, err := cmakeDir.Readdirnames(1)
|
|
|
|
if err != nil || len(cmakeVers) == 0 {
|
|
|
|
return errors.New("cmake was not found in the PATH. Please install it through the Android SDK manager.")
|
|
|
|
}
|
|
|
|
cmake = filepath.Join(cmakePath, cmakeVers[0], "bin", "cmake")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var alTmpDir string
|
|
|
|
if buildN {
|
|
|
|
alTmpDir = filepath.Join(gomobilepath, "work")
|
|
|
|
} else {
|
|
|
|
var err error
|
|
|
|
alTmpDir, err = ioutil.TempDir(gomobilepath, "openal-release-")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer removeAll(alTmpDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range []string{"include/AL/al.h", "include/AL/alc.h"} {
|
|
|
|
dst := filepath.Join(gomobilepath, f)
|
|
|
|
src := filepath.Join(initOpenAL, f)
|
|
|
|
if err := copyFile(dst, src); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 13:37:41 +02:00
|
|
|
for _, arch := range allArchs {
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
t := ndk[arch]
|
|
|
|
abi := t.arch
|
|
|
|
if abi == "arm" {
|
|
|
|
abi = "armeabi"
|
|
|
|
}
|
2019-02-22 11:41:06 +01:00
|
|
|
make := filepath.Join(ndkRoot, "prebuilt", archNDK(), "bin", "make")
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
// Split android-XX to get the api version.
|
|
|
|
buildDir := alTmpDir + "/build/" + abi
|
2018-03-15 17:30:30 +01:00
|
|
|
if err := mkdir(buildDir); err != nil {
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
return err
|
|
|
|
}
|
2018-03-15 17:30:30 +01:00
|
|
|
cmd := exec.Command(cmake,
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
initOpenAL,
|
|
|
|
"-DCMAKE_TOOLCHAIN_FILE="+initOpenAL+"/XCompile-Android.txt",
|
2019-02-22 11:41:06 +01:00
|
|
|
"-DHOST="+t.clangPrefix)
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
cmd.Dir = buildDir
|
2019-02-22 11:41:06 +01:00
|
|
|
tcPath := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin")
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
if !buildN {
|
2018-03-15 17:30:30 +01:00
|
|
|
orgPath := os.Getenv("PATH")
|
|
|
|
cmd.Env = []string{"PATH=" + tcPath + string(os.PathListSeparator) + orgPath}
|
cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.
This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.
gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.
gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.
Tested on Linux, macOS, Windows.
Fixes golang/go#16211
Fixes golang/go#18522
Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-13 00:59:09 +01:00
|
|
|
}
|
|
|
|
if err := runCmd(cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = exec.Command(make)
|
|
|
|
cmd.Dir = buildDir
|
|
|
|
if err := runCmd(cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
dst := filepath.Join(gomobilepath, "lib", t.abi, "libopenal.so")
|
|
|
|
src := filepath.Join(alTmpDir, "build", abi, "libopenal.so")
|
|
|
|
if err := copyFile(dst, src); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-20 13:50:18 -04:00
|
|
|
var commonPkgs = []string{
|
|
|
|
"golang.org/x/mobile/gl",
|
|
|
|
"golang.org/x/mobile/app",
|
|
|
|
"golang.org/x/mobile/exp/app/debug",
|
|
|
|
}
|
|
|
|
|
2015-02-12 08:23:25 -05:00
|
|
|
func mkdir(dir string) error {
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-02-12 08:23:25 -05:00
|
|
|
printcmd("mkdir -p %s", dir)
|
|
|
|
}
|
|
|
|
if buildN {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return os.MkdirAll(dir, 0755)
|
|
|
|
}
|
|
|
|
|
|
|
|
func symlink(src, dst string) error {
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-02-12 08:23:25 -05:00
|
|
|
printcmd("ln -s %s %s", src, dst)
|
|
|
|
}
|
|
|
|
if buildN {
|
|
|
|
return nil
|
|
|
|
}
|
2015-03-01 11:09:15 -05:00
|
|
|
if goos == "windows" {
|
|
|
|
return doCopyAll(dst, src)
|
|
|
|
}
|
2015-02-12 08:23:25 -05:00
|
|
|
return os.Symlink(src, dst)
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:52:42 -05:00
|
|
|
func rm(name string) error {
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-02-24 22:52:42 -05:00
|
|
|
printcmd("rm %s", name)
|
|
|
|
}
|
|
|
|
if buildN {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return os.Remove(name)
|
|
|
|
}
|
|
|
|
|
2015-03-01 11:09:15 -05:00
|
|
|
func doCopyAll(dst, src string) error {
|
2015-02-16 13:47:49 -05:00
|
|
|
return filepath.Walk(src, func(path string, info os.FileInfo, errin error) (err error) {
|
|
|
|
if errin != nil {
|
|
|
|
return errin
|
|
|
|
}
|
|
|
|
prefixLen := len(src)
|
|
|
|
if len(path) > prefixLen {
|
|
|
|
prefixLen++ // file separator
|
|
|
|
}
|
|
|
|
outpath := filepath.Join(dst, path[prefixLen:])
|
|
|
|
if info.IsDir() {
|
|
|
|
return os.Mkdir(outpath, 0755)
|
|
|
|
}
|
|
|
|
in, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer in.Close()
|
|
|
|
out, err := os.OpenFile(outpath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, info.Mode())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if errc := out.Close(); err == nil {
|
|
|
|
err = errc
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
_, err = io.Copy(out, in)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-12 08:23:25 -05:00
|
|
|
func removeAll(path string) error {
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-04-20 17:11:20 -04:00
|
|
|
printcmd(`rm -r -f "%s"`, path)
|
2015-02-12 08:23:25 -05:00
|
|
|
}
|
|
|
|
if buildN {
|
|
|
|
return nil
|
|
|
|
}
|
2015-07-27 16:33:08 -04:00
|
|
|
|
2015-03-01 11:09:15 -05:00
|
|
|
// os.RemoveAll behaves differently in windows.
|
|
|
|
// http://golang.org/issues/9606
|
|
|
|
if goos == "windows" {
|
|
|
|
resetReadOnlyFlagAll(path)
|
|
|
|
}
|
|
|
|
|
2015-02-12 08:23:25 -05:00
|
|
|
return os.RemoveAll(path)
|
|
|
|
}
|
|
|
|
|
2015-03-01 11:09:15 -05:00
|
|
|
func resetReadOnlyFlagAll(path string) error {
|
|
|
|
fi, err := os.Stat(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !fi.IsDir() {
|
|
|
|
return os.Chmod(path, 0666)
|
|
|
|
}
|
|
|
|
fd, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.Close()
|
|
|
|
|
|
|
|
names, _ := fd.Readdirnames(-1)
|
|
|
|
for _, name := range names {
|
|
|
|
resetReadOnlyFlagAll(path + string(filepath.Separator) + name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-05 21:33:48 +00:00
|
|
|
func goEnv(name string) string {
|
|
|
|
if val := os.Getenv(name); val != "" {
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
val, err := exec.Command("go", "env", name).Output()
|
|
|
|
if err != nil {
|
|
|
|
panic(err) // the Go tool was tested to work earlier
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(val))
|
|
|
|
}
|
2015-07-19 21:29:35 -04:00
|
|
|
|
|
|
|
func runCmd(cmd *exec.Cmd) error {
|
2015-07-21 15:44:18 -04:00
|
|
|
if buildX || buildN {
|
2015-07-19 21:29:35 -04:00
|
|
|
dir := ""
|
|
|
|
if cmd.Dir != "" {
|
|
|
|
dir = "PWD=" + cmd.Dir + " "
|
|
|
|
}
|
|
|
|
env := strings.Join(cmd.Env, " ")
|
|
|
|
if env != "" {
|
|
|
|
env += " "
|
|
|
|
}
|
|
|
|
printcmd("%s%s%s", dir, env, strings.Join(cmd.Args, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
buf.WriteByte('\n')
|
|
|
|
if buildV {
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
} else {
|
|
|
|
cmd.Stdout = buf
|
|
|
|
cmd.Stderr = buf
|
|
|
|
}
|
|
|
|
|
2015-07-27 16:33:08 -04:00
|
|
|
if buildWork {
|
|
|
|
if goos == "windows" {
|
|
|
|
cmd.Env = append(cmd.Env, `TEMP=`+tmpdir)
|
|
|
|
cmd.Env = append(cmd.Env, `TMP=`+tmpdir)
|
|
|
|
} else {
|
|
|
|
cmd.Env = append(cmd.Env, `TMPDIR=`+tmpdir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 21:29:35 -04:00
|
|
|
if !buildN {
|
|
|
|
cmd.Env = environ(cmd.Env)
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
return fmt.Errorf("%s failed: %v%s", strings.Join(cmd.Args, " "), err, buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|