]> git.ipfire.org Git - pakfire.git/commitdiff
builder: Allow building multiple packages one after the other
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 10:55:57 +0000 (10:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 10:55:57 +0000 (10:55 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/pakfire-builder.in

index 08a5d9806919afe4e1a30ed3940c9a2e66a36986..b3d4d4960a67937f9691a3feb2c1326f92170914 100644 (file)
@@ -48,7 +48,7 @@ class Cli(object):
 
                # build
                build = subparsers.add_parser("build", help=_("Build one or more packages"))
-               build.add_argument("package", nargs=1,
+               build.add_argument("package", nargs="+",
                        help=_("Give name of at least one package to build"))
                build.set_defaults(func=self._build)
                build.add_argument("--id", type=uuid.UUID, dest="build_id",
@@ -179,31 +179,29 @@ class Cli(object):
 
        def _build(self, ns):
                """
-                       Builds a package
+                       Builds one or more packages
                """
-               package, = ns.package
+               # Initialise a builder instance and build these packages
+               p = self.pakfire(ns)
 
                # Create a temporary directory if we need to call dist
-               tmp = tempfile.TemporaryDirectory(prefix="pakfire-builder-")
+               with tempfile.TemporaryDirectory(prefix="pakfire-builder-") as tmp:
+                       packages = []
 
-               try:
-                       # Initialise a builder instance and build this package
-                       p = self.pakfire(ns)
+                       # Run dist on packages where necessary
+                       for path in ns.package:
+                               if path.endswith(".nm"):
+                                       path = p.dist(path, tmp)
 
-                       # Package any makefiles
-                       if package.endswith(".nm"):
-                               package = p.dist(package, tmp.name)
+                               packages.append(path)
 
                        # Run build
-                       p.build(
-                               package,
-                               build_id="%s" % ns.build_id if ns.build_id else None,
-                               disable_snapshot=ns.disable_snapshot,
-                       )
-
-               # Cleanup the temporary directory
-               finally:
-                       tmp.cleanup()
+                       for package in packages:
+                               p.build(
+                                       package,
+                                       build_id="%s" % ns.build_id if ns.build_id else None,
+                                       disable_snapshot=ns.disable_snapshot,
+                               )
 
        def _dist(self, ns):
                # Get the packages from the command line options