summaryrefslogtreecommitdiffstats
path: root/third_party/instrumented_libraries/scripts/download_binaries.py
blob: 83ec7b6aa86ab9592c8661a88d03e046bef13f6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# Copyright (c) 2015 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.

"""Downloads pre-built sanitizer-instrumented third-party libraries from GCS."""

import os
import re
import subprocess
import sys

def get_ubuntu_release():
  supported_releases = ['precise', 'trusty']
  release = subprocess.check_output(['lsb_release', '-cs']).strip()
  if release not in supported_releases:
    raise Exception("Supported Ubuntu versions: %s", str(supported_releases))
  return release


def get_configuration(gyp_defines):
  if re.search(r'\b(msan)=1', gyp_defines):
    if 'msan_track_origins=0' in gyp_defines:
      return 'msan-no-origins'
    if 'msan_track_origins=2' in gyp_defines:
      return 'msan-chained-origins'
    if 'msan_track_origins=' not in gyp_defines:
      # NB: must be the same as the default value in common.gypi
      return 'msan-chained-origins'
  raise Exception(
      "Prebuilt instrumented libraries not available for your configuration.")


def get_archive_name(gyp_defines):
  return "%s-%s.tgz" % (get_configuration(gyp_defines), get_ubuntu_release())


def main(args):
  gyp_defines = os.environ.get('GYP_DEFINES', '')
  if not 'use_prebuilt_instrumented_libraries=1' in gyp_defines:
    return 0

  if not sys.platform.startswith('linux'):
    raise Exception("'use_prebuilt_instrumented_libraries=1' requires Linux.")

  archive_name = get_archive_name(gyp_defines)
  sha1file = '%s.sha1' % archive_name
  target_directory = 'src/third_party/instrumented_libraries/binaries/'

  subprocess.check_call([
      'download_from_google_storage',
      '--no_resume',
      '--no_auth',
      '--bucket', 'chromium-instrumented-libraries',
      '-s', sha1file], cwd=target_directory)

  return 0


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))