Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 17 | # pylint: disable=not-callable, relative-import |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 18 | |
| 19 | import argparse |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 20 | import multiprocessing |
| 21 | import os |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 22 | import shutil |
| 23 | import subprocess |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 24 | |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 25 | import build |
| 26 | import compiler_wrapper |
| 27 | import utils |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 28 | |
Leo Li | 341ed3d | 2017-06-07 13:27:48 -0700 | [diff] [blame] | 29 | TARGETS = ('aosp_angler-eng', 'aosp_bullhead-eng', 'aosp_marlin-eng') |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 30 | DEFAULT_TIDY_CHECKS = ('*', '-readability-*', '-google-readability-*', |
| 31 | '-google-runtime-references', '-cppcoreguidelines-*', |
| 32 | '-modernize-*', '-clang-analyzer-alpha*') |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 33 | |
Pirama Arumuga Nainar | b84f655 | 2017-10-03 12:56:02 -0700 | [diff] [blame] | 34 | # We may introduce some new warnings after rebasing and we need to disable them |
| 35 | # before we fix those warnings. |
| 36 | DISABLED_WARNINGS = [ |
Yi Kong | 44eac34 | 2018-10-27 12:31:57 -0700 | [diff] [blame] | 37 | '-Wno-error=defaulted-function-deleted', |
Yi Kong | cc26921 | 2019-03-01 15:09:25 -0800 | [diff] [blame] | 38 | '-Wno-error=string-plus-int', |
| 39 | '-fsplit-lto-unit', |
Pirama Arumuga Nainar | b84f655 | 2017-10-03 12:56:02 -0700 | [diff] [blame] | 40 | ] |
| 41 | |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 42 | |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 43 | class ClangProfileHandler(object): |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 44 | |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 45 | def __init__(self): |
Pirama Arumuga Nainar | e6cafd8 | 2017-09-07 13:30:55 -0700 | [diff] [blame] | 46 | self.profiles_dir = utils.out_path('clang-profiles') |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 47 | self.profiles_format = os.path.join(self.profiles_dir, '%4m.profraw') |
| 48 | |
| 49 | def getProfileFileEnvVar(self): |
| 50 | return ('LLVM_PROFILE_FILE', self.profiles_format) |
| 51 | |
| 52 | def mergeProfiles(self): |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 53 | stage1_install = utils.out_path('stage1-install') |
| 54 | profdata = os.path.join(stage1_install, 'bin', 'llvm-profdata') |
| 55 | |
Pirama Arumuga Nainar | 41981bc | 2019-01-10 18:31:19 -0800 | [diff] [blame] | 56 | profdata_file = build.pgo_profdata_filename() |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 57 | |
Pirama Arumuga Nainar | e6cafd8 | 2017-09-07 13:30:55 -0700 | [diff] [blame] | 58 | dist_dir = os.environ.get('DIST_DIR', utils.out_path()) |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 59 | out_file = os.path.join(dist_dir, profdata_file) |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 60 | |
| 61 | cmd = [profdata, 'merge', '-o', out_file, self.profiles_dir] |
| 62 | subprocess.check_call(cmd) |
| 63 | |
| 64 | |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 65 | def parse_args(): |
| 66 | parser = argparse.ArgumentParser() |
| 67 | parser.add_argument('android_path', help='Android source directory.') |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 68 | parser.add_argument( |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 69 | '--clang-path', |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 70 | nargs='?', |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 71 | help='Directory with a previously built Clang.') |
| 72 | parser.add_argument( |
| 73 | '--clang-package-path', |
| 74 | nargs='?', |
| 75 | help='Directory of a pre-packaged (.tar.bz2) Clang. ' |
| 76 | 'Toolchain extracted from the package will be used.') |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 77 | parser.add_argument( |
| 78 | '-k', |
| 79 | '--keep-going', |
| 80 | action='store_true', |
| 81 | default=False, |
| 82 | help='Keep going when some targets ' |
| 83 | 'cannot be built.') |
| 84 | parser.add_argument( |
| 85 | '-j', |
| 86 | action='store', |
| 87 | dest='jobs', |
| 88 | type=int, |
| 89 | default=multiprocessing.cpu_count(), |
| 90 | help='Number of executed jobs.') |
| 91 | parser.add_argument( |
| 92 | '--build-only', |
| 93 | action='store_true', |
| 94 | default=False, |
| 95 | help='Build default targets only.') |
| 96 | parser.add_argument( |
| 97 | '--flashall-path', |
| 98 | nargs='?', |
| 99 | help='Use internal ' |
| 100 | 'flashall tool if the path is set.') |
| 101 | parser.add_argument( |
| 102 | '-t', |
| 103 | '--target', |
| 104 | nargs='?', |
| 105 | help='Build for specified ' |
| 106 | 'target. This will work only when --build-only is ' |
| 107 | 'enabled.') |
| 108 | parser.add_argument( |
| 109 | '--with-tidy', |
| 110 | action='store_true', |
| 111 | default=False, |
| 112 | help='Enable clang tidy for Android build.') |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 113 | clean_built_target_group = parser.add_mutually_exclusive_group() |
| 114 | clean_built_target_group.add_argument( |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 115 | '--clean-built-target', |
| 116 | action='store_true', |
| 117 | default=True, |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 118 | help='Clean output for each target that is built.') |
| 119 | clean_built_target_group.add_argument( |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 120 | '--no-clean-built-target', |
| 121 | action='store_false', |
| 122 | dest='clean_built_target', |
| 123 | help='Do not remove target output.') |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 124 | redirect_stderr_group = parser.add_mutually_exclusive_group() |
| 125 | redirect_stderr_group.add_argument( |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 126 | '--redirect-stderr', |
| 127 | action='store_true', |
| 128 | default=True, |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 129 | help='Redirect clang stderr to $OUT/clang-error.log.') |
Leo Li | aed6bea | 2017-06-23 16:04:00 -0700 | [diff] [blame] | 130 | redirect_stderr_group.add_argument( |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 131 | '--no-redirect-stderr', |
| 132 | action='store_false', |
| 133 | dest='redirect_stderr', |
| 134 | help='Do not redirect clang stderr.') |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 135 | |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 136 | parser.add_argument( |
| 137 | '--generate-clang-profile', |
| 138 | action='store_true', |
| 139 | default=False, |
| 140 | dest='profile', |
| 141 | help='Build instrumented compiler and gather profiles') |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 142 | |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 143 | parser.add_argument( |
| 144 | '--no-pgo', |
| 145 | action='store_true', |
| 146 | default=False, |
| 147 | help='Do not use PGO profile to build stage2 Clang (defaults to False)') |
| 148 | |
Pirama Arumuga Nainar | 86364b1 | 2017-09-13 10:42:21 -0700 | [diff] [blame] | 149 | args = parser.parse_args() |
| 150 | if args.profile and not args.no_pgo: |
| 151 | parser.error( |
| 152 | '--no-pgo must be specified along with --generate-clang-profile') |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 153 | if args.clang_path and args.clang_package_path: |
| 154 | parser.error('Only one of --clang-path and --clang-package-path must' |
| 155 | 'be specified') |
Pirama Arumuga Nainar | 86364b1 | 2017-09-13 10:42:21 -0700 | [diff] [blame] | 156 | |
| 157 | return args |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 158 | |
| 159 | |
| 160 | def link_clang(android_base, clang_path): |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 161 | android_clang_path = os.path.join(android_base, 'prebuilts', |
| 162 | 'clang', 'host', |
| 163 | utils.build_os_type(), 'clang-dev') |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 164 | utils.remove(android_clang_path) |
| 165 | os.symlink(os.path.abspath(clang_path), android_clang_path) |
| 166 | |
| 167 | |
| 168 | def get_connected_device_list(): |
| 169 | try: |
| 170 | # Get current connected device list. |
Haibo Huang | 797fc54 | 2019-08-07 18:04:24 -0700 | [diff] [blame] | 171 | out = subprocess.check_output(['adb', 'devices', '-l'], universal_newlines=True) |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 172 | devices = [x.split() for x in out.strip().split('\n')[1:]] |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 173 | return devices |
| 174 | except subprocess.CalledProcessError: |
| 175 | # If adb is not working properly. Return empty list. |
| 176 | return [] |
| 177 | |
| 178 | |
| 179 | def rm_current_product_out(): |
| 180 | if 'ANDROID_PRODUCT_OUT' in os.environ: |
| 181 | utils.remove(os.environ['ANDROID_PRODUCT_OUT']) |
| 182 | |
| 183 | |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 184 | def build_target(android_base, clang_version, target, max_jobs, redirect_stderr, |
Yi Kong | cffd482 | 2018-09-10 14:43:32 -0700 | [diff] [blame] | 185 | with_tidy, profiler=None): |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 186 | jobs = '-j{}'.format(max(1, min(max_jobs, multiprocessing.cpu_count()))) |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 187 | env_out = subprocess.Popen( |
| 188 | [ |
| 189 | 'bash', '-c', '. ./build/envsetup.sh;' |
| 190 | 'lunch ' + target + ' >/dev/null && env' |
| 191 | ], |
| 192 | cwd=android_base, |
| 193 | stdout=subprocess.PIPE) |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 194 | env = {} |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 195 | for line in env_out.stdout: |
| 196 | (key, _, value) = line.partition('=') |
| 197 | value = value.strip() |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 198 | env[key] = value |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 199 | env_out.communicate() |
| 200 | |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 201 | if redirect_stderr: |
| 202 | redirect_key = compiler_wrapper.STDERR_REDIRECT_KEY |
Leo Li | aed6bea | 2017-06-23 16:04:00 -0700 | [diff] [blame] | 203 | if 'DIST_DIR' in env: |
| 204 | redirect_path = os.path.join(env['DIST_DIR'], 'logs', |
| 205 | 'clang-error.log') |
| 206 | else: |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 207 | redirect_path = os.path.abspath( |
| 208 | os.path.join(android_base, 'out', 'clang-error.log')) |
Leo Li | aed6bea | 2017-06-23 16:04:00 -0700 | [diff] [blame] | 209 | utils.remove(redirect_path) |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 210 | env[redirect_key] = redirect_path |
Leo Li | 686fce8 | 2017-07-07 11:18:38 -0700 | [diff] [blame] | 211 | fallback_path = build.clang_prebuilt_bin_dir() |
| 212 | env[compiler_wrapper.PREBUILT_COMPILER_PATH_KEY] = fallback_path |
Pirama Arumuga Nainar | b84f655 | 2017-10-03 12:56:02 -0700 | [diff] [blame] | 213 | env[compiler_wrapper.DISABLED_WARNINGS_KEY] = ' '.join( |
| 214 | DISABLED_WARNINGS) |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 215 | |
Leo Li | dd7832a | 2017-06-23 16:41:56 -0700 | [diff] [blame] | 216 | env['LLVM_PREBUILTS_VERSION'] = 'clang-dev' |
Pirama Arumuga Nainar | 08a4104 | 2017-09-20 16:09:00 -0700 | [diff] [blame] | 217 | env['LLVM_RELEASE_VERSION'] = clang_version.long_version() |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 218 | |
Leo Li | dd7832a | 2017-06-23 16:41:56 -0700 | [diff] [blame] | 219 | if with_tidy: |
| 220 | env['WITH_TIDY'] = '1' |
| 221 | if 'DEFAULT_GLOBAL_TIDY_CHECKS' not in env: |
| 222 | env['DEFAULT_GLOBAL_TIDY_CHECKS'] = ','.join(DEFAULT_TIDY_CHECKS) |
| 223 | |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 224 | modules = ['dist'] |
| 225 | if profiler is not None: |
| 226 | # Build only a subset of targets and collect profiles |
Pirama Arumuga Nainar | dbb9362 | 2017-11-09 21:43:51 -0800 | [diff] [blame] | 227 | modules = ['libc', 'libLLVM_android-host64'] |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 228 | |
| 229 | key, val = profiler.getProfileFileEnvVar() |
| 230 | env[key] = val |
| 231 | |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 232 | modulesList = ' '.join(modules) |
| 233 | print 'Start building target %s and modules %s.' % (target, modulesList) |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 234 | subprocess.check_call( |
Pirama Arumuga Nainar | 538a144 | 2019-07-30 16:56:06 -0700 | [diff] [blame] | 235 | ['/bin/bash', '-c', 'build/soong/soong_ui.bash --make-mode ' + jobs + \ |
| 236 | ' ' + modulesList], |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 237 | cwd=android_base, |
| 238 | env=env) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 239 | |
| 240 | |
| 241 | def test_device(android_base, clang_version, device, max_jobs, clean_output, |
Leo Li | dd7832a | 2017-06-23 16:41:56 -0700 | [diff] [blame] | 242 | flashall_path, redirect_stderr, with_tidy): |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 243 | [label, target] = device[-1].split(':') |
| 244 | # If current device is not connected correctly we will just skip it. |
| 245 | if label != 'device': |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 246 | print 'Device %s is not connecting correctly.' % device[0] |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 247 | return True |
| 248 | else: |
| 249 | target = 'aosp_' + target + '-eng' |
| 250 | try: |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 251 | build_target(android_base, clang_version, target, max_jobs, |
Leo Li | dd7832a | 2017-06-23 16:41:56 -0700 | [diff] [blame] | 252 | redirect_stderr, with_tidy) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 253 | if flashall_path is None: |
Leo Li | 5ce70ae | 2017-06-13 12:42:12 -0700 | [diff] [blame] | 254 | bin_path = os.path.join(android_base, 'out', 'host', |
| 255 | utils.build_os_type(), 'bin') |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 256 | subprocess.check_call( |
| 257 | ['./adb', '-s', device[0], 'reboot', 'bootloader'], |
| 258 | cwd=bin_path) |
| 259 | subprocess.check_call( |
| 260 | ['./fastboot', '-s', device[0], 'flashall'], cwd=bin_path) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 261 | else: |
| 262 | os.environ['ANDROID_SERIAL'] = device[0] |
| 263 | subprocess.check_call(['./flashall'], cwd=flashall_path) |
| 264 | result = True |
| 265 | except subprocess.CalledProcessError: |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 266 | print 'Flashing/testing android for target %s failed!' % target |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 267 | result = False |
| 268 | if clean_output: |
| 269 | rm_current_product_out() |
| 270 | return result |
| 271 | |
| 272 | |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 273 | def build_clang(instrumented=False, pgo=True): |
Pirama Arumuga Nainar | e6cafd8 | 2017-09-07 13:30:55 -0700 | [diff] [blame] | 274 | stage1_install = utils.out_path('stage1-install') |
| 275 | stage2_install = utils.out_path('stage2-install') |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 276 | |
| 277 | # LLVM tool llvm-profdata from stage1 is needed to merge the collected |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 278 | # profiles. Build all LLVM tools if building instrumented stage2 |
Stephen Hines | 2a9a040 | 2018-01-31 21:03:39 -0800 | [diff] [blame] | 279 | build.build_stage1(stage1_install, build_name='dev', |
| 280 | build_llvm_tools=instrumented) |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 281 | |
| 282 | profdata = None |
| 283 | if pgo: |
| 284 | long_version = build.extract_clang_long_version(stage1_install) |
| 285 | profdata = build.pgo_profdata_file(long_version) |
| 286 | |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 287 | build.build_stage2( |
| 288 | stage1_install, |
| 289 | stage2_install, |
| 290 | build.STAGE2_TARGETS, |
Stephen Hines | 2a9a040 | 2018-01-31 21:03:39 -0800 | [diff] [blame] | 291 | build_name='dev', |
Pirama Arumuga Nainar | 641bc4b | 2017-09-07 16:48:34 -0700 | [diff] [blame] | 292 | build_instrumented=instrumented, |
| 293 | profdata_file=profdata) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 294 | build.build_runtimes(stage2_install) |
Pirama Arumuga Nainar | 6295570 | 2019-08-27 15:40:51 -0700 | [diff] [blame] | 295 | |
| 296 | build.package_toolchain( |
| 297 | stage2_install, |
| 298 | 'dev', |
| 299 | utils.build_os_type(), |
| 300 | dist_dir=None, |
| 301 | strip=True, |
| 302 | create_tar=False) |
| 303 | |
| 304 | clang_path = build.get_package_install_path(utils.build_os_type(), 'clang-dev') |
| 305 | version = build.extract_clang_version(clang_path) |
| 306 | return clang_path, version |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 307 | |
| 308 | |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 309 | def extract_packaged_clang(package_path): |
| 310 | # Find package to extract |
| 311 | tarballs = [f for f in os.listdir(package_path) if \ |
Pirama Arumuga Nainar | de37f72 | 2018-09-17 15:10:35 -0700 | [diff] [blame] | 312 | f.endswith('.tar.bz2') and 'linux' in f] |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 313 | if len(tarballs) != 1: |
| 314 | raise RuntimeError( |
| 315 | 'No clang packages (.tar.bz2) found in ' + package_path) |
| 316 | |
| 317 | tarball = os.path.join(package_path, tarballs[0]) |
| 318 | |
| 319 | # Extract package to $OUT_DIR/extracted |
| 320 | extract_dir = utils.out_path('extracted') |
| 321 | if os.path.exists(extract_dir): |
| 322 | utils.rm_tree(extract_dir) |
| 323 | build.check_create_path(extract_dir) |
| 324 | |
| 325 | args = ['tar', '-xjC', extract_dir, '-f', tarball] |
| 326 | subprocess.check_call(args) |
| 327 | |
| 328 | # Find and return a singleton subdir |
| 329 | extracted = os.listdir(extract_dir) |
| 330 | if len(extracted) != 1: |
| 331 | raise RuntimeError( |
| 332 | 'Expected one file from package. Found: ' + ' '.join(extracted)) |
| 333 | |
| 334 | clang_path = os.path.join(extract_dir, extracted[0]) |
| 335 | if not os.path.isdir(clang_path): |
| 336 | raise RuntimeError('Extracted path is not a dir: ' + clang_path) |
| 337 | |
| 338 | return clang_path |
| 339 | |
| 340 | |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 341 | def main(): |
| 342 | args = parse_args() |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 343 | if args.clang_path is not None: |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 344 | clang_path = args.clang_path |
| 345 | clang_version = build.extract_clang_version(clang_path) |
Pirama Arumuga Nainar | a4f171d | 2018-09-10 11:12:37 -0700 | [diff] [blame] | 346 | elif args.clang_package_path is not None: |
| 347 | clang_path = extract_packaged_clang(args.clang_package_path) |
| 348 | clang_version = build.extract_clang_version(clang_path) |
| 349 | else: |
| 350 | clang_path, clang_version = build_clang( |
| 351 | instrumented=args.profile, pgo=(not args.no_pgo)) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 352 | link_clang(args.android_path, clang_path) |
| 353 | |
Leo Li | 062ce69 | 2017-06-15 10:36:36 -0700 | [diff] [blame] | 354 | if args.build_only: |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 355 | profiler = ClangProfileHandler() if args.profile else None |
| 356 | |
Leo Li | 341ed3d | 2017-06-07 13:27:48 -0700 | [diff] [blame] | 357 | targets = [args.target] if args.target else TARGETS |
| 358 | for target in targets: |
Pirama Arumuga Nainar | 56cbbec | 2017-09-06 22:56:12 -0700 | [diff] [blame] | 359 | build_target(args.android_path, clang_version, target, args.jobs, |
| 360 | args.redirect_stderr, args.with_tidy, profiler) |
Pirama Arumuga Nainar | ab32021 | 2017-09-06 12:25:37 -0700 | [diff] [blame] | 361 | |
| 362 | if profiler is not None: |
| 363 | profiler.mergeProfiles() |
| 364 | |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 365 | else: |
Leo Li | 062ce69 | 2017-06-15 10:36:36 -0700 | [diff] [blame] | 366 | devices = get_connected_device_list() |
| 367 | if len(devices) == 0: |
Yi Kong | e973e24 | 2018-09-10 13:44:28 -0700 | [diff] [blame] | 368 | print "You don't have any devices connected." |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 369 | for device in devices: |
| 370 | result = test_device(args.android_path, clang_version, device, |
| 371 | args.jobs, args.clean_built_target, |
Leo Li | dd7832a | 2017-06-23 16:41:56 -0700 | [diff] [blame] | 372 | args.flashall_path, args.redirect_stderr, |
| 373 | args.with_tidy) |
Leo Li | 5f369e9 | 2017-05-30 12:02:02 -0700 | [diff] [blame] | 374 | if not result and not args.keep_going: |
| 375 | break |
| 376 | |
| 377 | |
| 378 | if __name__ == '__main__': |
| 379 | main() |