| Index: go/mobile_env.py
|
| diff --git a/go/mobile_env.py b/go/mobile_env.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..6a31d9c98bb5a3f0e4fb3e6356887fa3ab167c0d
|
| --- /dev/null
|
| +++ b/go/mobile_env.py
|
| @@ -0,0 +1,82 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2014 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""Like env.py, but for building go-on-mobile.
|
| +
|
| +It wraps env.py, runs `gomobile init`, and adds mobile-specific env vars.
|
| +"""
|
| +
|
| +assert __name__ == '__main__'
|
| +
|
| +import os
|
| +import pipes
|
| +import platform
|
| +import subprocess
|
| +import sys
|
| +
|
| +
|
| +ANDROID_NDK_PATH = os.path.join(
|
| + os.path.abspath(os.path.dirname(__file__)), '.vendor', 'pkg', 'gomobile',
|
| + 'android-ndk-r12b')
|
| +
|
| +# Used for mapping GOARCH values to NDK toolsets.
|
| +ANDROID_TOOLSETS = {
|
| + 'arm': 'arm',
|
| + 'arm64': 'aarch64',
|
| + '386': 'x86',
|
| + 'amd64': 'x86_64',
|
| +}
|
| +
|
| +
|
| +def _get_android_env(env):
|
| + """Adds GO* and C* environment variables needed for building for android."""
|
| + if platform.system() != 'Linux':
|
| + raise Exception(
|
| + 'Only Linux hosts supported for android cross-compiling')
|
| +
|
| + arch = env.get('GOARCH')
|
| + if arch not in ANDROID_TOOLSETS:
|
| + raise Exception(
|
| + 'Specified arch not currently supported on android: %s' % arch)
|
| +
|
| + toolset = ANDROID_TOOLSETS[arch]
|
| +
|
| + # Needed when cross-compiling uses of cgo.
|
| + env['CGO_ENABLED'] = '1'
|
| + env['CC'] = os.path.join(
|
| + ANDROID_NDK_PATH, arch, 'bin', '%s-linux-androideabi-clang' % toolset)
|
| + env['CXX'] = os.path.join(
|
| + ANDROID_NDK_PATH, arch, 'bin', '%s-linux-androideabi-clang++' % toolset)
|
| +
|
| + # Compiler/linker needs access to android system headers in the NDK.
|
| + sysroot_path = os.path.join(ANDROID_NDK_PATH, arch, 'sysroot')
|
| + env['CGO_CFLAGS'] = '-I %s/usr/include --sysroot %s' % (
|
| + sysroot_path, sysroot_path)
|
| + env['CGO_LDFLAGS'] = '-L %s/usr/lib --sysroot %s' % (
|
| + sysroot_path, sysroot_path)
|
| +
|
| +
|
| +# Run `gomobile init` to fetch the android NDK.
|
| +if not os.path.exists(ANDROID_NDK_PATH):
|
| + cmd = [sys.executable, 'env.py', 'gomobile', 'init']
|
| + subprocess.check_call(cmd)
|
| +
|
| +# Keep track of any changed env vars for printing to stdout later.
|
| +old = os.environ.copy()
|
| +new = os.environ.copy()
|
| +if 'android' in old.get('GOOS', ''):
|
| + _get_android_env(new)
|
| +
|
| +cwd = os.path.dirname(os.path.realpath(__file__))
|
| +if len(sys.argv) == 1:
|
| + cmd = [sys.executable, 'env.py']
|
| + print subprocess.check_output(cmd, env=new, cwd=cwd).strip()
|
| + for key, value in sorted(new.iteritems()):
|
| + if old.get(key) != value:
|
| + print 'export %s=%s' % (key, pipes.quote(value))
|
| +else:
|
| + cmd = [sys.executable, 'env.py']
|
| + cmd.extend(sys.argv[1:])
|
| + sys.exit(subprocess.call(cmd, env=new, cwd=cwd))
|
|
|