| #!/usr/bin/env python |
| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Minimize Fuchsia clang toochains. |
| Usage: |
| python preprocess_clang.py --src=SRC_PATH --dst=dst_PATH --platforms='linux_amd64, mac_amd64' |
| """ |
| |
| import argparse |
| import os |
| import os.path |
| import sys |
| import shutil |
| |
| |
| def preprocess_clang(src_dir, dst_dir): |
| # remove unnecessary clang libs from toolchain images. |
| bin_root = os.path.join(dst_dir, 'bin') |
| os.makedirs(bin_root) |
| # read link target of 'clang' |
| src_clang = os.path.join(src_dir, 'bin', |
| os.readlink(os.path.join(src_dir, 'bin', 'clang'))) |
| dst_clang = os.path.join(bin_root, os.path.basename(src_clang)) |
| shutil.copy2(src_clang, dst_clang) |
| |
| cwd = os.getcwd() |
| try: |
| os.chdir(bin_root) |
| clang = os.path.basename(src_clang) |
| os.symlink(clang, 'clang') |
| os.symlink(clang, 'clang++') |
| os.symlink(clang, 'clang-cl') |
| finally: |
| os.chdir(cwd) |
| shutil.copytree( |
| os.path.join(src_dir, 'include'), os.path.join(dst_dir, 'include')) |
| shutil.copy2( |
| os.path.join(src_dir, 'LICENSE'), os.path.join(dst_dir, 'LICENSE')) |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument('src', help='source toolchain path') |
| parser.add_argument('dst', help='target toolchain path') |
| parser.add_argument( |
| '--platform', action='append', help='target platform name') |
| args = parser.parse_args() |
| for platform in args.platform: |
| preprocess_clang( |
| os.path.join(args.src, platform), os.path.join(args.dst, platform)) |
| |
| |
| if __name__ == '__main__': |
| sys.exit(main()) |