Christopher Ferris | cce6d65 | 2021-08-27 11:54:19 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Pirama Arumuga Nainar | 2558ce3 | 2021-06-24 15:59:38 -0700 | [diff] [blame] | 2 | # |
| 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 | |
| 18 | import os |
| 19 | import re |
| 20 | import sys |
| 21 | |
| 22 | |
| 23 | ANDROID_BUILD_TOP = os.environ.get("ANDROID_BUILD_TOP", ".") |
Peter Collingbourne | cbfbd64 | 2021-09-08 13:46:01 -0700 | [diff] [blame] | 24 | LLVM_PREBUILTS_VERSION = os.environ.get("LLVM_PREBUILTS_VERSION") |
Pirama Arumuga Nainar | 2558ce3 | 2021-06-24 15:59:38 -0700 | [diff] [blame] | 25 | |
| 26 | def get_clang_prebuilts_version(global_go): |
Peter Collingbourne | cbfbd64 | 2021-09-08 13:46:01 -0700 | [diff] [blame] | 27 | if LLVM_PREBUILTS_VERSION: |
| 28 | return LLVM_PREBUILTS_VERSION |
| 29 | |
Pirama Arumuga Nainar | 2558ce3 | 2021-06-24 15:59:38 -0700 | [diff] [blame] | 30 | # TODO(b/187231324): Get clang version from the json file once it is no longer |
| 31 | # hard-coded in global.go |
| 32 | if global_go is None: |
| 33 | global_go = ANDROID_BUILD_TOP + '/build/soong/cc/config/global.go' |
| 34 | with open(global_go) as infile: |
| 35 | contents = infile.read() |
| 36 | |
Pirama Arumuga Nainar | 811a1ae | 2021-10-06 09:42:35 -0700 | [diff] [blame] | 37 | regex_rev = r'\tClangDefaultVersion\s+= "(?P<rev>clang-.*)"' |
Pirama Arumuga Nainar | 2558ce3 | 2021-06-24 15:59:38 -0700 | [diff] [blame] | 38 | match_rev = re.search(regex_rev, contents) |
| 39 | if match_rev is None: |
| 40 | raise RuntimeError('Parsing clang info failed') |
| 41 | return match_rev.group('rev') |
| 42 | |
| 43 | |
| 44 | def main(): |
| 45 | global_go = sys.argv[1] if len(sys.argv) > 1 else None |
| 46 | print(get_clang_prebuilts_version(global_go)); |
| 47 | |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | main() |