• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2017 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8
9"""Create the asset."""
10
11
12import argparse
13import common
14import grp
15import os
16import pwd
17import shutil
18import subprocess
19import sys
20import tempfile
21import urllib2
22import utils
23
24
25VALGRIND = 'valgrind-3.13.0'
26TARBALL = '%s.tar.bz2' % VALGRIND
27DOWNLOAD_URL = 'ftp://sourceware.org/pub/valgrind/%s' % TARBALL
28TEMP_DIR = os.path.join(tempfile.gettempdir(), 'skia-%s' % VALGRIND)
29INSTALL_DIR = os.path.join(TEMP_DIR, 'valgrind_install')
30
31
32def download_tarball():
33  with utils.chdir(TEMP_DIR):
34    if os.path.isfile(TARBALL):
35      return
36    with open(TARBALL, 'wb') as f:
37      f.write(urllib2.urlopen(DOWNLOAD_URL).read())
38
39
40def unzip_tarball():
41  with utils.chdir(TEMP_DIR):
42    if os.path.isdir(VALGRIND):
43      return
44    subprocess.check_call(['tar', 'xvjf', TARBALL])
45
46
47def create_install_dir():
48  if os.path.isdir(INSTALL_DIR):
49    return
50  os.makedirs(INSTALL_DIR)
51
52
53def build_valgrind():
54  if os.path.isfile(os.path.join(INSTALL_DIR, 'bin', 'valgrind')):
55    return
56  with utils.chdir(os.path.join(TEMP_DIR, VALGRIND)):
57    subprocess.check_call(['./configure', '--prefix=%s' % INSTALL_DIR])
58    subprocess.check_call(['make'])
59    subprocess.check_call(['make', 'install'])
60
61
62def copy_files(target_dir):
63  with utils.chdir(os.path.join(TEMP_DIR, VALGRIND)):
64    os.mkdir(os.path.join(target_dir, 'bin'))
65    shutil.copy(os.path.join(INSTALL_DIR, 'bin', 'valgrind'),
66                os.path.join(target_dir, 'bin', 'valgrind'))
67    os.mkdir(os.path.join(target_dir, 'lib'))
68    os.mkdir(os.path.join(target_dir, 'lib', 'valgrind'))
69    for lib in ['memcheck-amd64-linux']:
70      shutil.copy(os.path.join(INSTALL_DIR, 'lib', 'valgrind', lib),
71                  os.path.join(target_dir, 'lib', 'valgrind', lib))
72    for lib in ['core', 'memcheck']:
73      libname = 'vgpreload_%s-amd64-linux.so' % lib
74      shutil.copy(os.path.join(INSTALL_DIR, 'lib', 'valgrind', libname),
75                  os.path.join(target_dir, 'lib', 'valgrind', libname))
76
77    shutil.copy('default.supp',
78                os.path.join(target_dir, 'lib', 'valgrind', 'default.supp'))
79
80
81def create_asset(target_dir):
82  """Create the asset."""
83  if os.name == 'nt':
84    print 'This script does not run on Windows.'
85    sys.exit(1)
86
87  create_install_dir()
88  if not os.path.isdir(TEMP_DIR):
89    os.makedirs(TEMP_DIR)
90  download_tarball()
91  unzip_tarball()
92  build_valgrind()
93  copy_files(target_dir)
94
95
96def main():
97  parser = argparse.ArgumentParser()
98  parser.add_argument('--target_dir', '-t', required=True)
99  args = parser.parse_args()
100  create_asset(args.target_dir)
101
102
103if __name__ == '__main__':
104  main()
105