Haibo Huang | 993a2a5 | 2020-08-12 15:27:30 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2019 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # pylint: disable=not-callable, relative-import |
| 18 | |
| 19 | """ Update symlinks for binutils """ |
| 20 | |
| 21 | import argparse |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 22 | import logging |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 23 | from pathlib import Path |
| 24 | import shutil |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 25 | import subprocess |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 26 | from typing import Optional |
| 27 | |
Matthew Maurer | 0848aa6 | 2024-09-24 16:28:42 +0000 | [diff] [blame] | 28 | import context |
| 29 | from llvm_android import paths, utils |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 30 | |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 31 | |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 32 | class ArgParser(argparse.ArgumentParser): |
| 33 | def __init__(self): |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 34 | super().__init__(description=__doc__) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 35 | |
| 36 | self.add_argument( |
| 37 | 'version', metavar='VERSION', |
| 38 | help='Version of binutil prebuilt updating to (e.g. r123456a).') |
| 39 | |
| 40 | self.add_argument( |
| 41 | '-b', '--bug', type=int, |
| 42 | help='Bug to reference in commit message.') |
| 43 | |
| 44 | self.add_argument( |
| 45 | '--use-current-branch', action='store_true', |
| 46 | help='Do not repo start a new branch for the update.') |
| 47 | |
| 48 | |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 49 | def update_binutils_symlink(prebuilt_dir: Path, version: str, use_cbr: bool): |
| 50 | if not use_cbr: |
| 51 | utils.unchecked_call(['repo', 'abandon', 'update-binutils-' + version, prebuilt_dir], |
| 52 | stderr=subprocess.DEVNULL) |
| 53 | utils.check_call(['repo', 'start', 'update-binutils-' + version, prebuilt_dir]) |
| 54 | |
| 55 | binutils_dir = prebuilt_dir / 'llvm-binutils-stable' |
| 56 | binutils = [p.name for p in binutils_dir.iterdir()] |
| 57 | shutil.rmtree(binutils_dir) |
| 58 | binutils_dir.mkdir() |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 59 | |
| 60 | for b in binutils: |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 61 | symlink_path = binutils_dir / b |
| 62 | util_rela_path = Path('..') / ('clang-' + version) / 'bin' / b |
| 63 | symlink_path.symlink_to(util_rela_path) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 64 | |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 65 | if not symlink_path.exists(): |
Pirama Arumuga Nainar | a67e11b | 2021-04-20 13:52:06 -0700 | [diff] [blame] | 66 | # check that the created link is valid |
| 67 | raise RuntimeError(f'Created symlink, {symlink_path}, is broken') |
| 68 | |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 69 | |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 70 | def do_commit(prebuilt_dir: Path, version: str, bug_id: Optional[str]): |
| 71 | utils.check_call(['git', 'add', 'llvm-binutils-stable'], cwd=prebuilt_dir) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 72 | |
| 73 | message_lines = [] |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 74 | message_lines.append(f'Update LLVM binutils to {version}.') |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 75 | message_lines.append('') |
| 76 | message_lines.append('Test: N/A') |
| 77 | if bug_id is not None: |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 78 | message_lines.append(f'Bug: http://b/{bug_id}') |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 79 | message = '\n'.join(message_lines) |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 80 | utils.check_call(['git', 'commit', '-m', message], cwd=prebuilt_dir) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 81 | |
| 82 | |
| 83 | def main(): |
Pirama Arumuga Nainar | 426eb2a | 2020-10-28 16:13:47 -0700 | [diff] [blame] | 84 | logging.basicConfig(level=logging.DEBUG) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 85 | args = ArgParser().parse_args() |
| 86 | bug_id = args.bug |
| 87 | use_cbr = args.use_current_branch |
| 88 | version = args.version |
| 89 | |
| 90 | hosts = ['darwin-x86', 'linux-x86'] |
| 91 | |
| 92 | for host in hosts: |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 93 | prebuilt_dir = paths.PREBUILTS_DIR / 'clang' / 'host' / host |
Yabin Cui | 8a7b4df | 2022-12-02 10:26:57 -0800 | [diff] [blame] | 94 | update_binutils_symlink(prebuilt_dir, version, use_cbr) |
| 95 | do_commit(prebuilt_dir, version, bug_id) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 96 | |
| 97 | return 0 |
| 98 | |
| 99 | |
| 100 | if __name__ == '__main__': |
| 101 | main() |