2 # Copyright (c) 2013 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.
6 # Script to install a Debian Wheezy sysroot for making official Google Chrome
8 # The sysroot is needed to make Chrome work for Debian Wheezy.
9 # This script can be run manually but is more often run as part of gclient
10 # hooks. When run from hooks this script should be a no-op on non-linux
13 # The sysroot image could be constructed from scratch based on the current
14 # state or Debian Wheezy but for consistency we currently use a pre-built root
15 # image. The image will normally need to be rebuilt every time chrome's build
16 # dependancies are changed.
27 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
28 URL_PREFIX = 'https://commondatastorage.googleapis.com'
29 URL_PATH = 'chrome-linux-sysroot/toolchain'
31 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz'
32 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz'
33 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot'
34 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot'
38 if options.arch not in ['amd64', 'i386']:
39 print 'Unknown architecture: %s' % options.arch
42 if options.linux_only:
43 # This argument is passed when run from the gclient hooks.
44 # In this case we return early on non-linux platforms.
45 if not sys.platform.startswith('linux'):
48 # Only install the sysroot for an Official Chrome Linux build.
49 defined = ['branding=Chrome', 'buildtype=Official']
50 undefined = ['chromeos=1']
51 gyp_defines = os.environ.get('GYP_DEFINES', '')
52 for option in defined:
53 if option not in gyp_defines:
55 for option in undefined:
56 if option in gyp_defines:
59 # Check for optional target_arch and only install for that architecture.
60 # If target_arch is not specified, then only install for the host
63 if 'target_arch=x64' in gyp_defines:
65 elif 'target_arch=ia32' in gyp_defines:
68 # Figure out host arch, like the host_arch variable in build/common.gypi.
69 machine_type = platform.machine()
70 if machine_type in ['amd64', 'x86_64']:
72 elif re.match('(i[3-6]86|i86pc)$', machine_type):
74 if host_arch != options.arch:
77 # The sysroot directory should match the one specified in build/common.gypi.
78 # TODO(thestig) Consider putting this else where to avoid having to recreate
80 linux_dir = os.path.dirname(SCRIPT_DIR)
81 if options.arch == 'amd64':
82 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
83 tarball_filename = TARBALL_AMD64
85 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
86 tarball_filename = TARBALL_I386
87 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, REVISION, tarball_filename)
89 stamp = os.path.join(sysroot, '.stamp')
90 if os.path.exists(stamp):
91 with open(stamp) as s:
93 print 'Debian Wheezy %s root image already up-to-date: %s' % \
94 (options.arch, sysroot)
97 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot)
98 if os.path.isdir(sysroot):
99 shutil.rmtree(sysroot)
101 tarball = os.path.join(sysroot, tarball_filename)
102 subprocess.check_call(['curl', '-L', url, '-o', tarball])
103 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
106 with open(stamp, 'w') as s:
111 if __name__ == '__main__':
112 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
113 parser.add_option('', '--linux-only', dest='linux_only', action='store_true',
114 default=False, help='Only install sysroot for official '
116 parser.add_option('', '--arch', dest='arch',
117 help='Sysroot architecture, i386 or amd64')
118 options, args = parser.parse_args()
119 sys.exit(main(options))