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