OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 """Builds and packages instrumented libraries for dynamic tools.""" |
| 6 |
| 7 import argparse |
| 8 import contextlib |
| 9 import os |
| 10 import shutil |
| 11 import subprocess |
| 12 import tarfile |
| 13 |
| 14 BUILD_TYPES = { |
| 15 'msan-no-origins': [ |
| 16 'is_msan = true', |
| 17 'msan_track_origins = 0', |
| 18 ], |
| 19 'msan-chained-origins': [ |
| 20 'is_msan = true', |
| 21 'msan_track_origins = 2', |
| 22 ], |
| 23 'tsan': ['is_tsan = true'], |
| 24 'asan': ['is_asan = true'] |
| 25 } |
| 26 SUPPORTED_RELEASES = frozenset(['trusty']) |
| 27 |
| 28 |
| 29 class Error(Exception): |
| 30 pass |
| 31 |
| 32 |
| 33 class UnsupportedReleaseError(Error): |
| 34 pass |
| 35 |
| 36 |
| 37 def _get_release(): |
| 38 return subprocess.check_output(['lsb_release', '-cs']).strip() |
| 39 |
| 40 |
| 41 def _tar_filter(tar_info): |
| 42 if tar_info.name.endswith('.txt'): |
| 43 return None |
| 44 return tar_info |
| 45 |
| 46 |
| 47 def build_libraries(build_type, ubuntu_release, jobs, use_goma): |
| 48 archive_name = '%s-%s' % (build_type, ubuntu_release) |
| 49 build_dir = 'out/Instrumented-%s' % archive_name |
| 50 if not os.path.exists(build_dir): |
| 51 os.makedirs(build_dir) |
| 52 |
| 53 gn_args = [ |
| 54 'is_debug = false', |
| 55 'use_goma = %s' % str(use_goma).lower(), |
| 56 'instrumented_libraries_jobs = %d' % jobs, |
| 57 'use_locally_built_instrumented_libraries = true', |
| 58 ] + BUILD_TYPES[build_type] |
| 59 with open(os.path.join(build_dir, 'args.gn'), 'w') as f: |
| 60 f.write('\n'.join(gn_args)) |
| 61 subprocess.check_call(['gn', 'gen', build_dir, '--check']) |
| 62 subprocess.check_call(['ninja', '-j2', '-C', build_dir, |
| 63 'third_party/instrumented_libraries:locally_built']) |
| 64 with tarfile.open('%s.tgz' % archive_name, mode='w:gz') as f: |
| 65 prefix = build_type.split('-', 1)[0] |
| 66 f.add('%s/instrumented_libraries/%s' % (build_dir, prefix), |
| 67 arcname=prefix, |
| 68 filter=_tar_filter) |
| 69 f.add('%s/instrumented_libraries/sources' % build_dir, |
| 70 arcname='sources', |
| 71 filter=_tar_filter) |
| 72 return archive_name |
| 73 |
| 74 |
| 75 def main(): |
| 76 parser = argparse.ArgumentParser( |
| 77 description=__doc__, |
| 78 formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 79 parser.add_argument( |
| 80 '--jobs', |
| 81 '-j', |
| 82 type=int, |
| 83 default=8, |
| 84 help='the default number of jobs to use when running make') |
| 85 parser.add_argument('--use_goma', |
| 86 action='store_true', |
| 87 default=False, |
| 88 help='whether to use goma to compile') |
| 89 parser.add_argument('build_type', |
| 90 nargs='*', |
| 91 default='all', |
| 92 choices=BUILD_TYPES.keys() + ['all'], |
| 93 help='the type of instrumented library to build') |
| 94 args = parser.parse_args() |
| 95 if args.build_type == 'all' or 'all' in args.build_type: |
| 96 args.build_type = BUILD_TYPES.keys() |
| 97 |
| 98 ubuntu_release = _get_release() |
| 99 if ubuntu_release not in SUPPORTED_RELEASES: |
| 100 raise UnsupportedReleaseError('%s is not a supported release' % |
| 101 _get_release()) |
| 102 archive_names = [ |
| 103 build_libraries(build_type, ubuntu_release, args.jobs, args.use_goma) |
| 104 for build_type in sorted(set(args.build_type)) |
| 105 ] |
| 106 print 'To upload, run:' |
| 107 for archive_name in archive_names: |
| 108 print('upload_to_google_storage.py -b ' |
| 109 'chromium-instrumented-libraries %s.tgz') % archive_name |
| 110 print 'You should then commit the resulting .sha1 files.' |
| 111 |
| 112 |
| 113 if __name__ == '__main__': |
| 114 main() |
OLD | NEW |