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. 7This script can be run manually but is more often run as part of gclient 8hooks. When run from hooks this script should be a no-op on non-linux 9platforms. 10 11The sysroot image could be constructed from scratch based on the current 12state or precise/arm but for consistency we currently use a pre-built root 13image which was originally designed for building trusted NaCl code. The image 14will normally need to be rebuilt every time chrome's build dependancies are 15changed. 16 17Steps 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 28import os 29import shutil 30import subprocess 31import sys 32 33 34SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 35URL_PREFIX = 'https://storage.googleapis.com' 36URL_PATH = 'nativeclient-archive2/toolchain' 37REVISION = 13035 38TARBALL = 'sysroot-arm-trusted.tgz' 39 40def 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 curl = ['curl', '--fail', '-L', url, '-o', tarball] 68 if os.isatty(sys.stdout.fileno()): 69 curl.append('--progress') 70 else: 71 curl.append('--silent') 72 subprocess.check_call(curl) 73 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 74 os.remove(tarball) 75 76 with open(stamp, 'w') as s: 77 s.write(url) 78 return 0 79 80 81if __name__ == '__main__': 82 sys.exit(main(sys.argv[1:])) 83