| 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 a Clang toolchain for Linux hosts.""" |
| 10 |
|
| 11 |
|
| 12 |
import argparse |
| 13 |
import os |
| 14 |
import subprocess |
| 15 |
|
| 16 |
|
| 17 |
def create_asset(target_dir): |
| 18 |
# Create a local docker image tagged "clang_ubuntu_noble_asset" with a] |
| 19 |
# compiled clang for amd64 Ubuntu Noble. |
| 20 |
# This will take a while. Output is in the image under /tmp/clang_output |
| 21 |
args = ['docker', 'build', '-t', 'clang_ubuntu_noble_asset', './infra/bots/assets/clang_ubuntu_noble'] |
| 22 |
subprocess.run(args, check=True, encoding='utf8') |
| 23 |
|
| 24 |
# Copy the assets out of the container by mounting target_dir |
| 25 |
print('Copying clang from Docker container into CIPD folder') |
| 26 |
os.makedirs(target_dir, exist_ok=True) |
| 27 |
args = ['docker', 'run', '--mount', 'type=bind,source=%s,target=/OUT' % target_dir, |
| 28 |
'clang_ubuntu_noble_asset', '/bin/sh', '-c', |
| 29 |
# After copying, we need to make the files write-able by all users. |
| 30 |
# Docker makes them owned by root by default, and without everyone being |
| 31 |
# able to write (e.g. delete) them, this can cause issues. |
| 32 |
'cp -R /tmp/clang_output/* /OUT && chmod -R a+w /OUT'] |
| 33 |
subprocess.run(args, check=True, encoding='utf8') |
| 34 |
|
| 35 |
|
| 36 |
def main(): |
| 37 |
parser = argparse.ArgumentParser() |
| 38 |
parser.add_argument('--target_dir', '-t', required=True) |
| 39 |
args = parser.parse_args() |
| 40 |
create_asset(args.target_dir) |
| 41 |
|
| 42 |
|
| 43 |
if __name__ == '__main__': |
| 44 |
main() |