1# -*- coding: utf-8 -*- 2 3import os 4import re 5import sys 6import shutil 7import argparse 8 9import common 10 11def getStoreKeyPasswords (filename): 12 f = open(filename) 13 storepass = None 14 keypass = None 15 for line in f: 16 m = re.search('([a-z]+)\s*\=\s*"([^"]+)"', line) 17 if m != None: 18 if m.group(1) == "storepass": 19 storepass = m.group(2) 20 elif m.group(1) == "keypass": 21 keypass = m.group(2) 22 f.close() 23 if storepass == None or keypass == None: 24 common.die("Could not read signing key passwords") 25 return (storepass, keypass) 26 27def getNativeBuildDir (nativeLib, buildType): 28 deqpDir = os.path.normpath(os.path.join(common.ANDROID_DIR, "..")) 29 return os.path.normpath(os.path.join(deqpDir, "android", "build", "%s-%d-%s" % (buildType.lower(), nativeLib.apiVersion, nativeLib.abiVersion))) 30 31def buildNative (nativeLib, buildType): 32 deqpDir = os.path.normpath(os.path.join(common.ANDROID_DIR, "..")) 33 buildDir = getNativeBuildDir(nativeLib, buildType) 34 assetsDir = os.path.join(buildDir, "assets") 35 libsDir = os.path.join(common.ANDROID_DIR, "package", "libs", nativeLib.abiVersion) 36 srcLibFile = os.path.join(buildDir, "libtestercore.so") 37 dstLibFile = os.path.join(libsDir, "lib%s.so" % nativeLib.libName) 38 39 # Remove old lib files if such exist 40 if os.path.exists(srcLibFile): 41 os.unlink(srcLibFile) 42 43 if os.path.exists(dstLibFile): 44 os.unlink(dstLibFile) 45 46 # Remove assets directory so that we don't collect unnecessary cruft to the APK 47 if os.path.exists(assetsDir): 48 shutil.rmtree(assetsDir) 49 50 # Make build directory if necessary 51 if not os.path.exists(buildDir): 52 os.makedirs(buildDir) 53 os.chdir(buildDir) 54 common.execArgs([ 55 'cmake', 56 '-G%s' % common.CMAKE_GENERATOR, 57 '-DCMAKE_TOOLCHAIN_FILE=%s/framework/delibs/cmake/toolchain-android-%s.cmake' % (deqpDir, common.ANDROID_NDK_TOOLCHAIN_VERSION), 58 '-DANDROID_NDK_HOST_OS=%s' % common.ANDROID_NDK_HOST_OS, 59 '-DANDROID_NDK_PATH=%s' % common.ANDROID_NDK_PATH, 60 '-DANDROID_ABI=%s' % nativeLib.abiVersion, 61 '-DDE_ANDROID_API=%s' % nativeLib.apiVersion, 62 '-DCMAKE_BUILD_TYPE=%s' % buildType, 63 '-DDEQP_TARGET=android', 64 deqpDir 65 ]) 66 67 os.chdir(buildDir) 68 common.execute(common.BUILD_CMD) 69 70 if not os.path.exists(libsDir): 71 os.makedirs(libsDir) 72 73 # Copy libtestercore.so 74 shutil.copyfile(srcLibFile, dstLibFile) 75 76 # Copy gdbserver for debugging 77 if buildType.lower() == "debug": 78 if nativeLib.abiVersion == "x86": 79 shutil.copyfile(os.path.join(common.ANDROID_NDK_PATH, "prebuilt/android-x86/gdbserver/gdbserver"), os.path.join(libsDir, "gdbserver")) 80 elif nativeLib.abiVersion == "armeabi-v7a": 81 shutil.copyfile(os.path.join(common.ANDROID_NDK_PATH, "prebuilt/android-arm/gdbserver/gdbserver"), os.path.join(libsDir, "gdbserver")) 82 else: 83 print("Unknown ABI. Won't copy gdbserver to package") 84 elif os.path.exists(os.path.join(libsDir, "gdbserver")): 85 # Make sure there is no gdbserver if build is not debug build 86 os.unlink(os.path.join(libsDir, "gdbserver")) 87 88def copyAssets (nativeLib, buildType): 89 srcDir = os.path.join(getNativeBuildDir(nativeLib, buildType), "assets") 90 dstDir = os.path.join(common.ANDROID_DIR, "package", "assets") 91 92 if os.path.exists(dstDir): 93 shutil.rmtree(dstDir) 94 95 if os.path.exists(srcDir): 96 shutil.copytree(srcDir, dstDir) 97 98def fileContains (filename, str): 99 f = open(filename, 'rb') 100 data = f.read() 101 f.close() 102 103 return data.find(str) >= 0 104 105def buildApp (isRelease): 106 appDir = os.path.join(common.ANDROID_DIR, "package") 107 108 # Set up app 109 os.chdir(appDir) 110 common.execute("%s update project --name dEQP --path . --target %s" % (common.shellquote(common.ANDROID_BIN), common.ANDROID_JAVA_API)) 111 112 # Build 113 common.execute("%s %s" % (common.shellquote(common.ANT_BIN), "release" if isRelease else "debug")) 114 115def signApp (keystore, keyname, storepass, keypass): 116 os.chdir(os.path.join(common.ANDROID_DIR, "package")) 117 common.execute("%s -keystore %s -storepass %s -keypass %s -sigfile CERT -digestalg SHA1 -sigalg MD5withRSA -signedjar bin/dEQP-unaligned.apk bin/dEQP-release-unsigned.apk %s" % (common.shellquote(common.JARSIGNER_BIN), common.shellquote(keystore), storepass, keypass, keyname)) 118 common.execute("%s -f 4 bin/dEQP-unaligned.apk bin/dEQP-release.apk" % (common.shellquote(common.ZIPALIGN_BIN))) 119 120def build (isRelease=False, nativeBuildType="Release"): 121 curDir = os.getcwd() 122 123 try: 124 # Build native code 125 for lib in common.NATIVE_LIBS: 126 buildNative(lib, nativeBuildType) 127 128 # Copy assets from first build dir 129 copyAssets(common.NATIVE_LIBS[0], nativeBuildType) 130 131 # Build java code and .apk 132 buildApp(isRelease) 133 134 finally: 135 # Restore working dir 136 os.chdir(curDir) 137 138if __name__ == "__main__": 139 parser = argparse.ArgumentParser() 140 parser.add_argument('--is-release', dest='isRelease', type=bool, default=False, help="Build android project in release mode.") 141 parser.add_argument('--native-build-type', dest='nativeBuildType', default="Release", help="Build type passed cmake when building native code.") 142 143 args = parser.parse_args() 144 145 build(isRelease=args.isRelease, nativeBuildType=args.nativeBuildType) 146