xref: /llvm-project/lldb/packages/Python/lldbsuite/support/gmodules.py (revision e634c2f7149392b62e93c1b2b75701a12bc06721)
1# System modules
2import os
3import re
4
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 False
19        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 None
23
24    GMODULES_SUPPORT_MAP[compiler_path] = _gmodules_supported_internal()
25    return GMODULES_SUPPORT_MAP[compiler_path]
26