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
= 'a2d45701cb21244b9514e420950ba6ba687fb655'
32 REVISION_ARM
= 'a2d45701cb21244b9514e420950ba6ba687fb655'
33 REVISION_I386
= 'a2d45701cb21244b9514e420950ba6ba687fb655'
34 REVISION_MIPS
= '7749d2957387abf225b6d45154c3ddad142148dc'
35 TARBALL_AMD64
= 'debian_wheezy_amd64_sysroot.tgz'
36 TARBALL_ARM
= 'debian_wheezy_arm_sysroot.tgz'
37 TARBALL_I386
= 'debian_wheezy_i386_sysroot.tgz'
38 TARBALL_MIPS
= 'debian_wheezy_mips_sysroot.tgz'
39 TARBALL_AMD64_SHA1SUM
= '601216c0f980e798e7131635f3dd8171b3dcbcde'
40 TARBALL_ARM_SHA1SUM
= '6289593b36616526562a4d85ae9c92b694b8ce7e'
41 TARBALL_I386_SHA1SUM
= '0090e5a4b56ab9ffb5d557da6a520195ab59b446'
42 TARBALL_MIPS_SHA1SUM
= '3b4d782a237db4aac185a638572a7747c1a21825'
43 SYSROOT_DIR_AMD64
= 'debian_wheezy_amd64-sysroot'
44 SYSROOT_DIR_ARM
= 'debian_wheezy_arm-sysroot'
45 SYSROOT_DIR_I386
= 'debian_wheezy_i386-sysroot'
46 SYSROOT_DIR_MIPS
= 'debian_wheezy_mips-sysroot'
48 valid_archs
= ('arm', 'i386', 'amd64', 'mips')
51 def GetSha1(filename
):
53 with
open(filename
, 'rb') as f
:
55 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
56 chunk
= f
.read(1024*1024)
60 return sha1
.hexdigest()
63 def DetectArch(gyp_defines
):
64 # Check for optional target_arch and only install for that architecture.
65 # If target_arch is not specified, then only install for the host
67 if 'target_arch=x64' in gyp_defines
:
69 elif 'target_arch=ia32' in gyp_defines
:
71 elif 'target_arch=arm' in gyp_defines
:
73 elif 'target_arch=mipsel' in gyp_defines
:
76 # Figure out host arch using build/detect_host_arch.py and
77 # set target_arch to host arch
78 SRC_DIR
= os
.path
.abspath(
79 os
.path
.join(SCRIPT_DIR
, '..', '..', '..', '..'))
80 sys
.path
.append(os
.path
.join(SRC_DIR
, 'build'))
81 import detect_host_arch
83 detected_host_arch
= detect_host_arch
.HostArch()
84 if detected_host_arch
== 'x64':
86 elif detected_host_arch
== 'ia32':
88 elif detected_host_arch
== 'arm':
90 elif detected_host_arch
== 'mips':
93 print "Unknown host arch: %s" % detected_host_arch
99 if options
.running_as_hook
and not sys
.platform
.startswith('linux'):
102 gyp_defines
= os
.environ
.get('GYP_DEFINES', '')
105 target_arch
= options
.arch
107 target_arch
= DetectArch(gyp_defines
)
109 print 'Unable to detect host architecture'
112 if options
.running_as_hook
and target_arch
!= 'arm' and target_arch
!= 'mips':
113 # When run from runhooks, only install the sysroot for an Official Chrome
114 # Linux build, except on ARM where we always use a sysroot.
115 skip_if_defined
= ['branding=Chrome', 'buildtype=Official']
116 skip_if_undefined
= ['chromeos=1']
117 for option
in skip_if_defined
:
118 if option
not in gyp_defines
:
120 for option
in skip_if_undefined
:
121 if option
in gyp_defines
:
124 # The sysroot directory should match the one specified in build/common.gypi.
125 # TODO(thestig) Consider putting this else where to avoid having to recreate
127 linux_dir
= os
.path
.dirname(SCRIPT_DIR
)
128 if target_arch
== 'amd64':
129 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_AMD64
)
130 tarball_filename
= TARBALL_AMD64
131 tarball_sha1sum
= TARBALL_AMD64_SHA1SUM
132 revision
= REVISION_AMD64
133 elif target_arch
== 'arm':
134 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_ARM
)
135 tarball_filename
= TARBALL_ARM
136 tarball_sha1sum
= TARBALL_ARM_SHA1SUM
137 revision
= REVISION_ARM
138 elif target_arch
== 'i386':
139 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_I386
)
140 tarball_filename
= TARBALL_I386
141 tarball_sha1sum
= TARBALL_I386_SHA1SUM
142 revision
= REVISION_I386
143 elif target_arch
== 'mips':
144 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_MIPS
)
145 tarball_filename
= TARBALL_MIPS
146 tarball_sha1sum
= TARBALL_MIPS_SHA1SUM
147 revision
= REVISION_MIPS
149 print 'Unknown architecture: %s' % target_arch
152 url
= '%s/%s/%s/%s' % (URL_PREFIX
, URL_PATH
, revision
, tarball_filename
)
154 stamp
= os
.path
.join(sysroot
, '.stamp')
155 if os
.path
.exists(stamp
):
156 with
open(stamp
) as s
:
158 print 'Debian Wheezy %s root image already up-to-date: %s' % \
159 (target_arch
, sysroot
)
162 print 'Installing Debian Wheezy %s root image: %s' % (target_arch
, sysroot
)
163 if os
.path
.isdir(sysroot
):
164 shutil
.rmtree(sysroot
)
166 tarball
= os
.path
.join(sysroot
, tarball_filename
)
167 print 'Downloading %s' % url
170 subprocess
.check_call(['curl', '--fail', '-L', url
, '-o', tarball
])
171 sha1sum
= GetSha1(tarball
)
172 if sha1sum
!= tarball_sha1sum
:
173 print 'Tarball sha1sum is wrong.'
174 print 'Expected %s, actual: %s' % (tarball_sha1sum
, sha1sum
)
176 subprocess
.check_call(['tar', 'xf', tarball
, '-C', sysroot
])
179 with
open(stamp
, 'w') as s
:
184 if __name__
== '__main__':
185 parser
= optparse
.OptionParser('usage: %prog [OPTIONS]')
186 parser
.add_option('--running-as-hook', action
='store_true',
187 default
=False, help='Used when running from gclient hooks.'
188 ' In this mode the sysroot will only '
189 'be installed for official Linux '
190 'builds or ARM Linux builds')
191 parser
.add_option('--arch', type='choice', choices
=valid_archs
,
192 help='Sysroot architecture: %s' % ', '.join(valid_archs
))
193 options
, _
= parser
.parse_args()