phase1: use wrappers for ccache
authorThibaut VARÈNE <hacks@slashdirt.org>
Fri, 29 Jun 2018 10:39:01 +0000 (12:39 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 25 Sep 2018 13:13:21 +0000 (15:13 +0200)
750174c0cee95925dd322f37c211577d0ebc0dc4 attempted to inject ccache
into the CC environment, but that doesn't work as the CC/CXX variables
are processed by the build system, in order to extract the path to an
executable file.

This commit works around that situation by creating two simple wrapper
scripts on the slave. The remaining logic is unchanged:

When tryccache is False, CC/CXX point to the regular compilers and no
ccache injection is performed.

When tryccache is True, CC/CXX point to their respective wrapper, and
CCACHE is set to the path to ccache (if it exists, empty otherwise),
CCC/CCXX point to the original compilers, and the wrappers will execute
'${CCACHE} ${CCC} "$@"' or '${CCACHE} ${CCXX} "$@"'. If ${CCACHE} is
unset, this falls back to plain compilers.

i.e. ccache is only used if tryccache=True AND ccache has been found on
the slave.

Use 'exec' to avoid lingering shell during execution.

Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
phase1/master.cfg

index 118e8676100d1a9f6421c3d66931b70edb58dd11..0acf210ba69cc3a302486ae9ee54add7ebb05b26 100644 (file)
@@ -208,6 +208,7 @@ from buildbot.steps.shell import ShellCommand
 from buildbot.steps.shell import SetPropertyFromCommand
 from buildbot.steps.transfer import FileUpload
 from buildbot.steps.transfer import FileDownload
+from buildbot.steps.transfer import StringDownload
 from buildbot.steps.master import MasterShellCommand
 from buildbot.process.properties import Interpolate
 from buildbot.process import properties
@@ -320,7 +321,7 @@ def GetCwd(props):
 @properties.renderer
 def GetCCache(props):
        if props.hasProperty("ccache_command") and "ccache" in props["ccache_command"]:
-               return props["ccache_command"] + " "
+               return props["ccache_command"]
        else:
                return ""
 
@@ -332,14 +333,23 @@ def GetNextBuild(builder, requests):
 
 def MakeEnv(overrides=None, tryccache=False):
        if tryccache:
-               envcc = Interpolate("%(kw:ccache)s%(kw:cc)s", ccache=GetCCache, cc=GetCC)
-               envcxx = Interpolate("%(kw:ccache)s%(kw:cxx)s", ccache=GetCCache, cxx=GetCXX)
+               envcc = Interpolate("%(kw:cwd)s/ccache_cc.sh", cwd=GetCwd)
+               envcxx = Interpolate("%(kw:cwd)s/ccache_cxx.sh", cwd=GetCwd)
+               envccache = Interpolate("%(kw:ccache)s", ccache=GetCCache)
+               envccc = Interpolate("%(kw:cc)s", cc=GetCC)
+               envccxx = Interpolate("%(kw:cxx)s", cxx=GetCXX)
        else:
                envcc = Interpolate("%(kw:cc)s", cc=GetCC)
                envcxx = Interpolate("%(kw:cxx)s", cxx=GetCXX)
+               envccache = ""
+               envccc = ""
+               envccxx = ""
        env = {
                'CC': envcc,
                'CXX': envcxx,
+               'CCACHE': envccache,
+               'CCC': envccc,
+               'CCXX': envccxx,
        }
        if overrides is not None:
                env.update(overrides)
@@ -660,6 +670,20 @@ for target in targets:
                want_stdout = False
        ))
 
+       factory.addStep(StringDownload(
+               name = "ccachecc",
+               s = '#!/bin/sh\nexec ${CCACHE} ${CCC} "$@"\n',
+               slavedest = "../ccache_cc.sh",
+               mode = 0755,
+       ))
+
+       factory.addStep(StringDownload(
+               name = "ccachecxx",
+               s = '#!/bin/sh\nexec ${CCACHE} ${CCXX} "$@"\n',
+               slavedest = "../ccache_cxx.sh",
+               mode = 0755,
+       ))
+
        # prepare tar
        factory.addStep(ShellCommand(
                name = "dltar",