1#!/usr/bin/env python 2# Copyright 2015 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 6"""Unpacks pre-built sanitizer-instrumented third-party libraries.""" 7 8import os 9import subprocess 10import shutil 11import sys 12 13 14def get_archive_name(archive_prefix): 15 supported_release = 'trusty' 16 release = subprocess.check_output(['lsb_release', '-cs']).strip() 17 if release != supported_release: 18 print('WARNING: unsupported distro. You need to run a Trusty Docker ' 19 'image. Please see ' 20 'https://www.chromium.org/developers/testing/memorysanitizer/') 21 22 return '%s-%s.tgz' % (archive_prefix, supported_release) 23 24 25def main(archive_prefix, archive_dir, target_dir, stamp_dir=None): 26 shutil.rmtree(target_dir, ignore_errors=True) 27 28 os.mkdir(target_dir) 29 subprocess.check_call([ 30 'tar', 31 '-zxf', 32 os.path.join(archive_dir, get_archive_name(archive_prefix)), 33 '-C', 34 target_dir]) 35 stamp_file = os.path.join(stamp_dir or target_dir, '%s.txt' % archive_prefix) 36 open(stamp_file, 'w').close() 37 38 if stamp_dir: 39 with open(os.path.join(stamp_dir, '%s.d' % archive_prefix), 'w') as f: 40 f.write('%s: %s' % ( 41 stamp_file, os.path.join(archive_dir, 42 get_archive_name(archive_prefix)))) 43 return 0 44 45 46if __name__ == '__main__': 47 sys.exit(main(*sys.argv[1:])) 48