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
= 'https://commondatastorage.googleapis.com'
30 URL_PATH
= 'chrome-linux-sysroot/toolchain'
32 TARBALL_AMD64
= 'debian_wheezy_amd64_sysroot.tgz'
33 TARBALL_I386
= 'debian_wheezy_i386_sysroot.tgz'
34 TARBALL_AMD64_SHA1SUM
= '74b7231e12aaf45c5c5489d9aebb56bd6abb3653'
35 TARBALL_I386_SHA1SUM
= 'fe3d284926839683b00641bc66c9023f872ea4b4'
36 SYSROOT_DIR_AMD64
= 'debian_wheezy_amd64-sysroot'
37 SYSROOT_DIR_I386
= 'debian_wheezy_i386-sysroot'
40 def get_sha1(filename
):
42 with
open(filename
, 'rb') as f
:
44 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
45 chunk
= f
.read(1024*1024)
49 return sha1
.hexdigest()
53 if options
.arch
not in ['amd64', 'i386']:
54 print 'Unknown architecture: %s' % options
.arch
57 if options
.linux_only
:
58 # This argument is passed when run from the gclient hooks.
59 # In this case we return early on non-linux platforms.
60 if not sys
.platform
.startswith('linux'):
63 # Only install the sysroot for an Official Chrome Linux build.
64 defined
= ['branding=Chrome', 'buildtype=Official']
65 undefined
= ['chromeos=1']
66 gyp_defines
= os
.environ
.get('GYP_DEFINES', '')
67 for option
in defined
:
68 if option
not in gyp_defines
:
70 for option
in undefined
:
71 if option
in gyp_defines
:
74 # Check for optional target_arch and only install for that architecture.
75 # If target_arch is not specified, then only install for the host
78 if 'target_arch=x64' in gyp_defines
:
80 elif 'target_arch=ia32' in gyp_defines
:
83 # Figure out host arch using build/detect_host_arch.py.
84 SRC_DIR
= os
.path
.abspath(
85 os
.path
.join(SCRIPT_DIR
, '..', '..', '..', '..'))
86 sys
.path
.append(os
.path
.join(SRC_DIR
, 'build'))
87 import detect_host_arch
89 detected_host_arch
= detect_host_arch
.HostArch()
90 if detected_host_arch
== 'x64':
92 elif detected_host_arch
== 'ia32':
94 if host_arch
!= options
.arch
:
97 # The sysroot directory should match the one specified in build/common.gypi.
98 # TODO(thestig) Consider putting this else where to avoid having to recreate
100 linux_dir
= os
.path
.dirname(SCRIPT_DIR
)
101 if options
.arch
== 'amd64':
102 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_AMD64
)
103 tarball_filename
= TARBALL_AMD64
104 tarball_sha1sum
= TARBALL_AMD64_SHA1SUM
106 sysroot
= os
.path
.join(linux_dir
, SYSROOT_DIR_I386
)
107 tarball_filename
= TARBALL_I386
108 tarball_sha1sum
= TARBALL_I386_SHA1SUM
109 url
= '%s/%s/%s/%s' % (URL_PREFIX
, URL_PATH
, REVISION
, tarball_filename
)
111 stamp
= os
.path
.join(sysroot
, '.stamp')
112 if os
.path
.exists(stamp
):
113 with
open(stamp
) as s
:
115 print 'Debian Wheezy %s root image already up-to-date: %s' % \
116 (options
.arch
, sysroot
)
119 print 'Installing Debian Wheezy %s root image: %s' % (options
.arch
, sysroot
)
120 if os
.path
.isdir(sysroot
):
121 shutil
.rmtree(sysroot
)
123 tarball
= os
.path
.join(sysroot
, tarball_filename
)
124 subprocess
.check_call(['curl', '-L', url
, '-o', tarball
])
125 sha1sum
= get_sha1(tarball
)
126 if sha1sum
!= tarball_sha1sum
:
127 print 'Tarball sha1sum is wrong.'
128 print 'Expected %s, actual: %s' % (tarball_sha1sum
, sha1sum
)
130 subprocess
.check_call(['tar', 'xf', tarball
, '-C', sysroot
])
133 with
open(stamp
, 'w') as s
:
138 if __name__
== '__main__':
139 parser
= optparse
.OptionParser('usage: %prog [OPTIONS]')
140 parser
.add_option('', '--linux-only', dest
='linux_only', action
='store_true',
141 default
=False, help='Only install sysroot for official '
143 parser
.add_option('', '--arch', dest
='arch',
144 help='Sysroot architecture, i386 or amd64')
145 options
, args
= parser
.parse_args()
146 sys
.exit(main(options
))