xref: /aosp_15_r20/external/toolchain-utils/llvm_tools/copy_helpers_to_chromiumos_overlay.py (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1#!/usr/bin/env python3
2# Copyright 2019 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Clones helper scripts into chromiumos-overlay.
7
8Some files in here also need to live in chromiumos-overlay (e.g., the
9patch_manager ones). This script simplifies the copying of those around.
10"""
11
12# Necessary until crbug.com/1006448 is fixed
13
14import argparse
15import os
16import shutil
17import sys
18
19
20def _find_repo_root(script_root):
21    repo_root = os.path.abspath(os.path.join(script_root, "../../../../"))
22    if not os.path.isdir(os.path.join(repo_root, ".repo")):
23        return None
24    return repo_root
25
26
27def main():
28    parser = argparse.ArgumentParser(description=__doc__)
29    parser.add_argument(
30        "--chromeos_path",
31        help="Path to where CrOS' source tree lives. Will autodetect if you're "
32        "running this from inside the CrOS source tree.",
33    )
34    args = parser.parse_args()
35
36    my_dir = os.path.abspath(os.path.dirname(__file__))
37
38    repo_root = args.chromeos_path
39    if repo_root is None:
40        repo_root = _find_repo_root(my_dir)
41        if repo_root is None:
42            sys.exit(
43                "Couldn't detect the CrOS checkout root; please provide a "
44                "value for --chromeos_path"
45            )
46
47    chromiumos_overlay = os.path.join(
48        repo_root, "src/third_party/chromiumos-overlay"
49    )
50
51    clone_files = [
52        "failure_modes.py",
53        "get_llvm_hash.py",
54        "git_llvm_rev.py",
55        "patch_manager.py",
56        "subprocess_helpers.py",
57    ]
58
59    filesdir = os.path.join(
60        chromiumos_overlay, "sys-devel/llvm/files/patch_manager"
61    )
62    for f in clone_files:
63        source = os.path.join(my_dir, f)
64        dest = os.path.join(filesdir, f)
65        print("%r => %r" % (source, dest))
66        shutil.copyfile(source, dest)
67
68
69if __name__ == "__main__":
70    main()
71