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