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 import os 29 import shutil 30 import subprocess 31 import sys 32 33 34 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 35 URL_PREFIX = 'https://commondatastorage.googleapis.com' 36 URL_PATH = 'nativeclient-archive2/toolchain' 37 REVISION = 12356 38 TARBALL = 'sysroot-arm-trusted.tgz' 39 40 def main(args): 41 if '--linux-only' in args: 42 # This argument is passed when run from the gclient hooks. 43 # In this case we return early on non-linux platforms 44 # or if GYP_DEFINES doesn't include target_arch=arm 45 if not sys.platform.startswith('linux'): 46 return 0 47 48 if "target_arch=arm" not in os.environ.get('GYP_DEFINES', ''): 49 return 0 50 51 src_root = os.path.dirname(os.path.dirname(SCRIPT_DIR)) 52 sysroot = os.path.join(src_root, 'arm-sysroot') 53 url = "%s/%s/%s/%s" % (URL_PREFIX, URL_PATH, REVISION, TARBALL) 54 55 stamp = os.path.join(sysroot, ".stamp") 56 if os.path.exists(stamp): 57 with open(stamp) as s: 58 if s.read() == url: 59 print "ARM root image already up-to-date: %s" % sysroot 60 return 0 61 62 print "Installing ARM root image: %s" % sysroot 63 if os.path.isdir(sysroot): 64 shutil.rmtree(sysroot) 65 os.mkdir(sysroot) 66 tarball = os.path.join(sysroot, TARBALL) 67 subprocess.check_call(['curl', '-L', url, '-o', tarball]) 68 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 69 os.remove(tarball) 70 71 with open(stamp, 'w') as s: 72 s.write(url) 73 return 0 74 75 76 if __name__ == '__main__': 77 sys.exit(main(sys.argv[1:])) 78