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.
28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
29 URL_PREFIX = 'http://storage.googleapis.com'
30 URL_PATH = 'chrome-linux-sysroot/toolchain'
31 REVISION_AMD64 = 264817
32 REVISION_I386 = 264817
34 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz'
35 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz'
36 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz'
37 TARBALL_AMD64_SHA1SUM = '74b7231e12aaf45c5c5489d9aebb56bd6abb3653'
38 TARBALL_I386_SHA1SUM = 'fe3d284926839683b00641bc66c9023f872ea4b4'
39 TARBALL_ARM_SHA1SUM = 'fc2f54db168887c5190c4c6686c869bedf668b4e'
40 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot'
41 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot'
42 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot'
45 def get_sha1(filename):
47 with open(filename, 'rb') as f:
49 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
50 chunk = f.read(1024*1024)
54 return sha1.hexdigest()
58 if options.arch not in ['amd64', 'i386', 'arm']:
59 print 'Unknown architecture: %s' % options.arch
62 if options.linux_only:
63 # This argument is passed when run from the gclient hooks.
64 # In this case we return early on non-linux platforms.
65 if not sys.platform.startswith('linux'):
68 gyp_defines = os.environ.get('GYP_DEFINES', '')
70 # Only install the sysroot for an Official Chrome Linux build, except
71 # for ARM where we always use a sysroot.
72 if options.arch != 'arm':
73 defined = ['branding=Chrome', 'buildtype=Official']
74 undefined = ['chromeos=1']
75 for option in defined:
76 if option not in gyp_defines:
78 for option in undefined:
79 if option in gyp_defines:
82 # Check for optional target_arch and only install for that architecture.
83 # If target_arch is not specified, then only install for the host
86 if 'target_arch=x64' in gyp_defines:
88 elif 'target_arch=ia32' in gyp_defines:
90 elif 'target_arch=arm' in gyp_defines:
93 # Figure out host arch using build/detect_host_arch.py and
94 # set target_arch to host arch
95 SRC_DIR = os.path.abspath(
96 os.path.join(SCRIPT_DIR, '..', '..', '..', '..'))
97 sys.path.append(os.path.join(SRC_DIR, 'build'))
98 import detect_host_arch
100 detected_host_arch = detect_host_arch.HostArch()
101 if detected_host_arch == 'x64':
102 target_arch = 'amd64'
103 elif detected_host_arch == 'ia32':
105 elif detected_host_arch == 'arm':
108 if target_arch != options.arch:
111 # The sysroot directory should match the one specified in build/common.gypi.
112 # TODO(thestig) Consider putting this else where to avoid having to recreate
114 linux_dir = os.path.dirname(SCRIPT_DIR)
115 if options.arch == 'amd64':
116 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64)
117 tarball_filename = TARBALL_AMD64
118 tarball_sha1sum = TARBALL_AMD64_SHA1SUM
119 revision = REVISION_AMD64
120 elif options.arch == 'arm':
121 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM)
122 tarball_filename = TARBALL_ARM
123 tarball_sha1sum = TARBALL_ARM_SHA1SUM
124 revision = REVISION_ARM
125 elif options.arch == 'i386':
126 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386)
127 tarball_filename = TARBALL_I386
128 tarball_sha1sum = TARBALL_I386_SHA1SUM
129 revision = REVISION_I386
134 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
136 stamp = os.path.join(sysroot, '.stamp')
137 if os.path.exists(stamp):
138 with open(stamp) as s:
140 print 'Debian Wheezy %s root image already up-to-date: %s' % \
141 (options.arch, sysroot)
144 print 'Installing Debian Wheezy %s root image: %s' % (options.arch, sysroot)
145 if os.path.isdir(sysroot):
146 shutil.rmtree(sysroot)
148 tarball = os.path.join(sysroot, tarball_filename)
149 print 'Downloading %s' % url
152 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball])
153 sha1sum = get_sha1(tarball)
154 if sha1sum != tarball_sha1sum:
155 print 'Tarball sha1sum is wrong.'
156 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)
158 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
161 with open(stamp, 'w') as s:
166 if __name__ == '__main__':
167 parser = optparse.OptionParser('usage: %prog [OPTIONS]')
168 parser.add_option('--linux-only', action='store_true',
169 default=False, help='Only install sysroot for official '
171 parser.add_option('--arch', help='Sysroot architecture: i386, amd64 or arm')
172 options, args = parser.parse_args()