Add sccache support.

pull/9451/head
Jussi Pakkanen 3 years ago committed by Xavier Claessens
parent abaa980436
commit 4840c86ec9
  1. 5
      docs/markdown/snippets/sccache.md
  2. 9
      mesonbuild/compilers/detect.py
  3. 19
      mesonbuild/envconfig.py

@ -0,0 +1,5 @@
## Added support for sccache
Meson now supports [sccache](https://github.com/mozilla/sccache) just
like it has supported CCache. If both sccache and CCache are
available, the autodetection logic prefers sccache.

@ -236,7 +236,7 @@ def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) ->
if not env.machines.matches_build_machine(for_machine):
raise EnvironmentException(f'{lang!r} compiler binary not defined in cross or native file')
compilers = [[x] for x in defaults[lang]]
ccache = BinaryTable.detect_ccache()
ccache = BinaryTable.detect_compiler_cache()
if env.machines.matches_build_machine(for_machine):
exe_wrap: T.Optional[ExternalProgram] = None
@ -554,8 +554,13 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
raise EnvironmentException(m)
cls = VisualStudioCCompiler if lang == 'c' else VisualStudioCPPCompiler
linker = guess_win_linker(env, ['link'], cls, for_machine)
# As of this writing, CCache does not support MSVC but sccache does.
if 'sccache' in ccache:
final_compiler = ccache + compiler
else:
final_compiler = compiler
return cls(
compiler, version, for_machine, is_cross, info, target,
final_compiler, version, for_machine, is_cross, info, target,
exe_wrap, full_version=cl_signature, linker=linker)
if 'PGI Compilers' in out:
cls = PGICCompiler if lang == 'c' else PGICPPCompiler

@ -385,6 +385,22 @@ class BinaryTable:
return []
return ['ccache']
@staticmethod
def detect_sccache() -> T.List[str]:
try:
subprocess.check_call(['sccache', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except (OSError, subprocess.CalledProcessError):
return []
return ['sccache']
@staticmethod
def detect_compiler_cache() -> T.List[str]:
# Sccache is "newer" so it is assumed that people would prefer it by default.
cache = BinaryTable.detect_sccache()
if cache:
return cache
return BinaryTable.detect_ccache()
@classmethod
def parse_entry(cls, entry: T.Union[str, T.List[str]]) -> T.Tuple[T.List[str], T.List[str]]:
compiler = mesonlib.stringlistify(entry)
@ -392,6 +408,9 @@ class BinaryTable:
if compiler[0] == 'ccache':
compiler = compiler[1:]
ccache = cls.detect_ccache()
elif compiler[0] == 'sccache':
compiler = compiler[1:]
ccache = cls.detect_sccache()
else:
ccache = []
# Return value has to be a list of compiler 'choices'

Loading…
Cancel
Save