Chromium Code Reviews| Index: third_party/instrumented_libraries/scripts/build_and_package.py |
| diff --git a/third_party/instrumented_libraries/scripts/build_and_package.py b/third_party/instrumented_libraries/scripts/build_and_package.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..70c33eaae2b3968c5255f3adcd9497107c164688 |
| --- /dev/null |
| +++ b/third_party/instrumented_libraries/scripts/build_and_package.py |
| @@ -0,0 +1,101 @@ |
| +#!/usr/bin/python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +"""Builds and packages instrumented libraries for dynamic tools.""" |
| + |
| +import argparse |
| +import contextlib |
| +import os |
| +import shutil |
| +import subprocess |
| +import tarfile |
| + |
| +BUILD_TYPES = {'msan-no-origins': 0, 'msan-chained-origins': 2} |
| +SUPPORTED_RELEASES = frozenset(['trusty']) |
| + |
| + |
| +class Error(Exception): |
| + pass |
| + |
| + |
| +class UnsupportedReleaseError(Error): |
| + pass |
| + |
| + |
| +def _get_release(): |
| + return subprocess.check_output(['lsb_release', '-cs']).strip() |
| + |
| + |
| +def _tar_filter(tar_info): |
| + if tar_info.name.endswith('.txt'): |
| + return None |
| + return tar_info |
| + |
| + |
| +def build_libraries(build_type, ubuntu_release, jobs, use_goma): |
| + archive_name = '%s-%s' % (build_type, ubuntu_release) |
| + build_dir = 'out/Instrumented-%s' % archive_name |
| + if not os.path.exists(build_dir): |
| + os.makedirs(build_dir) |
| + |
| + gn_args = [ |
| + 'is_debug = false', |
| + '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.
|
| + 'use_goma = %s' % str(use_goma).lower(), |
| + 'instrumented_libraries_jobs = %d' % jobs, |
| + 'use_locally_built_instrumented_libraries = true', |
| + '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.
|
| + 'instrumented_libraries_platform = "%s"' % ubuntu_release, |
| + ] |
| + with open(os.path.join(build_dir, 'args.gn'), 'w') as f: |
| + f.write('\n'.join(gn_args)) |
| + 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.
|
| + subprocess.check_call(['ninja', '-j2', '-C', build_dir, |
| + 'third_party/instrumented_libraries:locally_built']) |
| + with tarfile.open('%s.tgz' % archive_name, mode='w:gz') as f: |
| + f.add('%s/instrumented_libraries/msan' % build_dir, |
| + arcname='msan', |
| + filter=_tar_filter) |
| + f.add('%s/instrumented_libraries/sources' % build_dir, |
| + arcname='sources', |
| + filter=_tar_filter) |
| + 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.
|
| + print('upload_to_google_storage.py -b ' |
| + 'chromium-instrumented-libraries %s.tgz') % archive_name |
| + print 'You should then commit the resulting .sha1 file.' |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser( |
| + description=__doc__, |
| + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| + parser.add_argument( |
| + '--jobs', |
| + '-j', |
| + type=int, |
| + default=8, |
| + help='the default number of jobs to use when running make') |
| + parser.add_argument('--use_goma', |
| + action='store_true', |
| + default=False, |
| + help='whether to use goma to compile') |
| + parser.add_argument('build_type', |
| + nargs='*', |
| + default='all', |
| + choices=BUILD_TYPES.keys() + ['all'], |
| + help='the type of instrumented library to build') |
| + args = parser.parse_args() |
| + if args.build_type == 'all' or 'all' in args.build_type: |
| + args.build_type = BUILD_TYPES.keys() |
| + |
| + ubuntu_release = _get_release() |
| + if ubuntu_release not in SUPPORTED_RELEASES: |
| + raise UnsupportedReleaseError('%s is not a supported release' % |
| + _get_release()) |
| + for build_type in sorted(set(args.build_type)): |
| + build_libraries(build_type, ubuntu_release, args.jobs, args.use_goma) |
| + |
| + |
| +if __name__ == '__main__': |
| + main() |