blob: 17bc88bbd52a93710ae5afcb92eacbe7c7b39b3e [file] [log] [blame]
Christopher Ferriscce6d652021-08-27 11:54:19 -07001#!/usr/bin/env python3
Pirama Arumuga Nainar2558ce32021-06-24 15:59:38 -07002#
3# Copyright (C) 2021 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"""A tool to report the current clang version used during build"""
17
18import os
19import re
20import sys
21
22
23ANDROID_BUILD_TOP = os.environ.get("ANDROID_BUILD_TOP", ".")
24
25def get_clang_prebuilts_version(global_go):
26 # TODO(b/187231324): Get clang version from the json file once it is no longer
27 # hard-coded in global.go
28 if global_go is None:
29 global_go = ANDROID_BUILD_TOP + '/build/soong/cc/config/global.go'
30 with open(global_go) as infile:
31 contents = infile.read()
32
Pirama Arumuga Nainar238ca382021-07-02 09:21:13 -070033 regex_rev = r'\tClangDefaultVersion\s+= "(?P<rev>clang-r\d+[a-z]?\d?)"'
Pirama Arumuga Nainar2558ce32021-06-24 15:59:38 -070034 match_rev = re.search(regex_rev, contents)
35 if match_rev is None:
36 raise RuntimeError('Parsing clang info failed')
37 return match_rev.group('rev')
38
39
40def main():
41 global_go = sys.argv[1] if len(sys.argv) > 1 else None
42 print(get_clang_prebuilts_version(global_go));
43
44
45if __name__ == '__main__':
46 main()