[elbe-devel] [PATCH v3 1/4] pbuilder: add ccache option to pbuilder

Christian Teklenborg chris at linutronix.de
Mon Jun 22 16:22:58 CEST 2020


By creating a pbuilder environment ccache gets installed by default. Therefore
change the pbuilder config file to implement ccache. It can be
deactivated by calling '--no-ccache' when the pbuilder environemt is created.
Also add an option '--ccache-size "size"' where size takes a number followed by
an optional suffix (k, M, G, T) and sets the maximum size of the compiler cache.
Use 0 for no limit.

Signed-off-by: Christian Teklenborg <chris at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/control.py  | 10 ++++++++++
 elbepack/commands/pbuilder.py | 10 ++++++++++
 elbepack/elbeproject.py       |  3 ++-
 elbepack/pbuilder.py          | 18 ++++++++++++++++--
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index 12c6a6d0..dc53825c 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -92,6 +92,16 @@ def run_command(argv):
                             "combined with create. Combined with build it"
                             " will use this environment.")
 
+    oparser.add_option("--no-ccache", dest="noccache", default=False,
+                       action="store_true",
+                       help="Deactivates the compiler cache 'ccache'")
+
+    oparser.add_option("--ccache-size", dest="ccachesize", default="10G",
+                       action="store", type="string",
+                       help="set a limit for the compiler cache size "
+                            "(should be a number followed by an optional "
+                            "suffix: k, M, G, T. Use 0 for no limit.)")
+
     devel = OptionGroup(
         oparser,
         "options for elbe developers",
diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index 91844e62..3e7dc578 100644
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -52,6 +52,16 @@ def run_command(argv):
                             "combined with create. Combined with build it"
                             " will use this environment.")
 
+    oparser.add_option("--no-ccache", dest="noccache", default=False,
+                       action="store_true",
+                       help="Deactivates the compiler cache 'ccache'")
+
+    oparser.add_option("--ccache-size", dest="ccachesize", default="10G",
+                       action="store", type="string",
+                       help="set a limit for the compiler cache size "
+                            "(should be a number followed by an optional "
+                            "suffix: k, M, G, T. Use 0 for no limit.)")
+
     PreprocessWrapper.add_options(oparser)
 
     (opt, args) = oparser.parse_args(argv)
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 1b466a02..4593dc88 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -570,7 +570,8 @@ class ElbeProject (object):
 
         if self.xml.has('target/pbuilder') and not skip_pbuild:
             if not os.path.exists(os.path.join(self.builddir, "pbuilder")):
-                self.create_pbuilder(cross=False)
+                self.create_pbuilder(cross=False, noccache=False,
+                                     ccachesize="10G")
             for p in self.xml.node('target/pbuilder'):
                 self.pbuild(p)
                 # the package might be needed by a following pbuild, so update
diff --git a/elbepack/pbuilder.py b/elbepack/pbuilder.py
index 6f266a93..fe90f3d1 100644
--- a/elbepack/pbuilder.py
+++ b/elbepack/pbuilder.py
@@ -12,7 +12,7 @@ try:
 except ImportError:
     from urllib2 import urlopen
 
-def pbuilder_write_config(builddir, xml):
+def pbuilder_write_config(builddir, xml, noccache):
     distname = xml.prj.text('suite')
     pbuilderrc_fname = os.path.join(builddir, "pbuilderrc")
     fp = open(pbuilderrc_fname, "w")
@@ -60,9 +60,16 @@ def pbuilder_write_config(builddir, xml):
     fp.write('PBUILDERSATISFYDEPENDSCMD='
              '/usr/lib/pbuilder/pbuilder-satisfydepends-experimental\n')
 
+    if not noccache:
+        fp.write('export CCACHE_DIR="%s/ccache"\n' % builddir)
+        fp.write('export PATH="/usr/lib/ccache:${PATH}"\n')
+        fp.write('EXTRAPACKAGES=ccache\n')
+        fp.write('export CCACHE_CONFIGPATH="%s/ccache/ccache.conf"\n' %
+                 builddir)
+        fp.write('BINDMOUNTS="${CCACHE_DIR}"')
     fp.close()
 
-def pbuilder_write_cross_config(builddir, xml):
+def pbuilder_write_cross_config(builddir, xml, noccache):
     distname = xml.prj.text('suite')
     pbuilderrc_fname = os.path.join(builddir, "cross_pbuilderrc")
     fp = open(pbuilderrc_fname, "w")
@@ -83,6 +90,13 @@ def pbuilder_write_cross_config(builddir, xml):
     fp.write('HOOKDIR="%s"\n' % os.path.join(builddir, 'pbuilder_cross', 'hooks.d'))
     fp.write('PBUILDERSATISFYDEPENDSCMD='
              '/usr/lib/pbuilder/pbuilder-satisfydepends-apt\n')
+    if not noccache:
+        fp.write('export CCACHE_DIR="%s/ccache"\n' % builddir)
+        fp.write('export PATH="/usr/lib/ccache:${PATH}"\n')
+        fp.write('EXTRAPACKAGES=ccache\n')
+        fp.write('export CCACHE_CONFIGPATH="%s/ccache/ccache.conf"\n' %
+                 builddir)
+        fp.write('BINDMOUNTS="${CCACHE_DIR}"')
     fp.close()
 
 
-- 
2.20.1




More information about the elbe-devel mailing list