1# -*- coding: utf-8 -*- 2 3import os 4import sys 5import shlex 6import subprocess 7 8class NativeLib: 9 def __init__ (self, libName, apiVersion, abiVersion): 10 self.libName = libName 11 self.apiVersion = apiVersion 12 self.abiVersion = abiVersion 13 14def getPlatform (): 15 if sys.platform.startswith('linux'): 16 return 'linux' 17 else: 18 return sys.platform 19 20def getCfg (variants): 21 platform = getPlatform() 22 if platform in variants: 23 return variants[platform] 24 elif 'other' in variants: 25 return variants['other'] 26 else: 27 raise Exception("No configuration for '%s'" % platform) 28 29def isExecutable (path): 30 return os.path.isfile(path) and os.access(path, os.X_OK) 31 32def which (binName): 33 for path in os.environ['PATH'].split(os.pathsep): 34 path = path.strip('"') 35 fullPath = os.path.join(path, binName) 36 if isExecutable(fullPath): 37 return fullPath 38 39 return None 40 41def isBinaryInPath (binName): 42 return which(binName) != None 43 44def selectBin (basePaths, relBinPath): 45 for basePath in basePaths: 46 fullPath = os.path.normpath(os.path.join(basePath, relBinPath)) 47 if isExecutable(fullPath): 48 return fullPath 49 return which(os.path.basename(relBinPath)) 50 51def die (msg): 52 print msg 53 exit(-1) 54 55def shellquote(s): 56 return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`') 57 58def execute (commandLine): 59 args = shlex.split(commandLine) 60 retcode = subprocess.call(args) 61 if retcode != 0: 62 raise Exception("Failed to execute '%s', got %d" % (commandLine, retcode)) 63 64def execArgs (args): 65 retcode = subprocess.call(args) 66 if retcode != 0: 67 raise Exception("Failed to execute '%s', got %d" % (str(args), retcode)) 68 69# deqp/android path 70ANDROID_DIR = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) 71 72# Build configuration 73NATIVE_LIBS = [ 74 # library name API ABI 75# NativeLib("testercore", 13, "armeabi"), # ARM v5 ABI 76 NativeLib("testercore", 13, "armeabi-v7a"), # ARM v7a ABI 77 NativeLib("testercore", 13, "x86"), # x86 78# NativeLib("testercore", 21, "arm64-v8a"), # ARM64 v8a ABI 79 ] 80ANDROID_JAVA_API = "android-13" 81 82# NDK paths 83ANDROID_NDK_HOST_OS = getCfg({ 84 'win32': "windows", 85 'darwin': "darwin-x86", 86 'linux': "linux-x86" 87 }) 88ANDROID_NDK_PATH = getCfg({ 89 'win32': "C:/android/android-ndk-r9d", 90 'darwin': os.path.expanduser("~/android-ndk-r9d"), 91 'linux': os.path.expanduser("~/android-ndk-r9d") 92 }) 93ANDROID_NDK_TOOLCHAIN_VERSION = "clang-r9d" # Toolchain file is selected based on this 94 95def getWin32Generator (): 96 if which("jom.exe") != None: 97 return "NMake Makefiles JOM" 98 else: 99 return "NMake Makefiles" 100 101# Native code build settings 102CMAKE_GENERATOR = getCfg({ 103 'win32': getWin32Generator(), 104 'darwin': "Unix Makefiles", 105 'linux': "Unix Makefiles" 106 }) 107BUILD_CMD = getCfg({ 108 'win32': "cmake --build .", 109 'darwin': "cmake --build . -- -j 4", 110 'linux': "cmake --build . -- -j 4" 111 }) 112 113# SDK paths 114ANDROID_SDK_PATHS = [ 115 "C:/android/android-sdk-windows", 116 os.path.expanduser("~/android-sdk-mac_x86"), 117 os.path.expanduser("~/android-sdk-linux") 118 ] 119ANDROID_BIN = getCfg({ 120 'win32': selectBin(ANDROID_SDK_PATHS, "tools/android.bat"), 121 'other': selectBin(ANDROID_SDK_PATHS, "tools/android"), 122 }) 123ADB_BIN = getCfg({ 124 'win32': selectBin(ANDROID_SDK_PATHS, "platform-tools/adb.exe"), 125 'other': selectBin(ANDROID_SDK_PATHS, "platform-tools/adb"), 126 }) 127ZIPALIGN_BIN = getCfg({ 128 'win32': selectBin(ANDROID_SDK_PATHS, "tools/zipalign.exe"), 129 'other': selectBin(ANDROID_SDK_PATHS, "tools/zipalign"), 130 }) 131JARSIGNER_BIN = "jarsigner" 132 133# Apache ant 134ANT_PATHS = [ 135 "C:/android/apache-ant-1.8.4", 136 "C:/android/apache-ant-1.9.2", 137 "C:/android/apache-ant-1.9.3", 138 "C:/android/apache-ant-1.9.4", 139 ] 140ANT_BIN = getCfg({ 141 'win32': selectBin(ANT_PATHS, "bin/ant.bat"), 142 'other': selectBin(ANT_PATHS, "bin/ant") 143 }) 144