1from __future__ import absolute_import 2from __future__ import print_function 3 4# System modules 5import os 6import re 7 8 9GMODULES_SUPPORT_MAP = {} 10GMODULES_HELP_REGEX = re.compile(r"\s-gmodules\s") 11 12 13def is_compiler_clang_with_gmodules(compiler_path): 14 # Before computing the result, check if we already have it cached. 15 if compiler_path in GMODULES_SUPPORT_MAP: 16 return GMODULES_SUPPORT_MAP[compiler_path] 17 18 def _gmodules_supported_internal(): 19 compiler = os.path.basename(compiler_path) 20 if "clang" not in compiler: 21 return False 22 else: 23 # Check the compiler help for the -gmodules option. 24 clang_help = os.popen("%s --help" % compiler_path).read() 25 return GMODULES_HELP_REGEX.search( 26 clang_help, re.DOTALL) is not None 27 28 GMODULES_SUPPORT_MAP[compiler_path] = _gmodules_supported_internal() 29 return GMODULES_SUPPORT_MAP[compiler_path] 30