• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import subprocess
18import sys
19
20
21def main():
22  devnull = open(os.devnull, 'w')
23  for clang in ('clang', 'clang-3.8', 'clang-3.5', 'clang-8'):
24    if subprocess.call(['which', clang], stdout=devnull, stderr=devnull) != 0:
25      continue
26    res = subprocess.check_output([clang, '-print-search-dirs']).decode("utf-8")
27    for line in res.splitlines():
28      if not line.startswith('libraries:'):
29        continue
30      libs = line.split('=', 1)[1].split(':')
31      for lib in libs:
32        if '/clang/' not in lib or not os.path.isdir(lib + '/lib'):
33          continue
34        print(os.path.abspath(lib))
35        print(clang)
36        print(clang.replace('clang', 'clang++'))
37        return 0
38  print('Could not find the LLVM lib dir')
39  return 1
40
41
42if __name__ == '__main__':
43  sys.exit(main())
44