2 # Copyright (c) 2012 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 ARM root image for cross building of ARM chrome on linux.
7 This script can be run manually but is more often run as part of gclient
8 hooks. When run from hooks this script should be a no-op on non-linux
11 The sysroot image could be constructed from scratch based on the current
12 state or precise/arm but for consistency we currently use a pre-built root
13 image which was originally designed for building trusted NaCl code. The image
14 will normally need to be rebuilt every time chrome's build dependancies are
17 Steps to rebuild the arm sysroot image:
19 - cd $SRC/native_client
20 - ./tools/trusted_cross_toolchains/trusted-toolchain-creator.armel.precise.sh \
22 - ./tools/trusted_cross_toolchains/trusted-toolchain-creator.armel.precise.sh \
23 BuildJail $SRC/out/arm-sysroot.tar.gz
24 - gsutil cp -a public-read $SRC/out/arm-sysroot.tar.gz \
25 nativeclient-archive2/toolchain/$NACL_REV/sysroot-arm-trusted.tgz
28 # TODO(sbc): merge this script into:
29 # chrome/installer/linux/sysroot_scripts/install-debian.wheezy.sysroot.py
38 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
39 URL_PREFIX
= 'https://storage.googleapis.com'
40 URL_PATH
= 'chrome-linux-sysroot/toolchain'
42 TARBALL
= 'debian_wheezy_arm_sysroot.tgz'
43 TARBALL_SHA1SUM
= 'fc2f54db168887c5190c4c6686c869bedf668b4e'
46 def get_sha1(filename
):
48 with
open(filename
, 'rb') as f
:
50 # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
51 chunk
= f
.read(1024*1024)
55 return sha1
.hexdigest()
59 if '--linux-only' in args
:
60 # This argument is passed when run from the gclient hooks.
61 # In this case we return early on non-linux platforms
62 # or if GYP_DEFINES doesn't include target_arch=arm
63 if not sys
.platform
.startswith('linux'):
66 if "target_arch=arm" not in os
.environ
.get('GYP_DEFINES', ''):
69 src_root
= os
.path
.dirname(os
.path
.dirname(SCRIPT_DIR
))
70 sysroot
= os
.path
.join(src_root
, 'arm-sysroot')
71 url
= "%s/%s/%s/%s" % (URL_PREFIX
, URL_PATH
, REVISION
, TARBALL
)
73 stamp
= os
.path
.join(sysroot
, ".stamp")
74 if os
.path
.exists(stamp
):
75 with
open(stamp
) as s
:
77 print "ARM root image already up-to-date: %s" % sysroot
80 print "Installing ARM root image: %s" % sysroot
81 if os
.path
.isdir(sysroot
):
82 shutil
.rmtree(sysroot
)
84 tarball
= os
.path
.join(sysroot
, TARBALL
)
85 curl
= ['curl', '--fail', '-L', url
, '-o', tarball
]
86 if os
.isatty(sys
.stdout
.fileno()):
87 curl
.append('--progress')
89 curl
.append('--silent')
90 subprocess
.check_call(curl
)
91 sha1sum
= get_sha1(tarball
)
92 if sha1sum
!= TARBALL_SHA1SUM
:
93 print 'Tarball sha1sum is wrong.'
94 print 'Expected %s, actual: %s' % (TARBALL_SHA1SUM
, sha1sum
)
96 subprocess
.check_call(['tar', 'xf', tarball
, '-C', sysroot
])
99 with
open(stamp
, 'w') as s
:
104 if __name__
== '__main__':
105 sys
.exit(main(sys
.argv
[1:]))