blob: 238a1d91fcbca6e19ff4014ccd04f9bb4163123a [file] [log] [blame]
Haibo Huang993a2a52020-08-12 15:27:30 -07001#!/usr/bin/env python3
Yi Konga8e8ffb2019-05-20 16:37:24 -07002#
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
21import argparse
22import inspect
Pirama Arumuga Nainar5529b422020-10-07 13:49:09 -070023import logging
Yi Konga8e8ffb2019-05-20 16:37:24 -070024import os
Pirama Arumuga Nainar5529b422020-10-07 13:49:09 -070025import paths
Yi Konga8e8ffb2019-05-20 16:37:24 -070026import subprocess
27import sys
28import utils
29
30class 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 Nainar5529b422020-10-07 13:49:09 -070048def update_binutils_symlink(prebuilt_dir, version):
49 binutils_dir = os.path.join(prebuilt_dir, 'llvm-binutils-stable')
50 binutils = os.listdir(binutils_dir)
Yi Konga8e8ffb2019-05-20 16:37:24 -070051
52 for b in binutils:
Pirama Arumuga Nainar5529b422020-10-07 13:49:09 -070053 symlink_path = os.path.join(binutils_dir, b)
Yi Konga8e8ffb2019-05-20 16:37:24 -070054 util_rela_path = os.path.join('..', 'clang-' + version, 'bin', b)
Pirama Arumuga Nainara67e11b2021-04-20 13:52:06 -070055 if os.path.islink(symlink_path):
Yi Konga8e8ffb2019-05-20 16:37:24 -070056 os.remove(symlink_path)
57 os.symlink(util_rela_path, symlink_path)
58
Pirama Arumuga Nainara67e11b2021-04-20 13:52:06 -070059 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 Konga8e8ffb2019-05-20 16:37:24 -070063
64def 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
81def main():
Pirama Arumuga Nainar426eb2a2020-10-28 16:13:47 -070082 logging.basicConfig(level=logging.DEBUG)
Yi Konga8e8ffb2019-05-20 16:37:24 -070083 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 Nainar5529b422020-10-07 13:49:09 -070091 prebuilt_dir = paths.PREBUILTS_DIR / 'clang' / 'host' / host
92 update_binutils_symlink(prebuilt_dir, version)
Yi Konga8e8ffb2019-05-20 16:37:24 -070093 do_commit(prebuilt_dir, use_cbr, version, bug_id)
94
95 return 0
96
97
98if __name__ == '__main__':
99 main()