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 = {'msan-no-origins': 0, 'msan-chained-origins': 2} | |
15 SUPPORTED_RELEASES = frozenset(['trusty']) | |
16 | |
17 | |
18 class Error(Exception): | |
19 pass | |
20 | |
21 | |
22 class UnsupportedReleaseError(Error): | |
23 pass | |
24 | |
25 | |
26 def _get_release(): | |
27 return subprocess.check_output(['lsb_release', '-cs']).strip() | |
28 | |
29 | |
30 def _tar_filter(tar_info): | |
31 if tar_info.name.endswith('.txt'): | |
32 return None | |
33 return tar_info | |
34 | |
35 | |
36 def build_libraries(build_type, ubuntu_release, jobs, use_goma): | |
37 archive_name = '%s-%s' % (build_type, ubuntu_release) | |
38 build_dir = 'out/Instrumented-%s' % archive_name | |
39 if not os.path.exists(build_dir): | |
40 os.makedirs(build_dir) | |
41 | |
42 gn_args = [ | |
43 'is_debug = false', | |
44 'is_msan = true', | |
aizatsky
2016/06/29 21:14:32
What about asan builds?
I suggest you store addit
Sam McNally
2016/06/30 04:17:06
Done.
| |
45 'use_goma = %s' % str(use_goma).lower(), | |
46 'instrumented_libraries_jobs = %d' % jobs, | |
47 'use_locally_built_instrumented_libraries = true', | |
48 'msan_track_origins = %d' % BUILD_TYPES[build_type], | |
aizatsky
2016/06/29 21:14:32
This arg should go into BUILD_TYPES map.
Sam McNally
2016/06/30 04:17:06
Done.
| |
49 'instrumented_libraries_platform = "%s"' % ubuntu_release, | |
50 ] | |
51 with open(os.path.join(build_dir, 'args.gn'), 'w') as f: | |
52 f.write('\n'.join(gn_args)) | |
53 subprocess.check_call(['gn', 'gen', build_dir]) | |
aizatsky
2016/06/29 21:14:32
add --check
Sam McNally
2016/06/30 04:17:06
Done.
| |
54 subprocess.check_call(['ninja', '-j2', '-C', build_dir, | |
55 'third_party/instrumented_libraries:locally_built']) | |
56 with tarfile.open('%s.tgz' % archive_name, mode='w:gz') as f: | |
57 f.add('%s/instrumented_libraries/msan' % build_dir, | |
58 arcname='msan', | |
59 filter=_tar_filter) | |
60 f.add('%s/instrumented_libraries/sources' % build_dir, | |
61 arcname='sources', | |
62 filter=_tar_filter) | |
63 print 'To upload, run:' | |
aizatsky
2016/06/29 21:14:32
This will be printed out in between runs and will
Sam McNally
2016/06/30 04:17:06
Done.
| |
64 print('upload_to_google_storage.py -b ' | |
65 'chromium-instrumented-libraries %s.tgz') % archive_name | |
66 print 'You should then commit the resulting .sha1 file.' | |
67 | |
68 | |
69 def main(): | |
70 parser = argparse.ArgumentParser( | |
71 description=__doc__, | |
72 formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
73 parser.add_argument( | |
74 '--jobs', | |
75 '-j', | |
76 type=int, | |
77 default=8, | |
78 help='the default number of jobs to use when running make') | |
79 parser.add_argument('--use_goma', | |
80 action='store_true', | |
81 default=False, | |
82 help='whether to use goma to compile') | |
83 parser.add_argument('build_type', | |
84 nargs='*', | |
85 default='all', | |
86 choices=BUILD_TYPES.keys() + ['all'], | |
87 help='the type of instrumented library to build') | |
88 args = parser.parse_args() | |
89 if args.build_type == 'all' or 'all' in args.build_type: | |
90 args.build_type = BUILD_TYPES.keys() | |
91 | |
92 ubuntu_release = _get_release() | |
93 if ubuntu_release not in SUPPORTED_RELEASES: | |
94 raise UnsupportedReleaseError('%s is not a supported release' % | |
95 _get_release()) | |
96 for build_type in sorted(set(args.build_type)): | |
97 build_libraries(build_type, ubuntu_release, args.jobs, args.use_goma) | |
98 | |
99 | |
100 if __name__ == '__main__': | |
101 main() | |
OLD | NEW |