Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Jarkko Pöyry | 3c77ed4 | 2015-01-06 12:54:34 -0800 | [diff] [blame] | 3 | #------------------------------------------------------------------------- |
| 4 | # drawElements Quality Program utilities |
| 5 | # -------------------------------------- |
| 6 | # |
| 7 | # Copyright 2015 The Android Open Source Project |
| 8 | # |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | # you may not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | # |
| 21 | #------------------------------------------------------------------------- |
| 22 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 23 | import os |
| 24 | import re |
| 25 | import sys |
| 26 | import shutil |
| 27 | import argparse |
| 28 | |
| 29 | import common |
| 30 | |
| 31 | def getStoreKeyPasswords (filename): |
| 32 | f = open(filename) |
| 33 | storepass = None |
| 34 | keypass = None |
| 35 | for line in f: |
| 36 | m = re.search('([a-z]+)\s*\=\s*"([^"]+)"', line) |
| 37 | if m != None: |
| 38 | if m.group(1) == "storepass": |
| 39 | storepass = m.group(2) |
| 40 | elif m.group(1) == "keypass": |
| 41 | keypass = m.group(2) |
| 42 | f.close() |
| 43 | if storepass == None or keypass == None: |
| 44 | common.die("Could not read signing key passwords") |
| 45 | return (storepass, keypass) |
| 46 | |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 47 | def getNativeBuildDir (buildRoot, nativeLib, buildType): |
| 48 | buildName = "%s-%d-%s" % (buildType.lower(), nativeLib.apiVersion, nativeLib.abiVersion) |
| 49 | return os.path.normpath(os.path.join(buildRoot, "native", buildName)) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 50 | |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 51 | def getAssetsDir (buildRoot, nativeLib, buildType): |
| 52 | return os.path.join(getNativeBuildDir(buildRoot, nativeLib, buildType), "assets") |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 53 | |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 54 | def buildNative (buildRoot, libTargetDir, nativeLib, buildType): |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 55 | deqpDir = os.path.normpath(os.path.join(common.ANDROID_DIR, "..")) |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 56 | buildDir = getNativeBuildDir(buildRoot, nativeLib, buildType) |
| 57 | libsDir = os.path.join(libTargetDir, nativeLib.abiVersion) |
Pyry Haulos | 03700a8 | 2014-10-20 13:01:20 -0700 | [diff] [blame] | 58 | srcLibFile = os.path.join(buildDir, common.NATIVE_LIB_NAME) |
| 59 | dstLibFile = os.path.join(libsDir, common.NATIVE_LIB_NAME) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 60 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 61 | # Make build directory if necessary |
| 62 | if not os.path.exists(buildDir): |
| 63 | os.makedirs(buildDir) |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 64 | toolchainFile = '%s/framework/delibs/cmake/toolchain-android-%s.cmake' % (deqpDir, common.ANDROID_NDK_TOOLCHAIN_VERSION) |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 65 | common.execArgsInDirectory([ |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 66 | 'cmake', |
| 67 | '-G%s' % common.CMAKE_GENERATOR, |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 68 | '-DCMAKE_TOOLCHAIN_FILE=%s' % toolchainFile, |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 69 | '-DANDROID_NDK_HOST_OS=%s' % common.ANDROID_NDK_HOST_OS, |
| 70 | '-DANDROID_NDK_PATH=%s' % common.ANDROID_NDK_PATH, |
| 71 | '-DANDROID_ABI=%s' % nativeLib.abiVersion, |
| 72 | '-DDE_ANDROID_API=%s' % nativeLib.apiVersion, |
| 73 | '-DCMAKE_BUILD_TYPE=%s' % buildType, |
| 74 | '-DDEQP_TARGET=android', |
| 75 | deqpDir |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 76 | ], buildDir) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 77 | |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 78 | common.execArgsInDirectory(['cmake', '--build', '.'] + common.EXTRA_BUILD_ARGS, buildDir) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 79 | |
| 80 | if not os.path.exists(libsDir): |
| 81 | os.makedirs(libsDir) |
| 82 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 83 | shutil.copyfile(srcLibFile, dstLibFile) |
| 84 | |
| 85 | # Copy gdbserver for debugging |
| 86 | if buildType.lower() == "debug": |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 87 | srcGdbserverPath = os.path.join(common.ANDROID_NDK_PATH, |
| 88 | 'prebuilt', |
Jarkko Pöyry | b6d3233 | 2015-03-09 16:38:57 -0700 | [diff] [blame] | 89 | nativeLib.prebuiltDir, |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 90 | 'gdbserver', |
| 91 | 'gdbserver') |
| 92 | dstGdbserverPath = os.path.join(libsDir, 'gdbserver') |
Pyry Haulos | 03700a8 | 2014-10-20 13:01:20 -0700 | [diff] [blame] | 93 | shutil.copyfile(srcGdbserverPath, dstGdbserverPath) |
| 94 | else: |
| 95 | assert not os.path.exists(os.path.join(libsDir, "gdbserver")) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 96 | |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 97 | def buildApp (buildRoot, androidBuildType, javaApi): |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 98 | appDir = os.path.join(buildRoot, "package") |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 99 | |
| 100 | # Set up app |
| 101 | os.chdir(appDir) |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 102 | |
| 103 | manifestSrcPath = os.path.normpath(os.path.join(common.ANDROID_DIR, "package", "AndroidManifest.xml")) |
| 104 | manifestDstPath = os.path.normpath(os.path.join(appDir, "AndroidManifest.xml")) |
| 105 | |
| 106 | # Build dir can be the Android dir, in which case the copy is not needed. |
| 107 | if manifestSrcPath != manifestDstPath: |
| 108 | shutil.copy(manifestSrcPath, manifestDstPath) |
| 109 | |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 110 | common.execArgs([ |
| 111 | common.ANDROID_BIN, |
| 112 | 'update', 'project', |
| 113 | '--name', 'dEQP', |
| 114 | '--path', '.', |
Kalle Raita | 97e3589 | 2014-11-21 16:58:07 -0800 | [diff] [blame] | 115 | '--target', javaApi, |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 116 | ]) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 117 | |
| 118 | # Build |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 119 | common.execArgs([ |
| 120 | common.ANT_BIN, |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 121 | androidBuildType, |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 122 | "-Dsource.dir=" + os.path.join(common.ANDROID_DIR, "package", "src"), |
| 123 | "-Dresource.absolute.dir=" + os.path.join(common.ANDROID_DIR, "package", "res") |
| 124 | ]) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 125 | |
| 126 | def signApp (keystore, keyname, storepass, keypass): |
| 127 | os.chdir(os.path.join(common.ANDROID_DIR, "package")) |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 128 | common.execArgs([ |
| 129 | common.JARSIGNER_BIN, |
| 130 | '-keystore', keystore, |
| 131 | '-storepass', storepass, |
| 132 | '-keypass', keypass, |
| 133 | '-sigfile', 'CERT', |
| 134 | '-digestalg', 'SHA1', |
| 135 | '-sigalg', 'MD5withRSA', |
| 136 | '-signedjar', 'bin/dEQP-unaligned.apk', |
| 137 | 'bin/dEQP-release-unsigned.apk', |
| 138 | keyname |
| 139 | ]) |
| 140 | common.execArgs([ |
| 141 | common.ZIPALIGN_BIN, |
| 142 | '-f', '4', |
| 143 | 'bin/dEQP-unaligned.apk', |
| 144 | 'bin/dEQP-release.apk' |
| 145 | ]) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 146 | |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 147 | def build (buildRoot=common.ANDROID_DIR, androidBuildType='debug', nativeBuildType="Release", javaApi=common.ANDROID_JAVA_API, doParallelBuild=False): |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 148 | curDir = os.getcwd() |
| 149 | |
| 150 | try: |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 151 | assetsSrcDir = getAssetsDir(buildRoot, common.NATIVE_LIBS[0], nativeBuildType) |
| 152 | assetsDstDir = os.path.join(buildRoot, "package", "assets") |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 153 | |
| 154 | # Remove assets from the first build dir where we copy assets from |
| 155 | # to avoid collecting cruft there. |
| 156 | if os.path.exists(assetsSrcDir): |
| 157 | shutil.rmtree(assetsSrcDir) |
| 158 | if os.path.exists(assetsDstDir): |
| 159 | shutil.rmtree(assetsDstDir) |
| 160 | |
| 161 | # Remove old libs dir to avoid collecting out-of-date versions |
| 162 | # of libs for ABIs not built this time. |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 163 | libTargetDir = os.path.join(buildRoot, "package", "libs") |
| 164 | if os.path.exists(libTargetDir): |
| 165 | shutil.rmtree(libTargetDir) |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 166 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 167 | # Build native code |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 168 | nativeBuildArgs = [(buildRoot, libTargetDir, nativeLib, nativeBuildType) for nativeLib in common.NATIVE_LIBS] |
| 169 | if doParallelBuild: |
| 170 | common.parallelApply(buildNative, nativeBuildArgs) |
| 171 | else: |
| 172 | common.serialApply(buildNative, nativeBuildArgs) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 173 | |
Pyry Haulos | 89e0405 | 2014-10-20 11:09:56 -0700 | [diff] [blame] | 174 | # Copy assets |
| 175 | if os.path.exists(assetsSrcDir): |
| 176 | shutil.copytree(assetsSrcDir, assetsDstDir) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 177 | |
| 178 | # Build java code and .apk |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 179 | buildApp(buildRoot, androidBuildType, javaApi) |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 180 | |
| 181 | finally: |
| 182 | # Restore working dir |
| 183 | os.chdir(curDir) |
| 184 | |
Kalle Raita | c9f7674 | 2014-11-13 13:00:08 -0800 | [diff] [blame] | 185 | def dumpConfig (): |
| 186 | print " " |
| 187 | for entry in common.CONFIG_STRINGS: |
| 188 | print "%-30s : %s" % (entry[0], entry[1]) |
| 189 | print " " |
| 190 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 191 | if __name__ == "__main__": |
Mika Isojärvi | 89b6a4a | 2015-03-17 14:39:57 -0700 | [diff] [blame] | 192 | nativeBuildTypes = ['Release', 'Debug', 'MinSizeRel', 'RelWithAsserts', 'RelWithDebInfo'] |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 193 | androidBuildTypes = ['debug', 'release'] |
Mika Isojärvi | 89b6a4a | 2015-03-17 14:39:57 -0700 | [diff] [blame] | 194 | |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 195 | parser = argparse.ArgumentParser() |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 196 | parser.add_argument('--android-build-type', dest='androidBuildType', choices=androidBuildTypes, default='debug', help="Build type for android project..") |
| 197 | parser.add_argument('--native-build-type', dest='nativeBuildType', default="RelWithAsserts", choices=nativeBuildTypes, help="Build type passed to cmake when building native code.") |
Kalle Raita | 829f589 | 2014-10-24 11:16:03 -0700 | [diff] [blame] | 198 | parser.add_argument('--build-root', dest='buildRoot', default=common.ANDROID_DIR, help="Root directory for storing build results.") |
Kalle Raita | c9f7674 | 2014-11-13 13:00:08 -0800 | [diff] [blame] | 199 | parser.add_argument('--dump-config', dest='dumpConfig', action='store_true', help="Print out all configurations variables") |
Kalle Raita | 97e3589 | 2014-11-21 16:58:07 -0800 | [diff] [blame] | 200 | parser.add_argument('--java-api', dest='javaApi', default=common.ANDROID_JAVA_API, help="Set the API signature for the java build.") |
Jarkko Pöyry | 842a87c | 2014-12-11 18:22:05 -0800 | [diff] [blame] | 201 | parser.add_argument('-p', '--parallel-build', dest='parallelBuild', action="store_true", help="Build native libraries in parallel.") |
Jarkko Poyry | 3c82736 | 2014-09-02 11:48:52 +0300 | [diff] [blame] | 202 | |
| 203 | args = parser.parse_args() |
| 204 | |
Kalle Raita | c9f7674 | 2014-11-13 13:00:08 -0800 | [diff] [blame] | 205 | if args.dumpConfig: |
| 206 | dumpConfig() |
| 207 | |
Mika Isojärvi | 1357009 | 2015-03-18 15:53:05 -0700 | [diff] [blame] | 208 | build(buildRoot=os.path.abspath(args.buildRoot), androidBuildType=args.androidBuildType, nativeBuildType=args.nativeBuildType, javaApi=args.javaApi, doParallelBuild=args.parallelBuild) |