From 2dd764f8db070a95dd24131f63b2d546de08aa88 Mon Sep 17 00:00:00 2001 From: Ryan Pessa Date: Sat, 16 Apr 2016 23:08:58 -0500 Subject: [PATCH] add ccache support --- recipes/hostpython/__init__.py | 3 ++- recipes/sdl2/__init__.py | 2 ++ toolchain.py | 28 +++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/recipes/hostpython/__init__.py b/recipes/hostpython/__init__.py index b259759..3afb3a4 100644 --- a/recipes/hostpython/__init__.py +++ b/recipes/hostpython/__init__.py @@ -48,7 +48,8 @@ class HostpythonRecipe(Recipe): def build_x86_64(self): sdk_path = sh.xcrun("--sdk", "macosx", "--show-sdk-path").strip() build_env = self.ctx.env.copy() - build_env["CC"] = "clang -Qunused-arguments -fcolor-diagnostics" + ccache = (build_env["CCACHE"] + ' ') if 'CCACHE' in build_env else '' + build_env["CC"] = ccache + "clang -Qunused-arguments -fcolor-diagnostics" build_env["LDFLAGS"] = " ".join([ "-lsqlite3", "-lffi", diff --git a/recipes/sdl2/__init__.py b/recipes/sdl2/__init__.py index bb016d8..f3040c3 100644 --- a/recipes/sdl2/__init__.py +++ b/recipes/sdl2/__init__.py @@ -19,9 +19,11 @@ class LibSDL2Recipe(Recipe): self.set_marker("patched") def build_arch(self, arch): + env = arch.get_env() shprint(sh.xcodebuild, "ONLY_ACTIVE_ARCH=NO", "ARCHS={}".format(arch.arch), + "CC={}".format(env['CC']), "-sdk", arch.sdk, "-project", "Xcode-iOS/SDL/SDL.xcodeproj", "-target", "libSDL", diff --git a/toolchain.py b/toolchain.py index 1b84fa0..b2a3aa7 100755 --- a/toolchain.py +++ b/toolchain.py @@ -122,6 +122,7 @@ class Arch(object): def __init__(self, ctx): super(Arch, self).__init__() self.ctx = ctx + self._ccsh = None def __str__(self): return self.arch @@ -143,7 +144,32 @@ class Arch(object): for d in self.ctx.include_dirs] env = {} - env["CC"] = sh.xcrun("-find", "-sdk", self.sdk, "clang").strip() + ccache = sh.which('ccache').strip() + cc = sh.xcrun("-find", "-sdk", self.sdk, "clang").strip() + if ccache: + use_ccache = environ.get("USE_CCACHE", "1") + if use_ccache != '1': + env["CC"] = cc + else: + if not self._ccsh: + self._ccsh = ccsh = sh.mktemp().strip() + with open(ccsh, 'w') as f: + f.write('#!/bin/sh\n') + f.write(ccache + ' ' + cc + ' "$@"\n') + sh.chmod('+x', ccsh) + else: + ccsh = self._ccsh + env["USE_CCACHE"] = '1' + env["CCACHE"] = ccache + env["CC"] = ccsh + + env.update({k: v for k, v in environ.items() if k.startswith('CCACHE_')}) + env.setdefault('CCACHE_MAXSIZE', '10G') + env.setdefault('CCACHE_HARDLINK', 'true') + env.setdefault('CCACHE_SLOPPINESS', ('file_macro,time_macros,' + 'include_file_mtime,include_file_ctime,file_stat_matches')) + else: + env["CC"] = cc env["AR"] = sh.xcrun("-find", "-sdk", self.sdk, "ar").strip() env["LD"] = sh.xcrun("-find", "-sdk", self.sdk, "ld").strip() env["OTHER_CFLAGS"] = " ".join(include_dirs)