1cb93a386Sopenharmony_ci#!/usr/bin/env python 2cb93a386Sopenharmony_ci# 3cb93a386Sopenharmony_ci# Copyright 2016 Google Inc. 4cb93a386Sopenharmony_ci# 5cb93a386Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 6cb93a386Sopenharmony_ci# found in the LICENSE file. 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci 9cb93a386Sopenharmony_ci"""Create the asset.""" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_cifrom __future__ import print_function 13cb93a386Sopenharmony_ciimport argparse 14cb93a386Sopenharmony_ciimport fileinput 15cb93a386Sopenharmony_ciimport os 16cb93a386Sopenharmony_ciimport shutil 17cb93a386Sopenharmony_ciimport subprocess 18cb93a386Sopenharmony_ciimport sys 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_cifrom distutils import dir_util 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_cidef create_asset(target_dir): 24cb93a386Sopenharmony_ci """Create the asset.""" 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_ci print("Installing some cross-compiling packages. Hit enter to continue.") 27cb93a386Sopenharmony_ci input() 28cb93a386Sopenharmony_ci subprocess.check_call([ 29cb93a386Sopenharmony_ci "sudo","apt-get","install", 30cb93a386Sopenharmony_ci "libstdc++-6-dev-armhf-cross", 31cb93a386Sopenharmony_ci "libgcc-6-dev-armhf-cross", 32cb93a386Sopenharmony_ci "binutils-arm-linux-gnueabihf" 33cb93a386Sopenharmony_ci ]) 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci shutil.copytree('/usr/arm-linux-gnueabihf', target_dir) 37cb93a386Sopenharmony_ci shutil.copytree('/usr/lib/gcc-cross/arm-linux-gnueabihf/6', 38cb93a386Sopenharmony_ci os.path.join(target_dir, 'gcc-cross')) 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci # Libs needed to link: 41cb93a386Sopenharmony_ci shutil.copy('/usr/lib/x86_64-linux-gnu/libbfd-2.28-armhf.so', 42cb93a386Sopenharmony_ci os.path.join(target_dir, 'lib')) 43cb93a386Sopenharmony_ci shutil.copy('/usr/lib/x86_64-linux-gnu/libopcodes-2.28-armhf.so', 44cb93a386Sopenharmony_ci os.path.join(target_dir, 'lib')) 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci # The file paths in libpthread.so and libc.so start off as absolute file 47cb93a386Sopenharmony_ci # paths (e.g. /usr/arm-linux-gnueabihf/lib/libpthread.so.0), which won't 48cb93a386Sopenharmony_ci # work on the bots. We use fileinput to replace just those lines (which 49cb93a386Sopenharmony_ci # start with GROUP). fileinput redirects stdout, so printing here actually 50cb93a386Sopenharmony_ci # writes to the file. 51cb93a386Sopenharmony_ci bad_libpthread = os.path.join(target_dir, "lib", "libpthread.so") 52cb93a386Sopenharmony_ci for line in fileinput.input(bad_libpthread, inplace=True): 53cb93a386Sopenharmony_ci if line.startswith("GROUP"): 54cb93a386Sopenharmony_ci print("GROUP ( libpthread.so.0 libpthread_nonshared.a )") 55cb93a386Sopenharmony_ci else: 56cb93a386Sopenharmony_ci print(line) 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ci bad_libc = os.path.join(target_dir, "lib", "libc.so") 59cb93a386Sopenharmony_ci for line in fileinput.input(bad_libc, inplace=True): 60cb93a386Sopenharmony_ci if line.startswith("GROUP"): 61cb93a386Sopenharmony_ci print("GROUP ( libc.so.6 libc_nonshared.a " 62cb93a386Sopenharmony_ci "AS_NEEDED ( ld-linux-armhf.so.3 ) )") 63cb93a386Sopenharmony_ci else: 64cb93a386Sopenharmony_ci print(line) 65cb93a386Sopenharmony_ci 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_cidef main(): 68cb93a386Sopenharmony_ci if 'linux' not in sys.platform: 69cb93a386Sopenharmony_ci print('This script only runs on Linux.', file=sys.stderr) 70cb93a386Sopenharmony_ci sys.exit(1) 71cb93a386Sopenharmony_ci parser = argparse.ArgumentParser() 72cb93a386Sopenharmony_ci parser.add_argument('--target_dir', '-t', required=True) 73cb93a386Sopenharmony_ci args = parser.parse_args() 74cb93a386Sopenharmony_ci create_asset(args.target_dir) 75cb93a386Sopenharmony_ci 76cb93a386Sopenharmony_ci 77cb93a386Sopenharmony_ciif __name__ == '__main__': 78cb93a386Sopenharmony_ci main() 79