cmd/gomobile: pack OpenAL libraries into the apk if audio is imported

Fixes #10058.

Change-Id: Ie947f98d2ebbf1f851e1eb68132ddfe848c9aa94
Reviewed-on: https://go-review.googlesource.com/7020
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Burcu Dogan 2015-03-05 20:58:01 -08:00
parent 33ee14d530
commit b316a2d0ce
1 changed files with 55 additions and 0 deletions

View File

@ -198,6 +198,33 @@ func runBuild(cmd *command) error {
} }
} }
importsAudio := pkgImportsAudio(pkg)
if importsAudio {
alDir := filepath.Join(ndkccpath, "openal/lib")
filepath.Walk(alDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
name := "lib/" + path[len(alDir)+1:]
w, err := apkwcreate(name)
if err != nil {
return err
}
if !buildN {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(w, f)
}
return err
})
}
// Add any assets. // Add any assets.
assetsDir := filepath.Join(pkg.Dir, "assets") assetsDir := filepath.Join(pkg.Dir, "assets")
assetsDirExists := true assetsDirExists := true
@ -370,6 +397,34 @@ func gobuild(src, libPath string) error {
return nil return nil
} }
var importsAudioPkgs = make(map[string]struct{})
// pkgImportsAudio returns true if the given package or one of its
// dependencies imports the mobile/audio package.
func pkgImportsAudio(pkg *build.Package) bool {
for _, path := range pkg.Imports {
if path == "C" {
continue
}
if _, ok := importsAudioPkgs[path]; ok {
continue
}
importsAudioPkgs[path] = struct{}{}
if strings.HasPrefix(path, "golang.org/x/mobile/audio") {
return true
}
dPkg, err := ctx.Import(path, "", build.ImportComment)
if err != nil {
fmt.Fprintf(os.Stderr, "error while looking up for the audio package: %v", err)
os.Exit(2)
}
if pkgImportsAudio(dPkg) {
return true
}
}
return false
}
func init() { func init() {
buildO = cmdBuild.flag.String("o", "", "output file") buildO = cmdBuild.flag.String("o", "", "output file")
addBuildFlags(cmdBuild) addBuildFlags(cmdBuild)