Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / build / linux / install-arm-sysroot.py
1 #!/usr/bin/env python
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.
5
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
9 platforms.
10
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
15 changed.
16
17 Steps to rebuild the arm sysroot image:
18
19 - cd $SRC/native_client
20 - ./tools/trusted_cross_toolchains/trusted-toolchain-creator.armel.precise.sh \
21     UpdatePackageLists
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
26 """
27
28 # TODO(sbc): merge this script into:
29 #  chrome/installer/linux/sysroot_scripts/install-debian.wheezy.sysroot.py
30
31 import hashlib
32 import os
33 import shutil
34 import subprocess
35 import sys
36
37
38 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
39 URL_PREFIX = 'https://storage.googleapis.com'
40 URL_PATH = 'chrome-linux-sysroot/toolchain'
41 REVISION = 285950
42 TARBALL = 'debian_wheezy_arm_sysroot.tgz'
43 TARBALL_SHA1SUM = 'fc2f54db168887c5190c4c6686c869bedf668b4e'
44
45
46 def get_sha1(filename):
47   sha1 = hashlib.sha1()
48   with open(filename, 'rb') as f:
49     while True:
50       # Read in 1mb chunks, so it doesn't all have to be loaded into memory.
51       chunk = f.read(1024*1024)
52       if not chunk:
53         break
54       sha1.update(chunk)
55   return sha1.hexdigest()
56
57
58 def main(args):
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'):
64       return 0
65
66     if "target_arch=arm" not in os.environ.get('GYP_DEFINES', ''):
67       return 0
68
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)
72
73   stamp = os.path.join(sysroot, ".stamp")
74   if os.path.exists(stamp):
75     with open(stamp) as s:
76       if s.read() == url:
77         print "ARM root image already up-to-date: %s" % sysroot
78         return 0
79
80   print "Installing ARM root image: %s" % sysroot
81   if os.path.isdir(sysroot):
82     shutil.rmtree(sysroot)
83   os.mkdir(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')
88   else:
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)
95     return 1
96   subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
97   os.remove(tarball)
98
99   with open(stamp, 'w') as s:
100     s.write(url)
101   return 0
102
103
104 if __name__ == '__main__':
105   sys.exit(main(sys.argv[1:]))