blob: c3bd83d55dc3e154c869906c40d4fdcd752fa1b0 [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)
55 if os.path.exists(symlink_path):
56 os.remove(symlink_path)
57 os.symlink(util_rela_path, symlink_path)
58
59
60def do_commit(prebuilt_dir, use_cbr, version, bug_id):
61 if not use_cbr:
62 subprocess.call(['repo', 'abandon', 'update-binutils-' + version, prebuilt_dir])
63 subprocess.check_call(['repo', 'start', 'update-binutils-' + version, prebuilt_dir])
64
65 subprocess.check_call(['git', 'add', '.'], cwd=prebuilt_dir)
66
67 message_lines = []
68 message_lines.append('Update LLVM binutils to {}.'.format(version))
69 message_lines.append('')
70 message_lines.append('Test: N/A')
71 if bug_id is not None:
72 message_lines.append('Bug: http://b/{}'.format(bug_id))
73 message = '\n'.join(message_lines)
74 subprocess.check_call(['git', 'commit', '-m', message], cwd=prebuilt_dir)
75
76
77def main():
Pirama Arumuga Nainar5529b422020-10-07 13:49:09 -070078 logging.basicConfig(level=logging.INFO)
Yi Konga8e8ffb2019-05-20 16:37:24 -070079 args = ArgParser().parse_args()
80 bug_id = args.bug
81 use_cbr = args.use_current_branch
82 version = args.version
83
84 hosts = ['darwin-x86', 'linux-x86']
85
86 for host in hosts:
Pirama Arumuga Nainar5529b422020-10-07 13:49:09 -070087 prebuilt_dir = paths.PREBUILTS_DIR / 'clang' / 'host' / host
88 update_binutils_symlink(prebuilt_dir, version)
Yi Konga8e8ffb2019-05-20 16:37:24 -070089 do_commit(prebuilt_dir, use_cbr, version, bug_id)
90
91 return 0
92
93
94if __name__ == '__main__':
95 main()