[elbe-devel] [PATCH v3 2/4] pbuilder: create ccache dir in pbuilder environment

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


Make sure that the noccache and ccachesize parameters end up in the right
place. Create a ccache dir in the elbe pbuilder environment and write the
ccache.conf in there.

Signed-off-by: Christian Teklenborg <chris at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/asyncworker.py        |  7 +++++--
 elbepack/daemons/soap/esoap.py |  6 +++---
 elbepack/elbeproject.py        | 14 +++++++++++---
 elbepack/pbuilderaction.py     | 13 +++++++++----
 elbepack/projectmanager.py     |  5 +++--
 elbepack/soapclient.py         |  5 +++--
 6 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/elbepack/asyncworker.py b/elbepack/asyncworker.py
index cb75baaa..b342de13 100644
--- a/elbepack/asyncworker.py
+++ b/elbepack/asyncworker.py
@@ -250,9 +250,11 @@ class PdebuildJob(AsyncWorkerJob):
             db.reset_busy(self.project.builddir, success)
 
 class CreatePbuilderJob(AsyncWorkerJob):
-    def __init__(self, project, cross=False):
+    def __init__(self, project, ccachesize, cross=False, noccache=False):
         AsyncWorkerJob.__init__(self, project)
         self.cross = cross
+        self.noccache = noccache
+        self.ccachesize = ccachesize
 
     def enqueue(self, queue, db):
         db.set_busy(self.project.builddir,
@@ -265,7 +267,8 @@ class CreatePbuilderJob(AsyncWorkerJob):
         success = self.build_failed
         try:
             logging.info("Building pbuilder started")
-            self.project.create_pbuilder(self.cross)
+            self.project.create_pbuilder(self.cross, self.noccache,
+                                         self.ccachesize)
         # pylint: disable=broad-except
         except Exception:
             logging.exception("Pbuilder failed")
diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
index 25d3be76..6a3a224b 100644
--- a/elbepack/daemons/soap/esoap.py
+++ b/elbepack/daemons/soap/esoap.py
@@ -227,12 +227,12 @@ class ESoap (ServiceBase):
         self.app.pm.build_current_project(uid, build_bin, build_src,
                                           skip_pbuilder)
 
-    @rpc(String, Boolean)
+    @rpc(String, Boolean, Boolean, String)
     @authenticated_uid
     @soap_faults
-    def build_pbuilder(self, uid, builddir, cross):
+    def build_pbuilder(self, uid, builddir, cross, noccache, ccachesize):
         self.app.pm.open_project(uid, builddir)
-        self.app.pm.build_pbuilder(uid, cross)
+        self.app.pm.build_pbuilder(uid, cross, noccache, ccachesize)
 
     @rpc(String)
     @authenticated_uid
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 4593dc88..72594283 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -815,7 +815,7 @@ class ElbeProject (object):
            (os.path.join(self.builddir, "pbuilderrc"),
             os.path.join(self.builddir, "aptconfdir")))
 
-    def create_pbuilder(self, cross):
+    def create_pbuilder(self, cross, noccache, ccachesize):
         # Remove old pbuilder directory, if it exists
         do('rm -rf "%s" "%s"' % (os.path.join(self.builddir, "pbuilder"),
                                  os.path.join(self.builddir, "pbuilder_cross")))
@@ -834,14 +834,22 @@ class ElbeProject (object):
         do('mkdir -p "%s"' %
            os.path.join(self.builddir, "aptconfdir", "apt.conf.d"))
 
+        if not noccache:
+            ccache_path = os.path.join(self.builddir, "ccache")
+            do('mkdir -p "%s"' % ccache_path)
+            do('chmod a+w "%s"' % ccache_path)
+            ccache_fp = open(os.path.join(ccache_path, "ccache.conf"), "w")
+            ccache_fp.write("max_size = %s" % ccachesize)
+            ccache_fp.close()
+
         # write config files
         if cross:
-            pbuilder_write_cross_config(self.builddir, self.xml)
+            pbuilder_write_cross_config(self.builddir, self.xml, noccache)
             pbuilder_write_repo_hook(self.builddir, self.xml, cross)
             do('chmod -R 755 "%s"' %
                os.path.join(self.builddir, "pbuilder_cross", "hooks.d"))
         else:
-            pbuilder_write_config(self.builddir, self.xml)
+            pbuilder_write_config(self.builddir, self.xml, noccache)
             pbuilder_write_repo_hook(self.builddir, self.xml, cross)
             do('chmod -R 755 "%s"' %
                os.path.join(self.builddir, "pbuilder", "hooks.d"))
diff --git a/elbepack/pbuilderaction.py b/elbepack/pbuilderaction.py
index 4b38e240..99e431cc 100644
--- a/elbepack/pbuilderaction.py
+++ b/elbepack/pbuilderaction.py
@@ -71,6 +71,12 @@ class CreateAction(PBuilderAction):
         crossopt = ""
         if opt.cross:
             crossopt = "--cross"
+        if opt.noccache:
+            ccacheopt = "--no-ccache"
+            ccachesize = ""
+        else:
+            ccacheopt = "--ccache-size"
+            ccachesize = opt.ccachesize
 
         if opt.xmlfile:
             try:
@@ -115,9 +121,8 @@ class CreateAction(PBuilderAction):
         print("Creating pbuilder")
 
         try:
-            system('%s control build_pbuilder "%s" "%s"' % (elbe_exe,
-                                                            prjdir,
-                                                            crossopt))
+            system('%s control build_pbuilder "%s" %s %s %s' % (
+                    elbe_exe, prjdir, crossopt, ccacheopt, ccachesize))
         except CommandError:
             print("elbe control build_pbuilder Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -253,7 +258,7 @@ class BuildAction(PBuilderAction):
         print("")
 
         try:
-            system('%s control set_pdebuild --cpuset "%d" --profile "%s" "%s" '
+            system('%s control set_pdebuild --cpuset "%d" --profile "%s" %s '
                    '"%s" "%s"' %
                    (elbe_exe, opt.cpuset, opt.profile, crossopt,
                     prjdir, tmp.fname("pdebuild.tar.gz")))
diff --git a/elbepack/projectmanager.py b/elbepack/projectmanager.py
index c03874d5..096b136e 100644
--- a/elbepack/projectmanager.py
+++ b/elbepack/projectmanager.py
@@ -309,10 +309,11 @@ class ProjectManager(object):
             ep = self._get_current_project(userid, allow_busy=False)
             self.worker.enqueue(UpdatePbuilderJob(ep))
 
-    def build_pbuilder(self, userid, cross):
+    def build_pbuilder(self, userid, cross, noccache, ccachesize):
         with self.lock:
             ep = self._get_current_project(userid, allow_busy=False)
-            self.worker.enqueue(CreatePbuilderJob(ep, cross))
+            self.worker.enqueue(CreatePbuilderJob(ep, ccachesize, cross,
+                                                  noccache))
 
     def build_current_pdebuild(self, userid, cpuset, profile, cross):
         with self.lock:
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 8fc0df4a..493e7731 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -757,14 +757,15 @@ class BuildPbuilderAction(ClientAction):
         ClientAction.__init__(self, node)
 
     def execute(self, client, opt, args):
-        if len(args) != 1 and len(args) != 2:
+        if len(args) != 1:
             print(
                 "usage: elbe control build_pbuilder <project_dir>",
                 file=sys.stderr)
             sys.exit(20)
 
         builddir = args[0]
-        client.service.build_pbuilder(builddir, opt.cross)
+        client.service.build_pbuilder(builddir, opt.cross, opt.noccache,
+                                      opt.ccachesize)
 
 
 ClientAction.register(BuildPbuilderAction)
-- 
2.20.1




More information about the elbe-devel mailing list