• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2018 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
12import argparse
13import common
14import os
15import shutil
16import subprocess
17import utils
18
19# This is basically all the deps of g++-multilib-mips64el-linux-gnuabi64 that
20# are not already installed on the bots.
21#
22# We could try to also include packages that *are* already installed on the bots
23# as well, but that would be quite a bit, and would probably entail more hacky
24# fixes like below.
25#
26# There is probably a way to generate this list from apt, but it's not as
27# straightforward as it should be.
28PKGS = [
29    'binutils-mips64el-linux-gnuabi64',
30    'cpp-7-mips64el-linux-gnuabi64',
31    'g++-7-mips64el-linux-gnuabi64',
32    'gcc-7-cross-base',
33    'gcc-7-mips64el-linux-gnuabi64',
34    'gcc-7-mips64el-linux-gnuabi64-base',
35    'libatomic1-mips64el-cross',
36    'libc6-dev-mips64el-cross',
37    'libc6-mips64el-cross',
38    'libgcc-7-dev-mips64el-cross',
39    'libgcc1-mips64el-cross',
40    'libgomp1-mips64el-cross',
41    'libmpfr6',  # This is new in buster, so build machines don't have it yet.
42    'libstdc++-7-dev-mips64el-cross',
43    'libstdc++6-mips64el-cross',
44    'linux-libc-dev-mips64el-cross',
45]
46
47def create_asset(target_dir):
48  """Create the asset."""
49  # This is all a bit hacky. Rather than installing to a chroot, we just extract
50  # all the packages to the target dir, then fix things up so that it can be
51  # used in our recipes.
52  with utils.tmp_dir():
53    # Download required Debian packages.
54    subprocess.check_call(['apt-get', 'download'] + PKGS)
55    for f in os.listdir('.'):
56      subprocess.check_call(['dpkg-deb', '--extract', f, target_dir])
57  parent_dir = os.path.join(target_dir, 'usr')
58  # Remove unnecessary files that cause problems with zipping (due to dangling
59  # symlinks).
60  os.remove(os.path.join(parent_dir,
61                         'lib/gcc-cross/mips64el-linux-gnuabi64/7/libcc1.so'))
62  shutil.rmtree(os.path.join(parent_dir, 'share'))
63  # Remove usr/ prefix.
64  for d in os.listdir(parent_dir):
65    os.rename(os.path.join(parent_dir, d), os.path.join(target_dir, d))
66  os.rmdir(parent_dir)
67  # Remove absolute paths in GNU ld scripts.
68  lib_dir = os.path.join(target_dir, 'mips64el-linux-gnuabi64/lib')
69  ld_script_token = 'OUTPUT_FORMAT(elf64-tradlittlemips)'
70  ld_script_files = subprocess.check_output(
71    ['grep', '--recursive', '--files-with-matches',
72     '--binary-files=without-match', '--fixed-strings', ld_script_token,
73     lib_dir]).split()
74  abs_path = '/usr/mips64el-linux-gnuabi64/lib/'
75  for f in ld_script_files:
76    with open(f) as script:
77      contents = script.read()
78    contents = contents.replace(abs_path, '')
79    with open(f, 'w') as script:
80      script.write(contents)
81
82
83def main():
84  parser = argparse.ArgumentParser()
85  parser.add_argument('--target_dir', '-t', required=True)
86  args = parser.parse_args()
87  create_asset(args.target_dir)
88
89
90if __name__ == '__main__':
91  main()
92