OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Builds and packages instrumented libraries for dynamic tools.""" | 5 """Builds and packages instrumented libraries for dynamic tools.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import contextlib | 8 import contextlib |
| 9 import multiprocessing |
9 import os | 10 import os |
10 import shutil | 11 import shutil |
11 import subprocess | 12 import subprocess |
12 import tarfile | 13 import tarfile |
13 | 14 |
14 BUILD_TYPES = { | 15 BUILD_TYPES = { |
15 'msan-no-origins': [ | 16 'msan-no-origins': [ |
16 'is_msan = true', | 17 'is_msan = true', |
17 'msan_track_origins = 0', | 18 'msan_track_origins = 0', |
18 ], | 19 ], |
(...skipping 27 matching lines...) Expand all Loading... |
46 | 47 |
47 def build_libraries(build_type, ubuntu_release, jobs, use_goma): | 48 def build_libraries(build_type, ubuntu_release, jobs, use_goma): |
48 archive_name = '%s-%s' % (build_type, ubuntu_release) | 49 archive_name = '%s-%s' % (build_type, ubuntu_release) |
49 build_dir = 'out/Instrumented-%s' % archive_name | 50 build_dir = 'out/Instrumented-%s' % archive_name |
50 if not os.path.exists(build_dir): | 51 if not os.path.exists(build_dir): |
51 os.makedirs(build_dir) | 52 os.makedirs(build_dir) |
52 | 53 |
53 gn_args = [ | 54 gn_args = [ |
54 'is_debug = false', | 55 'is_debug = false', |
55 'use_goma = %s' % str(use_goma).lower(), | 56 'use_goma = %s' % str(use_goma).lower(), |
56 'instrumented_libraries_jobs = %d' % jobs, | |
57 'use_locally_built_instrumented_libraries = true', | 57 'use_locally_built_instrumented_libraries = true', |
58 ] + BUILD_TYPES[build_type] | 58 ] + BUILD_TYPES[build_type] |
59 with open(os.path.join(build_dir, 'args.gn'), 'w') as f: | 59 with open(os.path.join(build_dir, 'args.gn'), 'w') as f: |
60 f.write('\n'.join(gn_args)) | 60 f.write('\n'.join(gn_args) + '\n') |
61 subprocess.check_call(['gn', 'gen', build_dir, '--check']) | 61 subprocess.check_call(['gn', 'gen', build_dir, '--check']) |
62 subprocess.check_call(['ninja', '-j2', '-C', build_dir, | 62 subprocess.check_call(['ninja', '-j%d' % jobs, '-C', build_dir, |
63 'third_party/instrumented_libraries:locally_built']) | 63 'third_party/instrumented_libraries:locally_built']) |
64 with tarfile.open('%s.tgz' % archive_name, mode='w:gz') as f: | 64 with tarfile.open('%s.tgz' % archive_name, mode='w:gz') as f: |
65 prefix = build_type.split('-', 1)[0] | 65 prefix = build_type.split('-', 1)[0] |
66 f.add('%s/instrumented_libraries/%s' % (build_dir, prefix), | 66 f.add('%s/instrumented_libraries/%s' % (build_dir, prefix), |
67 arcname=prefix, | 67 arcname=prefix, |
68 filter=_tar_filter) | 68 filter=_tar_filter) |
69 f.add('%s/instrumented_libraries/sources' % build_dir, | 69 f.add('%s/instrumented_libraries/sources' % build_dir, |
70 arcname='sources', | 70 arcname='sources', |
71 filter=_tar_filter) | 71 filter=_tar_filter) |
72 return archive_name | |
73 | 72 |
74 | 73 |
75 def main(): | 74 def main(): |
76 parser = argparse.ArgumentParser( | 75 parser = argparse.ArgumentParser( |
77 description=__doc__, | 76 description=__doc__, |
78 formatter_class=argparse.ArgumentDefaultsHelpFormatter) | 77 formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
79 parser.add_argument( | 78 parser.add_argument( |
80 '--jobs', | 79 '--jobs', |
81 '-j', | 80 '-j', |
82 type=int, | 81 type=int, |
83 default=8, | 82 default=8, |
84 help='the default number of jobs to use when running make') | 83 help='the default number of jobs to use when running ninja') |
| 84 parser.add_argument('--parallel', |
| 85 action='store_true', |
| 86 default=False, |
| 87 help='whether to run all instrumented builds in parallel') |
85 parser.add_argument('--use_goma', | 88 parser.add_argument('--use_goma', |
86 action='store_true', | 89 action='store_true', |
87 default=False, | 90 default=False, |
88 help='whether to use goma to compile') | 91 help='whether to use goma to compile') |
89 parser.add_argument('build_type', | 92 parser.add_argument('build_type', |
90 nargs='*', | 93 nargs='*', |
91 default='all', | 94 default='all', |
92 choices=BUILD_TYPES.keys() + ['all'], | 95 choices=BUILD_TYPES.keys() + ['all'], |
93 help='the type of instrumented library to build') | 96 help='the type of instrumented library to build') |
94 args = parser.parse_args() | 97 args = parser.parse_args() |
95 if args.build_type == 'all' or 'all' in args.build_type: | 98 if args.build_type == 'all' or 'all' in args.build_type: |
96 args.build_type = BUILD_TYPES.keys() | 99 args.build_type = BUILD_TYPES.keys() |
97 | 100 |
98 ubuntu_release = _get_release() | 101 ubuntu_release = _get_release() |
99 if ubuntu_release not in SUPPORTED_RELEASES: | 102 if ubuntu_release not in SUPPORTED_RELEASES: |
100 raise UnsupportedReleaseError('%s is not a supported release' % | 103 raise UnsupportedReleaseError('%s is not a supported release' % |
101 _get_release()) | 104 _get_release()) |
102 archive_names = [ | 105 build_types = sorted(set(args.build_type)) |
| 106 if args.parallel: |
| 107 procs = [] |
| 108 for build_type in build_types: |
| 109 proc = multiprocessing.Process(target=build_libraries, |
| 110 args=(build_type, ubuntu_release, |
| 111 args.jobs, args.use_goma)) |
| 112 proc.start() |
| 113 procs.append(proc) |
| 114 for proc in procs: |
| 115 proc.join() |
| 116 else: |
| 117 for build_type in build_types: |
103 build_libraries(build_type, ubuntu_release, args.jobs, args.use_goma) | 118 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:' | 119 print 'To upload, run:' |
107 for archive_name in archive_names: | 120 for build_type in build_types: |
108 print('upload_to_google_storage.py -b ' | 121 print('upload_to_google_storage.py -b ' |
109 'chromium-instrumented-libraries %s.tgz') % archive_name | 122 'chromium-instrumented-libraries %s-%s.tgz' % |
| 123 (build_type, ubuntu_release)) |
110 print 'You should then commit the resulting .sha1 files.' | 124 print 'You should then commit the resulting .sha1 files.' |
111 | 125 |
112 | 126 |
113 if __name__ == '__main__': | 127 if __name__ == '__main__': |
114 main() | 128 main() |
OLD | NEW |