| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Copyright 2022 Google LLC |
| 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 |
|
| 12 |
import argparse |
| 13 |
import glob |
| 14 |
import os |
| 15 |
import shutil |
| 16 |
import subprocess |
| 17 |
import sys |
| 18 |
|
| 19 |
FILE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 |
INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir)) |
| 21 |
sys.path.insert(0, INFRA_BOTS_DIR) |
| 22 |
import utils |
| 23 |
|
| 24 |
# https://packages.debian.org/buster/amd64/binutils-x86-64-linux-gnu/download |
| 25 |
# The older version from buster has fewer dynamic library dependencies. |
| 26 |
URL = 'https://ftp.debian.org/debian/pool/main/b/binutils/binutils-x86-64-linux-gnu_2.31.1-16_amd64.deb' |
| 27 |
SHA256 = 'c1da1cffff8a024b5eca0a6795558d9e0ec88fbd24fe059490dc665dc5cac92f' |
| 28 |
|
| 29 |
# https://packages.debian.org/buster/amd64/binutils-x86-64-linux-gnu/filelist |
| 30 |
to_copy = { |
| 31 |
# If we need other files, we can add them to this mapping. |
| 32 |
'x86_64-linux-gnu-strip': 'strip', |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
def create_asset(target_dir): |
| 37 |
with utils.tmp_dir(): |
| 38 |
subprocess.check_call(['wget', '--output-document=binutils.deb', '--quiet', URL]) |
| 39 |
output = subprocess.check_output(['sha256sum', 'binutils.deb'], encoding='utf-8') |
| 40 |
actual_hash = output.split(' ')[0] |
| 41 |
if actual_hash != SHA256: |
| 42 |
raise Exception('SHA256 does not match (%s != %s)' % (actual_hash, SHA256)) |
| 43 |
# A .deb file is just a re-named .ar file... |
| 44 |
subprocess.check_call(['ar', 'x', 'binutils.deb']) |
| 45 |
# with a control.tar.xz and a data.tar.xz in it. The binaries are in the data one. |
| 46 |
subprocess.check_call(['tar', '-xf', 'data.tar.xz']) |
| 47 |
for (orig, copy) in to_copy.items(): |
| 48 |
shutil.copy(os.path.join('usr', 'bin', orig), os.path.join(target_dir, copy)) |
| 49 |
|
| 50 |
|
| 51 |
def main(): |
| 52 |
parser = argparse.ArgumentParser() |
| 53 |
parser.add_argument('--target_dir', '-t', required=True) |
| 54 |
args = parser.parse_args() |
| 55 |
create_asset(args.target_dir) |
| 56 |
|
| 57 |
|
| 58 |
if __name__ == '__main__': |
| 59 |
main() |
| 60 |
|