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'
44 valid_archs
= ('arm', 'i386', 'amd64')
47 def GetSha1(filename
):
49 with
open(filename
, 'rb') as f
:
51 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
52 chunk
= f
.read(1024*1024)
56 return sha1
.hexdigest()
59 def DetectArch(gyp_defines
):
60 # Check for optional target_arch and only install for that architecture.
61 # 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
:
67 elif 'target_arch=arm' in gyp_defines
:
70 # Figure out host arch using build/detect_host_arch.py and
71 # set target_arch to host arch
72 SRC_DIR
= os
.path
.abspath(
73 os
.path
.join(SCRIPT_DIR
, '..', '..', '..', '..'))
74 sys
.path
.append(os
.path
.join(SRC_DIR
, 'build'))
75 import detect_host_arch
77 detected_host_arch
= detect_host_arch
.HostArch()
78 if detected_host_arch
== 'x64':
80 elif detected_host_arch
== 'ia32':
82 elif detected_host_arch
== 'arm':
85 print "Unknown host arch: %s" % detected_host_arch
91 if options
.linux_only
:
92 # This argument is passed when run from the gclient hooks.
93 # In this case we return early on non-linux platforms.
94 if not sys
.platform
.startswith('linux'):
97 gyp_defines
= os
.environ
.get('GYP_DEFINES', '')
100 target_arch
= options
.arch
102 target_arch
= DetectArch(gyp_defines
)
104 print 'Unable to detect host architecture'
107 if options
.linux_only
and target_arch
!= 'arm':
108 # When run from runhooks, only install the sysroot for an Official Chrome
109 # Linux build, except on ARM where we always use a sysroot.
110 defined
= ['branding=Chrome', 'buildtype=Official']
111 undefined
= ['chromeos=1']
112 for option
in defined
:
113 if option
not in gyp_defines
:
115 for option
in undefined
:
116 if option
in gyp_defines
:
119 # The sysroot directory should match the one specified in build/common.gypi.
120 # TODO(thestig) Consider putting this else where to avoid having to recreate
122 linux_dir
= os
.path
.dirname(SCRIPT_DIR
)
123 if target_arch
== 'amd64':
124 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_AMD64
)
125 tarball_filename
= TARBALL_AMD64
126 tarball_sha1sum
= TARBALL_AMD64_SHA1SUM
127 revision
= REVISION_AMD64
128 elif target_arch
== 'arm':
129 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_ARM
)
130 tarball_filename
= TARBALL_ARM
131 tarball_sha1sum
= TARBALL_ARM_SHA1SUM
132 revision
= REVISION_ARM
133 elif target_arch
== 'i386':
134 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_I386
)
135 tarball_filename
= TARBALL_I386
136 tarball_sha1sum
= TARBALL_I386_SHA1SUM
137 revision
= REVISION_I386
139 print 'Unknown architecture: %s' % target_arch
142 url
= '%s/%s/%s/%s' % (URL_PREFIX
, URL_PATH
, revision
, tarball_filename
)
144 stamp
= os
.path
.join(sysroot
, '.stamp')
145 if os
.path
.exists(stamp
):
146 with
open(stamp
) as s
:
148 print 'Debian Wheezy %s root image already up-to-date: %s' % \
149 (target_arch
, sysroot
)
152 print 'Installing Debian Wheezy %s root image: %s' % (target_arch
, sysroot
)
153 if os
.path
.isdir(sysroot
):
154 shutil
.rmtree(sysroot
)
156 tarball
= os
.path
.join(sysroot
, tarball_filename
)
157 print 'Downloading %s' % url
160 subprocess
.check_call(['curl', '--fail', '-L', url
, '-o', tarball
])
161 sha1sum
= GetSha1(tarball
)
162 if sha1sum
!= tarball_sha1sum
:
163 print 'Tarball sha1sum is wrong.'
164 print 'Expected %s, actual: %s' % (tarball_sha1sum
, sha1sum
)
166 subprocess
.check_call(['tar', 'xf', tarball
, '-C', sysroot
])
169 with
open(stamp
, 'w') as s
:
174 if __name__
== '__main__':
175 parser
= optparse
.OptionParser('usage: %prog [OPTIONS]')
176 parser
.add_option('--linux-only', action
='store_true',
177 default
=False, help='Only install sysroot for official '
179 parser
.add_option('--arch', type='choice', choices
=valid_archs
,
180 help='Sysroot architecture: %s' % ', '.join(valid_archs
))
181 options
, _
= parser
.parse_args()