aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2021-10-22 16:59:34 +0300
committerXavier Claessens <xclaesse@gmail.com>2021-10-25 19:59:49 -0400
commit4840c86ec94b0d34a443d38ac771f1e7fe000c59 (patch)
treebeb52df91153e8b67557ab30ba2fc93187bb1298
parentabaa980436f53100041bd5535589bb1c42019bd6 (diff)
downloadmeson-4840c86ec94b0d34a443d38ac771f1e7fe000c59.zip
meson-4840c86ec94b0d34a443d38ac771f1e7fe000c59.tar.gz
meson-4840c86ec94b0d34a443d38ac771f1e7fe000c59.tar.bz2
Add sccache support.
-rw-r--r--docs/markdown/snippets/sccache.md5
-rw-r--r--mesonbuild/compilers/detect.py9
-rw-r--r--mesonbuild/envconfig.py19
3 files changed, 31 insertions, 2 deletions
diff --git a/docs/markdown/snippets/sccache.md b/docs/markdown/snippets/sccache.md
new file mode 100644
index 0000000..72bdf5f
--- /dev/null
+++ b/docs/markdown/snippets/sccache.md
@@ -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.
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 5e0710b..272f5e4 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -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
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
index 307aac3..2af45bf 100644
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.py
@@ -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'