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 |
| 22 | import inspect |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 23 | import logging |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 24 | import os |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 25 | import paths |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 26 | import subprocess |
| 27 | import sys |
| 28 | import utils |
| 29 | |
| 30 | class ArgParser(argparse.ArgumentParser): |
| 31 | def __init__(self): |
| 32 | super(ArgParser, self).__init__( |
| 33 | description=inspect.getdoc(sys.modules[__name__])) |
| 34 | |
| 35 | self.add_argument( |
| 36 | 'version', metavar='VERSION', |
| 37 | help='Version of binutil prebuilt updating to (e.g. r123456a).') |
| 38 | |
| 39 | self.add_argument( |
| 40 | '-b', '--bug', type=int, |
| 41 | help='Bug to reference in commit message.') |
| 42 | |
| 43 | self.add_argument( |
| 44 | '--use-current-branch', action='store_true', |
| 45 | help='Do not repo start a new branch for the update.') |
| 46 | |
| 47 | |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 48 | def update_binutils_symlink(prebuilt_dir, version): |
| 49 | binutils_dir = os.path.join(prebuilt_dir, 'llvm-binutils-stable') |
| 50 | binutils = os.listdir(binutils_dir) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 51 | |
| 52 | for b in binutils: |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 53 | symlink_path = os.path.join(binutils_dir, b) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 54 | util_rela_path = os.path.join('..', 'clang-' + version, 'bin', b) |
Pirama Arumuga Nainar | a67e11b | 2021-04-20 13:52:06 -0700 | [diff] [blame^] | 55 | if os.path.islink(symlink_path): |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 56 | os.remove(symlink_path) |
| 57 | os.symlink(util_rela_path, symlink_path) |
| 58 | |
Pirama Arumuga Nainar | a67e11b | 2021-04-20 13:52:06 -0700 | [diff] [blame^] | 59 | if not os.path.exists(symlink_path): |
| 60 | # check that the created link is valid |
| 61 | raise RuntimeError(f'Created symlink, {symlink_path}, is broken') |
| 62 | |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 63 | |
| 64 | def do_commit(prebuilt_dir, use_cbr, version, bug_id): |
| 65 | if not use_cbr: |
| 66 | subprocess.call(['repo', 'abandon', 'update-binutils-' + version, prebuilt_dir]) |
| 67 | subprocess.check_call(['repo', 'start', 'update-binutils-' + version, prebuilt_dir]) |
| 68 | |
| 69 | subprocess.check_call(['git', 'add', '.'], cwd=prebuilt_dir) |
| 70 | |
| 71 | message_lines = [] |
| 72 | message_lines.append('Update LLVM binutils to {}.'.format(version)) |
| 73 | message_lines.append('') |
| 74 | message_lines.append('Test: N/A') |
| 75 | if bug_id is not None: |
| 76 | message_lines.append('Bug: http://b/{}'.format(bug_id)) |
| 77 | message = '\n'.join(message_lines) |
| 78 | subprocess.check_call(['git', 'commit', '-m', message], cwd=prebuilt_dir) |
| 79 | |
| 80 | |
| 81 | def main(): |
Pirama Arumuga Nainar | 426eb2a | 2020-10-28 16:13:47 -0700 | [diff] [blame] | 82 | logging.basicConfig(level=logging.DEBUG) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 83 | args = ArgParser().parse_args() |
| 84 | bug_id = args.bug |
| 85 | use_cbr = args.use_current_branch |
| 86 | version = args.version |
| 87 | |
| 88 | hosts = ['darwin-x86', 'linux-x86'] |
| 89 | |
| 90 | for host in hosts: |
Pirama Arumuga Nainar | 5529b42 | 2020-10-07 13:49:09 -0700 | [diff] [blame] | 91 | prebuilt_dir = paths.PREBUILTS_DIR / 'clang' / 'host' / host |
| 92 | update_binutils_symlink(prebuilt_dir, version) |
Yi Kong | a8e8ffb | 2019-05-20 16:37:24 -0700 | [diff] [blame] | 93 | do_commit(prebuilt_dir, use_cbr, version, bug_id) |
| 94 | |
| 95 | return 0 |
| 96 | |
| 97 | |
| 98 | if __name__ == '__main__': |
| 99 | main() |