phase1: opportunistic use of ccache
authorThibaut VARÈNE <hacks@slashdirt.org>
Thu, 21 Jun 2018 19:14:14 +0000 (21:14 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 26 Jun 2018 20:08:51 +0000 (22:08 +0200)
Assuming that CONFIG_CCACHE is disabled in the target config.seed,
this patch tries to enable the use of ccache (if available from the host)
for the 'dltar' and 'tools' steps, which are the only two steps where the
build objects are shared by /all/ workers, and thus the two steps where
caching makes the most sense and should provide the most benefits.

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

index 80955b58bb8e043bdc627b3bbffcb17cf7cf5c3b..b0e6422eef9efee8f872f121f809cba84dbaf43c 100644 (file)
@@ -203,6 +203,7 @@ from buildbot.process.factory import BuildFactory
 from buildbot.steps.source.git import Git
 from buildbot.steps.shell import ShellCommand
 from buildbot.steps.shell import SetProperty
+from buildbot.steps.shell import SetPropertyFromCommand
 from buildbot.steps.transfer import FileUpload
 from buildbot.steps.transfer import FileDownload
 from buildbot.steps.master import MasterShellCommand
@@ -299,17 +300,29 @@ def GetCwd(props):
        else:
                return "/"
 
+def GetCCache(props):
+       if props.hasProperty("ccache_command") and "ccache" in props["ccache_command"]:
+               return props["ccache_command"] + " "
+       else:
+               return ""
+
 def GetNextBuild(builder, requests):
        for r in requests:
                if r.properties and r.properties.hasProperty("tag"):
                        return r
        return requests[0]
 
-def MakeEnv(overrides=None):
+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)
+       else:
+               envcc = Interpolate("%(kw:cc)s", cc=GetCC)
+               envcxx = Interpolate("%(kw:cxx)s", cxx=GetCXX)
        env = {
-               'CC': WithProperties("%(cc)s", cc=GetCC),
-               'CXX': WithProperties("%(cxx)s", cxx=GetCXX),
-               'CCACHE_BASEDIR': WithProperties("%(cwd)s", cwd=GetCwd)
+               'CC': envcc,
+               'CXX': envcxx,
+               'CCACHE_BASEDIR': Interpolate("%(kw:cwd)s", cwd=GetCwd)
        }
        if overrides is not None:
                env.update(overrides)
@@ -430,6 +443,16 @@ for target in targets:
                        command = ["../findbin.pl", "g++", cc_version[0], cc_version[1]],
                        haltOnFailure = True))
 
+       # see if ccache is available
+       factory.addStep(SetPropertyFromCommand(
+               property = "ccache_command",
+               command = ["which", "ccache"],
+               description = "Testing for ccache command",
+               haltOnFailure = False,
+               flunkOnFailure = False,
+               warnOnFailure = False,
+       ))
+
        # expire tree if needed
        if tree_expire > 0:
                factory.addStep(FileDownload(
@@ -623,7 +646,7 @@ for target in targets:
                name = "dltar",
                description = "Building and installing GNU tar",
                command = ["make", WithProperties("-j%(jobs)d", jobs=GetNumJobs), "tools/tar/compile", "V=s"],
-               env = MakeEnv(),
+               env = MakeEnv(tryccache=True),
                haltOnFailure = True
        ))
 
@@ -648,7 +671,7 @@ for target in targets:
                name = "tools",
                description = "Building and installing tools",
                command = ["make", WithProperties("-j%(jobs)d", jobs=GetNumJobs), "tools/install", "V=s"],
-               env = MakeEnv(),
+               env = MakeEnv(tryccache=True),
                haltOnFailure = True
        ))