|
5 | 5 |
|
6 | 6 | from ..mesonlib import ( |
7 | 7 | MesonException, EnvironmentException, MachineChoice, join_args, |
8 | | - search_version, is_windows, Popen_safe, Popen_safe_logged, windows_proof_rm, |
| 8 | + search_version, is_windows, Popen_safe, Popen_safe_logged, version_compare, windows_proof_rm, |
9 | 9 | ) |
| 10 | +from ..programs import ExternalProgram |
10 | 11 | from ..envconfig import BinaryTable |
11 | 12 | from .. import mlog |
12 | 13 |
|
@@ -118,7 +119,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic |
118 | 119 | # ======= |
119 | 120 |
|
120 | 121 | def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice, |
121 | | - allow_build_machine: bool = False) -> T.Tuple[T.List[T.List[str]], T.List[str]]: |
| 122 | + allow_build_machine: bool = False) -> T.Tuple[T.List[T.List[str]], T.Union[None, ExternalProgram]]: |
122 | 123 | ''' |
123 | 124 | The list of compilers is detected in the exact same way for |
124 | 125 | C, C++, ObjC, ObjC++, Fortran, CS so consolidate it here. |
@@ -269,7 +270,8 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin |
269 | 270 | from . import c, cpp |
270 | 271 | from ..linkers import linkers |
271 | 272 | popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {} |
272 | | - compilers, ccache = _get_compilers(env, lang, for_machine) |
| 273 | + compilers, ccache_exe = _get_compilers(env, lang, for_machine) |
| 274 | + ccache = ccache_exe.get_command() if (ccache_exe and ccache_exe.found()) else [] |
273 | 275 | if override_compiler is not None: |
274 | 276 | compilers = [override_compiler] |
275 | 277 | is_cross = env.is_cross_build(for_machine) |
@@ -516,9 +518,10 @@ def sanitize(p: T.Optional[str]) -> T.Optional[str]: |
516 | 518 | raise EnvironmentException(m) |
517 | 519 | cls = c.VisualStudioCCompiler if lang == 'c' else cpp.VisualStudioCPPCompiler |
518 | 520 | linker = guess_win_linker(env, ['link'], cls, version, for_machine) |
519 | | - # As of this writing, CCache does not support MSVC but sccache does. |
520 | | - if 'sccache' not in ccache: |
521 | | - ccache = [] |
| 521 | + if ccache_exe and ccache_exe.found(): |
| 522 | + if ccache_exe.get_name() == 'ccache' and version_compare(ccache_exe.get_version(), '< 4.6'): |
| 523 | + mlog.warning('Visual Studio support requires ccache 4.6 or higher. You have ccache {}. '.format(ccache_exe.get_version()), once=True) |
| 524 | + ccache = [] |
522 | 525 | return cls( |
523 | 526 | ccache, compiler, version, for_machine, is_cross, info, target, |
524 | 527 | full_version=cl_signature, linker=linker) |
@@ -641,7 +644,8 @@ def detect_cuda_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp |
641 | 644 | from ..linkers.linkers import CudaLinker |
642 | 645 | popen_exceptions = {} |
643 | 646 | is_cross = env.is_cross_build(for_machine) |
644 | | - compilers, ccache = _get_compilers(env, 'cuda', for_machine) |
| 647 | + compilers, ccache_exe = _get_compilers(env, 'cuda', for_machine) |
| 648 | + ccache = ccache_exe.get_command() if (ccache_exe and ccache_exe.found()) else [] |
645 | 649 | info = env.machines[for_machine] |
646 | 650 | for compiler in compilers: |
647 | 651 | arg = '--version' |
@@ -876,7 +880,8 @@ def detect_objcpp_compiler(env: 'Environment', for_machine: MachineChoice) -> 'C |
876 | 880 | def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine: MachineChoice) -> 'Compiler': |
877 | 881 | from . import objc, objcpp |
878 | 882 | popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {} |
879 | | - compilers, ccache = _get_compilers(env, lang, for_machine) |
| 883 | + compilers, ccache_exe = _get_compilers(env, lang, for_machine) |
| 884 | + ccache = ccache_exe.get_command() if (ccache_exe and ccache_exe.found()) else [] |
880 | 885 | is_cross = env.is_cross_build(for_machine) |
881 | 886 | info = env.machines[for_machine] |
882 | 887 | comp: T.Union[T.Type[objc.ObjCCompiler], T.Type[objcpp.ObjCPPCompiler]] |
|
0 commit comments