[elbe-devel] [PATCH v2 3/4] pbuilder: add cross option to pbuilder

Christian Teklenborg chris at linutronix.de
Fri Mar 20 17:41:03 CET 2020


Add a '--cross' option to pbuilder with the 'store_true' action. The option
defaults to False. Make sure that the stored boolean ends up in the
elbeproject. If the 'elbe pbuilder create' command is called without the cross
option and then the 'elbe pbuilder build' command is used with the cross option
it would raise a CommandError because the cross_pbuilderrc does not exist. Thus
catch the Error before it occurs and print a message how to avoid this Error.

Signed-off-by: Christian Teklenborg <chris at linutronix.de>
---
 elbepack/asyncworker.py        | 10 ++++++----
 elbepack/commands/control.py   |  6 ++++++
 elbepack/commands/pbuilder.py  |  6 ++++++
 elbepack/daemons/soap/esoap.py | 12 ++++++------
 elbepack/elbeproject.py        |  8 ++++++++
 elbepack/pbuilderaction.py     | 14 +++++++++++---
 elbepack/projectmanager.py     |  8 ++++----
 elbepack/soapclient.py         | 13 +++++++------
 8 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/elbepack/asyncworker.py b/elbepack/asyncworker.py
index 2d2deeff..451725d9 100644
--- a/elbepack/asyncworker.py
+++ b/elbepack/asyncworker.py
@@ -209,10 +209,11 @@ class BuildJob(AsyncWorkerJob):
             db.reset_busy(self.project.builddir, success)
 
 class PdebuildJob(AsyncWorkerJob):
-    def __init__(self, project, cpuset=-1, profile=""):
+    def __init__(self, project, cpuset=-1, profile="", cross=False):
         AsyncWorkerJob.__init__(self, project)
         self.cpuset=cpuset
         self.profile=profile
+        self.cross=cross
 
     def enqueue(self, queue, db):
         db.set_busy(self.project.builddir,
@@ -225,7 +226,7 @@ class PdebuildJob(AsyncWorkerJob):
         success = self.build_failed
         try:
             logging.info("Pdebuild started")
-            self.project.pdebuild(self.cpuset, self.profile)
+            self.project.pdebuild(self.cpuset, self.profile, self.cross)
         except Exception:
             logging.exception("Pdebuild failed")
         else:
@@ -239,8 +240,9 @@ class PdebuildJob(AsyncWorkerJob):
             db.reset_busy(self.project.builddir, success)
 
 class CreatePbuilderJob(AsyncWorkerJob):
-    def __init__(self, project):
+    def __init__(self, project, cross=False):
         AsyncWorkerJob.__init__(self, project)
+        self.cross = cross
 
     def enqueue(self, queue, db):
         db.set_busy(self.project.builddir,
@@ -253,7 +255,7 @@ class CreatePbuilderJob(AsyncWorkerJob):
         success = self.build_failed
         try:
             logging.info("Building pbuilder started")
-            self.project.create_pbuilder()
+            self.project.create_pbuilder(self.cross)
         except Exception:
             logging.exception("Pbuilder failed")
         else:
diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index 442df289..24b39269 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -86,6 +86,12 @@ def run_command(argv):
     oparser.add_option("--profile", dest="profile", default="",
                        help="Make pbuilder commands build the specified profile")
 
+    oparser.add_option("--cross", dest="cross", default=False,
+                       action="store_true",
+                       help="Creates an environment for crossbuilding if "
+                            "combined with create. Combined with build it"
+                            " will use this environment.")
+
     devel = OptionGroup(
         oparser,
         "options for elbe developers",
diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index 2e5f55d9..91844e62 100644
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -46,6 +46,12 @@ def run_command(argv):
     oparser.add_option("--profile", dest="profile", default="",
                        help="profile that shall be built")
 
+    oparser.add_option("--cross", dest="cross", default=False,
+                       action="store_true",
+                       help="Creates an environment for crossbuilding if "
+                            "combined with create. Combined with build it"
+                            " will use this environment.")
+
     PreprocessWrapper.add_options(oparser)
 
     (opt, args) = oparser.parse_args(argv)
diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
index 7d76d6a3..27e9e93c 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)
+    @rpc(String, Boolean)
     @authenticated_uid
     @soap_faults
-    def build_pbuilder(self, uid, builddir):
+    def build_pbuilder(self, uid, builddir, cross):
         self.app.pm.open_project(uid, builddir)
-        self.app.pm.build_pbuilder(uid)
+        self.app.pm.build_pbuilder(uid, cross)
 
     @rpc(String)
     @authenticated_uid
@@ -301,12 +301,12 @@ class ESoap (ServiceBase):
         fp.write(binascii.a2b_base64(data))
         fp.close()
 
-    @rpc(String, Integer, String)
+    @rpc(String, Integer, String, Boolean)
     @authenticated_uid
     @soap_faults
-    def finish_pdebuild(self, uid, builddir, cpuset, profile):
+    def finish_pdebuild(self, uid, builddir, cpuset, profile, cross):
         self.app.pm.open_project(uid, builddir)
-        self.app.pm.build_current_pdebuild(uid, cpuset, profile)
+        self.app.pm.build_current_pdebuild(uid, cpuset, profile, cross)
 
     @rpc(String, String)
     @authenticated_uid
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 3c860fba..c2e8d8ba 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -12,6 +12,7 @@ import os
 import datetime
 import io
 import logging
+import sys
 
 from elbepack.shellhelper import CommandError, system, do, chroot
 
@@ -659,6 +660,13 @@ class ElbeProject (object):
                                           "pbuilder", "result"))
 
     def pdebuild(self, cpuset, profile, cross):
+        cross_pbuilderrc = os.path.join(self.builddir, "cross_pbuilderrc")
+        if cross and not os.path.exists(cross_pbuilderrc):
+            logging.error("Please make sure that you create the pbuilder environment "
+                          "with the --cross option if you want to use the build "
+                          "command with --cross.")
+            sys.exit(20)
+
         self.pdebuild_init()
 
         pbdir = os.path.join(self.builddir, "pdebuilder", "current")
diff --git a/elbepack/pbuilderaction.py b/elbepack/pbuilderaction.py
index 1a567a33..ca7b9aa3 100644
--- a/elbepack/pbuilderaction.py
+++ b/elbepack/pbuilderaction.py
@@ -67,6 +67,9 @@ class CreateAction(PBuilderAction):
         PBuilderAction.__init__(self, node)
 
     def execute(self, opt, _args):
+        crossopt = ""
+        if opt.cross:
+            crossopt = "--cross"
 
         if opt.xmlfile:
             try:
@@ -111,7 +114,9 @@ class CreateAction(PBuilderAction):
         print("Creating pbuilder")
 
         try:
-            system('%s control build_pbuilder "%s"' % (elbe_exe, prjdir))
+            system('%s control build_pbuilder "%s" "%s"' % (elbe_exe,
+                                                            prjdir,
+                                                            crossopt))
         except CommandError:
             print("elbe control build_pbuilder Failed", file=sys.stderr)
             print("Giving up", file=sys.stderr)
@@ -176,6 +181,9 @@ class BuildAction(PBuilderAction):
         # pylint: disable=too-many-statements
         # pylint: disable=too-many-branches
 
+        crossopt = ""
+        if opt.cross:
+            crossopt = "--cross"
         tmp = TmpdirFilesystem()
 
         if opt.xmlfile:
@@ -244,9 +252,9 @@ class BuildAction(PBuilderAction):
         print("")
 
         try:
-            system('%s control set_pdebuild --cpuset "%d" --profile "%s" '
+            system('%s control set_pdebuild --cpuset "%d" --profile "%s" "%s" '
                    '"%s" "%s"' %
-                   (elbe_exe, opt.cpuset, opt.profile,
+                   (elbe_exe, opt.cpuset, opt.profile, crossopt,
                     prjdir, tmp.fname("pdebuild.tar.gz")))
         except CommandError:
             print("elbe control set_pdebuild Failed", file=sys.stderr)
diff --git a/elbepack/projectmanager.py b/elbepack/projectmanager.py
index f8ed894f..381475b2 100644
--- a/elbepack/projectmanager.py
+++ b/elbepack/projectmanager.py
@@ -308,19 +308,19 @@ class ProjectManager(object):
             ep = self._get_current_project(userid, allow_busy=False)
             self.worker.enqueue(UpdatePbuilderJob(ep))
 
-    def build_pbuilder(self, userid):
+    def build_pbuilder(self, userid, cross):
         with self.lock:
             ep = self._get_current_project(userid, allow_busy=False)
-            self.worker.enqueue(CreatePbuilderJob(ep))
+            self.worker.enqueue(CreatePbuilderJob(ep, cross))
 
-    def build_current_pdebuild(self, userid, cpuset, profile):
+    def build_current_pdebuild(self, userid, cpuset, profile, cross):
         with self.lock:
             ep = self._get_current_project(userid, allow_busy=False)
             if not path.isdir(path.join(ep.builddir, "pbuilder")):
                 raise InvalidState('No pbuilder exists: run "elbe pbuilder '
                                    'create --project %s" first' % ep.builddir)
 
-            self.worker.enqueue(PdebuildJob(ep, cpuset, profile))
+            self.worker.enqueue(PdebuildJob(ep, cpuset, profile, cross))
 
     def set_orig_fname(self, userid, fname):
         with self.lock:
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 589bdefd..ad971db4 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -722,13 +722,13 @@ class SetPdebuilderAction(ClientAction):
     def execute(self, client, opt, args):
         size = 1024 * 1024
 
-        if len(args) != 2:
+        if len(args) != 2 and len(args) != 3:
             print("usage: elbe control set_pdebuild "
                   "<project_dir> <pdebuild file>", file=sys.stderr)
             sys.exit(20)
 
-        builddir = args[0]
-        filename = args[1]
+        builddir = args[-2]
+        filename = args[-1]
 
         fp = open(filename, "r")
         client.service.start_pdebuild(builddir)
@@ -739,7 +739,8 @@ class SetPdebuilderAction(ClientAction):
             if len(bindata) != size:
                 break
 
-        client.service.finish_pdebuild(builddir, opt.cpuset, opt.profile)
+        client.service.finish_pdebuild(builddir, opt.cpuset,
+                                       opt.profile, opt.cross)
 
 
 ClientAction.register(SetPdebuilderAction)
@@ -753,14 +754,14 @@ class BuildPbuilderAction(ClientAction):
         ClientAction.__init__(self, node)
 
     def execute(self, client, _opt, args):
-        if len(args) != 1:
+        if len(args) != 1 and len(args) != 2:
             print(
                 "usage: elbe control build_pbuilder <project_dir>",
                 file=sys.stderr)
             sys.exit(20)
 
         builddir = args[0]
-        client.service.build_pbuilder(builddir)
+        client.service.build_pbuilder(builddir, _opt.cross)
 
 
 ClientAction.register(BuildPbuilderAction)
-- 
2.20.1




More information about the elbe-devel mailing list