1#!/usr/bin/env python 2# 3# Copyright (C) 2015 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17"""Interface to NDK build information.""" 18import os 19import re 20import sys 21 22import util 23 24 25THIS_DIR = os.path.dirname(os.path.realpath(__file__)) 26NDK_ROOT = os.path.realpath(os.path.join(THIS_DIR, '..')) 27 28 29def get_host_tag(): 30 if sys.platform.startswith('linux'): 31 return 'linux-x86_64' 32 elif sys.platform == 'darwin': 33 return 'darwin-x86_64' 34 elif sys.platform == 'win32': 35 host_tag = 'windows-x86_64' 36 test_path = os.path.join(os.environ['NDK'], 'prebuilt', host_tag) 37 if not os.path.exists(test_path): 38 host_tag = 'windows' 39 return host_tag 40 41 42def get_tool(tool): 43 ext = '' 44 if sys.platform == 'win32': 45 ext = '.exe' 46 47 host_tag = get_host_tag() 48 prebuilt_path = os.path.join(os.environ['NDK'], 'prebuilt', host_tag) 49 return os.path.join(prebuilt_path, 'bin', tool) + ext 50 51 52def build(build_flags): 53 ndk_build_path = os.path.join(os.environ['NDK'], 'ndk-build') 54 if os.name == 'nt': 55 ndk_build_path += '.cmd' 56 return util.call_output([ndk_build_path] + build_flags) 57 58 59def expand_app_abi(abi): 60 all32 = ('armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'mips', 'x86') 61 all64 = ('arm64-v8a', 'mips64', 'x86_64') 62 all_abis = all32 + all64 63 if abi == 'all': 64 return all_abis 65 elif abi == 'all32': 66 return all32 67 elif abi == 'all64': 68 return all64 69 return re.split(r'\s+', abi) 70