e1f6c08aee9e7c56c670cea83224057eff5af062
[platform/upstream/VK-GL-CTS.git] / android / scripts / common.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 import sys
5 import shlex
6 import subprocess
7
8 class NativeLib:
9         def __init__ (self, libName, apiVersion, abiVersion):
10                 self.libName            = libName
11                 self.apiVersion         = apiVersion
12                 self.abiVersion         = abiVersion
13
14 def getPlatform ():
15         if sys.platform.startswith('linux'):
16                 return 'linux'
17         else:
18                 return sys.platform
19
20 def 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
29 def isExecutable (path):
30         return os.path.isfile(path) and os.access(path, os.X_OK)
31
32 def 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
41 def isBinaryInPath (binName):
42         return which(binName) != None
43
44 def 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
51 def die (msg):
52         print msg
53         exit(-1)
54
55 def shellquote(s):
56         return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`')
57
58 def 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
64 def 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
70 ANDROID_DIR                             = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
71
72 # Build configuration
73 NATIVE_LIBS                             = [
74                 #                 library name          API  ABI
75 #               NativeLib("testercore_legacy",  5,      "armeabi-v7a"),         # Pre-gingerbread
76 #               NativeLib("testercore_legacy",  5,      "armeabi"),                     # ARM v5 ABI / pre-gingerbread
77                 NativeLib("testercore",                 9,      "armeabi-v7a"),         # ARM v7a ABI
78 #               NativeLib("testercore",                 9,      "x86"),                         # x86
79         ]
80 ANDROID_JAVA_API                = "android-10"
81
82 # NDK paths
83 ANDROID_NDK_HOST_OS             = getCfg({
84                 'win32':        "windows",
85                 'darwin':       "darwin-x86",
86                 'linux':        "linux-x86"
87         })
88 ANDROID_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         })
93 ANDROID_NDK_TOOLCHAIN_VERSION = "clang-r9d" # Toolchain file is selected based on this
94
95 def getWin32Generator ():
96         if which("jom.exe") != None:
97                 return "NMake Makefiles JOM"
98         else:
99                 return "NMake Makefiles"
100
101 # Native code build settings
102 CMAKE_GENERATOR                 = getCfg({
103                 'win32':        getWin32Generator(),
104                 'darwin':       "Unix Makefiles",
105                 'linux':        "Unix Makefiles"
106         })
107 BUILD_CMD                               = getCfg({
108                 'win32':        "cmake --build .",
109                 'darwin':       "cmake --build . -- -j 4",
110                 'linux':        "cmake --build . -- -j 4"
111         })
112
113 # SDK paths
114 ANDROID_SDK_PATHS               = [
115         "C:/android/android-sdk-windows",
116         os.path.expanduser("~/android-sdk-mac_x86"),
117         os.path.expanduser("~/android-sdk-linux")
118         ]
119 ANDROID_BIN                             = getCfg({
120                 'win32':        selectBin(ANDROID_SDK_PATHS, "tools/android.bat"),
121                 'other':        selectBin(ANDROID_SDK_PATHS, "tools/android"),
122         })
123 ADB_BIN                                 = getCfg({
124                 'win32':        selectBin(ANDROID_SDK_PATHS, "platform-tools/adb.exe"),
125                 'other':        selectBin(ANDROID_SDK_PATHS, "platform-tools/adb"),
126         })
127 ZIPALIGN_BIN                    = getCfg({
128                 'win32':        selectBin(ANDROID_SDK_PATHS, "tools/zipalign.exe"),
129                 'other':        selectBin(ANDROID_SDK_PATHS, "tools/zipalign"),
130         })
131 JARSIGNER_BIN                   = "jarsigner"
132
133 # Apache ant
134 ANT_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         ]
140 ANT_BIN                                 = getCfg({
141                 'win32':        selectBin(ANT_PATHS, "bin/ant.bat"),
142                 'other':        selectBin(ANT_PATHS, "bin/ant")
143         })