OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 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 | 5 |
6 """Downloads pre-built sanitizer-instrumented third-party libraries from GCS. | 6 """Downloads pre-built sanitizer-instrumented third-party libraries from GCS.""" |
7 This script should only be run from gn. | |
8 """ | |
9 | 7 |
| 8 import os |
| 9 import re |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 | 12 |
13 | 13 |
| 14 SCRIPT_PATH = os.path.abspath(__file__) |
| 15 BASE_PATH = os.path.normpath(os.path.join(SCRIPT_PATH, *(4 * ['..']))) |
| 16 |
| 17 # This defaults to the consuming project's base directory, e.g. 'src' in |
| 18 # chromium. |
| 19 BASE_DIR = os.path.basename(BASE_PATH) |
| 20 |
| 21 |
| 22 def get_ubuntu_release(): |
| 23 supported_releases = ['trusty'] |
| 24 release = subprocess.check_output(['lsb_release', '-cs']).strip() |
| 25 if release not in supported_releases: |
| 26 raise Exception("Supported Ubuntu versions: %s", str(supported_releases)) |
| 27 return release |
| 28 |
| 29 |
| 30 def get_configuration(gyp_defines): |
| 31 if re.search(r'\b(msan)=1', gyp_defines): |
| 32 if 'msan_track_origins=0' in gyp_defines: |
| 33 return 'msan-no-origins' |
| 34 if 'msan_track_origins=2' in gyp_defines: |
| 35 return 'msan-chained-origins' |
| 36 if 'msan_track_origins=' not in gyp_defines: |
| 37 # NB: must be the same as the default value in common.gypi |
| 38 return 'msan-chained-origins' |
| 39 raise Exception( |
| 40 "Prebuilt instrumented libraries not available for your configuration.") |
| 41 |
| 42 |
| 43 def get_archive_name(gyp_defines): |
| 44 return "%s-%s.tgz" % (get_configuration(gyp_defines), get_ubuntu_release()) |
| 45 |
| 46 |
14 def main(args): | 47 def main(args): |
| 48 gyp_defines = os.environ.get('GYP_DEFINES', '') |
| 49 if not 'use_prebuilt_instrumented_libraries=1' in gyp_defines: |
| 50 return 0 |
| 51 |
15 if not sys.platform.startswith('linux'): | 52 if not sys.platform.startswith('linux'): |
16 raise Exception("Prebuilt instrumented libraries require Linux.") | 53 raise Exception("'use_prebuilt_instrumented_libraries=1' requires Linux.") |
17 | 54 |
18 sha1file = args[0] | 55 archive_name = get_archive_name(gyp_defines) |
19 tarfile = args[1] | 56 sha1file = '%s.sha1' % archive_name |
| 57 target_directory = os.path.join( |
| 58 BASE_DIR, 'third_party', 'instrumented_libraries', 'binaries') |
20 | 59 |
21 subprocess.check_call([ | 60 subprocess.check_call([ |
22 'download_from_google_storage', | 61 'download_from_google_storage', |
23 '--no_resume', | 62 '--no_resume', |
24 '--no_auth', | 63 '--no_auth', |
25 '--bucket', 'chromium-instrumented-libraries', | 64 '--bucket', 'chromium-instrumented-libraries', |
26 '-s', sha1file, '-o', tarfile]) | 65 '-s', sha1file], cwd=target_directory) |
27 | 66 |
28 return 0 | 67 return 0 |
29 | 68 |
30 | 69 |
31 if __name__ == '__main__': | 70 if __name__ == '__main__': |
32 # TODO(thomasanderson): Remove this once all third_party DEPS | |
33 # entires for this script are removed. | |
34 if (len(sys.argv) == 1): | |
35 sys.exit(0) | |
36 sys.exit(main(sys.argv[1:])) | 71 sys.exit(main(sys.argv[1:])) |
OLD | NEW |