26 lines · python
1# System modules2import os3import re4 5 6GMODULES_SUPPORT_MAP = {}7GMODULES_HELP_REGEX = re.compile(r"\s-gmodules\s")8 9 10def is_compiler_clang_with_gmodules(compiler_path):11 # Before computing the result, check if we already have it cached.12 if compiler_path in GMODULES_SUPPORT_MAP:13 return GMODULES_SUPPORT_MAP[compiler_path]14 15 def _gmodules_supported_internal():16 compiler = os.path.basename(compiler_path)17 if "clang" not in compiler:18 return False19 else:20 # Check the compiler help for the -gmodules option.21 clang_help = os.popen("%s --help" % compiler_path).read()22 return GMODULES_HELP_REGEX.search(clang_help, re.DOTALL) is not None23 24 GMODULES_SUPPORT_MAP[compiler_path] = _gmodules_supported_internal()25 return GMODULES_SUPPORT_MAP[compiler_path]26