Debian Codegraph @

infra/bots/assets/arm64_sysroot/create.py

raw
1 #!/usr/bin/env python
2 #
3 # Copyright 2025 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
12 from __future__ import print_function
13 import argparse
14 import fileinput
15 import os
16 import shutil
17 import subprocess
18 import sys
19
20
21 def create_asset(target_dir):
22 # Create a local docker image tagged "arm64_sysroot" with a sysroot for
23 # building arm64 targets. Output is in the image under
24 # /tmp/arm64_sysroot_output.
25 args = ['docker', 'build', '-t', 'arm64_sysroot', './infra/bots/assets/arm64_sysroot']
26 subprocess.run(args, check=True, encoding='utf8')
27
28 # Copy the assets out of the container by mounting target_dir
29 print('Copying assets from Docker container into CIPD folder')
30 os.makedirs(target_dir, exist_ok=True)
31 args = ['docker', 'run', '--mount', 'type=bind,source=%s,target=/OUT' % target_dir,
32 'arm64_sysroot', '/bin/sh', '-c',
33 # After copying, we need to make the files write-able by all users.
34 # Docker makes them owned by root by default, and without everyone being
35 # able to write (e.g. delete) them, this can cause issues.
36 'cp -R /tmp/arm64_sysroot_output/* /OUT && chmod -R a+w /OUT']
37 subprocess.run(args, check=True, encoding='utf8')
38
39 def main():
40 if 'linux' not in sys.platform:
41 print('This script only runs on Linux.', file=sys.stderr)
42 sys.exit(1)
43 parser = argparse.ArgumentParser()
44 parser.add_argument('--target_dir', '-t', required=True)
45 args = parser.parse_args()
46 create_asset(args.target_dir)
47
48
49 if __name__ == '__main__':
50 main()