1 # -*- coding: utf-8 -*-
11 def getStoreKeyPasswords (filename):
16 m = re.search('([a-z]+)\s*\=\s*"([^"]+)"', line)
18 if m.group(1) == "storepass":
19 storepass = m.group(2)
20 elif m.group(1) == "keypass":
23 if storepass == None or keypass == None:
24 common.die("Could not read signing key passwords")
25 return (storepass, keypass)
27 def getNativeBuildDir (buildRoot, nativeLib, buildType):
28 buildName = "%s-%d-%s" % (buildType.lower(), nativeLib.apiVersion, nativeLib.abiVersion)
29 return os.path.normpath(os.path.join(buildRoot, "native", buildName))
31 def getAssetsDir (buildRoot, nativeLib, buildType):
32 return os.path.join(getNativeBuildDir(buildRoot, nativeLib, buildType), "assets")
34 def getPrebuiltsDirName (abiName):
37 'armeabi-v7a': 'android-arm',
38 'arm64-v8a': 'android-arm64'
41 if not abiName in PREBUILT_DIRS:
42 raise Exception("Unknown ABI %s, don't know where prebuilts are" % abiName)
44 return PREBUILT_DIRS[abiName]
46 def buildNative (buildRoot, libTargetDir, nativeLib, buildType):
47 deqpDir = os.path.normpath(os.path.join(common.ANDROID_DIR, ".."))
48 buildDir = getNativeBuildDir(buildRoot, nativeLib, buildType)
49 libsDir = os.path.join(libTargetDir, nativeLib.abiVersion)
50 srcLibFile = os.path.join(buildDir, common.NATIVE_LIB_NAME)
51 dstLibFile = os.path.join(libsDir, common.NATIVE_LIB_NAME)
53 # Make build directory if necessary
54 if not os.path.exists(buildDir):
57 toolchainFile = '%s/framework/delibs/cmake/toolchain-android-%s.cmake' % (deqpDir, common.ANDROID_NDK_TOOLCHAIN_VERSION)
60 '-G%s' % common.CMAKE_GENERATOR,
61 '-DCMAKE_TOOLCHAIN_FILE=%s' % toolchainFile,
62 '-DANDROID_NDK_HOST_OS=%s' % common.ANDROID_NDK_HOST_OS,
63 '-DANDROID_NDK_PATH=%s' % common.ANDROID_NDK_PATH,
64 '-DANDROID_ABI=%s' % nativeLib.abiVersion,
65 '-DDE_ANDROID_API=%s' % nativeLib.apiVersion,
66 '-DCMAKE_BUILD_TYPE=%s' % buildType,
67 '-DDEQP_TARGET=android',
72 common.execArgs(['cmake', '--build', '.'] + common.EXTRA_BUILD_ARGS)
74 if not os.path.exists(libsDir):
77 shutil.copyfile(srcLibFile, dstLibFile)
79 # Copy gdbserver for debugging
80 if buildType.lower() == "debug":
81 srcGdbserverPath = os.path.join(common.ANDROID_NDK_PATH,
83 getPrebuiltsDirName(nativeLib.abiVersion),
86 dstGdbserverPath = os.path.join(libsDir, 'gdbserver')
87 shutil.copyfile(srcGdbserverPath, dstGdbserverPath)
89 assert not os.path.exists(os.path.join(libsDir, "gdbserver"))
91 def buildApp (buildRoot, isRelease):
92 appDir = os.path.join(buildRoot, "package")
97 manifestSrcPath = os.path.normpath(os.path.join(common.ANDROID_DIR, "package", "AndroidManifest.xml"))
98 manifestDstPath = os.path.normpath(os.path.join(appDir, "AndroidManifest.xml"))
100 # Build dir can be the Android dir, in which case the copy is not needed.
101 if manifestSrcPath != manifestDstPath:
102 shutil.copy(manifestSrcPath, manifestDstPath)
109 '--target', str(common.ANDROID_JAVA_API),
115 "release" if isRelease else "debug",
116 "-Dsource.dir=" + os.path.join(common.ANDROID_DIR, "package", "src"),
117 "-Dresource.absolute.dir=" + os.path.join(common.ANDROID_DIR, "package", "res")
120 def signApp (keystore, keyname, storepass, keypass):
121 os.chdir(os.path.join(common.ANDROID_DIR, "package"))
123 common.JARSIGNER_BIN,
124 '-keystore', keystore,
125 '-storepass', storepass,
128 '-digestalg', 'SHA1',
129 '-sigalg', 'MD5withRSA',
130 '-signedjar', 'bin/dEQP-unaligned.apk',
131 'bin/dEQP-release-unsigned.apk',
137 'bin/dEQP-unaligned.apk',
138 'bin/dEQP-release.apk'
141 def build (buildRoot=common.ANDROID_DIR, isRelease=False, nativeBuildType="Release"):
145 assetsSrcDir = getAssetsDir(buildRoot, common.NATIVE_LIBS[0], nativeBuildType)
146 assetsDstDir = os.path.join(buildRoot, "package", "assets")
148 # Remove assets from the first build dir where we copy assets from
149 # to avoid collecting cruft there.
150 if os.path.exists(assetsSrcDir):
151 shutil.rmtree(assetsSrcDir)
152 if os.path.exists(assetsDstDir):
153 shutil.rmtree(assetsDstDir)
155 # Remove old libs dir to avoid collecting out-of-date versions
156 # of libs for ABIs not built this time.
157 libTargetDir = os.path.join(buildRoot, "package", "libs")
158 if os.path.exists(libTargetDir):
159 shutil.rmtree(libTargetDir)
162 for lib in common.NATIVE_LIBS:
163 buildNative(buildRoot, libTargetDir, lib, nativeBuildType)
166 if os.path.exists(assetsSrcDir):
167 shutil.copytree(assetsSrcDir, assetsDstDir)
169 # Build java code and .apk
170 buildApp(buildRoot, isRelease)
173 # Restore working dir
176 if __name__ == "__main__":
177 parser = argparse.ArgumentParser()
178 parser.add_argument('--is-release', dest='isRelease', type=bool, default=False, help="Build android project in release mode.")
179 parser.add_argument('--native-build-type', dest='nativeBuildType', default="Release", help="Build type passed cmake when building native code.")
180 parser.add_argument('--build-root', dest='buildRoot', default=common.ANDROID_DIR, help="Root directory for storing build results.")
182 args = parser.parse_args()
184 build(buildRoot=os.path.abspath(args.buildRoot), isRelease=args.isRelease, nativeBuildType=args.nativeBuildType)