]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire-builder: Implement the build command
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 09:43:10 +0000 (09:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 09:43:10 +0000 (09:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/build.c [new file with mode: 0644]
src/cli/lib/build.h [new file with mode: 0644]
src/cli/pakfire-builder.c

index 2e0356494d982196b2cef8a55aa92366fdf29dbb..baa60a7946c76dde7f0125b4532ff0d5bacd92ee 100644 (file)
@@ -429,6 +429,8 @@ noinst_LTLIBRARIES += \
        libcli.la
 
 libcli_la_SOURCES = \
+       src/cli/lib/build.c \
+       src/cli/lib/build.h \
        src/cli/lib/check.c \
        src/cli/lib/check.h \
        src/cli/lib/clean.c \
diff --git a/src/cli/lib/build.c b/src/cli/lib/build.c
new file mode 100644 (file)
index 0000000..4ddff0d
--- /dev/null
@@ -0,0 +1,166 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+
+#include "build.h"
+#include "command.h"
+
+#include <pakfire/build.h>
+#include <pakfire/pakfire.h>
+
+struct config {
+       const char* id;
+       const char* target;
+       int flags;
+};
+
+static void help(void) {
+       printf(
+               "%s [OPTIONS...] build [OPTIONS...] MAKEFILE\n\n"
+               "Options:\n"
+               "     --disable-ccache       Disables using ccache\n"
+               "     --disable-snapshot     Do not use the snapshot\n"
+               "     --disable-tests        Do not run tests\n"
+               "     --non-interactive      Run the build non-interactively\n"
+               "     --target               Output all packages to this directory\n"
+               "  -h --help                 Show help\n",
+               program_invocation_short_name
+       );
+
+       exit(0);
+}
+
+static int parse_argv(struct config* config, int argc, char* argv[]) {
+       enum {
+               ARG_DISABLE_CCACHE,
+               ARG_DISABLE_SNAPSHOT,
+               ARG_DISABLE_TESTS,
+               ARG_ID,
+               ARG_NON_INTERACTIVE,
+               ARG_TARGET,
+       };
+
+       static const struct option options[] = {
+               { "disable-ccache",      no_argument,       NULL, ARG_DISABLE_CCACHE },
+               { "disable-snapshot",    no_argument,       NULL, ARG_DISABLE_SNAPSHOT },
+               { "disable-tests",       no_argument,       NULL, ARG_DISABLE_TESTS },
+               { "id",                  required_argument, NULL, ARG_ID },
+               { "non-interactive",     no_argument,       NULL, ARG_NON_INTERACTIVE },
+               { "target",              required_argument, NULL, ARG_TARGET },
+               { "help",                no_argument,       NULL, 'h' },
+               { NULL },
+       };
+       int c;
+
+       for (;;) {
+               c = getopt_long(argc, argv, "h", options, NULL);
+               if (c < 0)
+                       break;
+
+               switch (c) {
+                       case 'h':
+                               help();
+
+                       case ARG_DISABLE_CCACHE:
+                               config->flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
+                               break;
+
+                       case ARG_DISABLE_SNAPSHOT:
+                               config->flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
+                               break;
+
+                       case ARG_DISABLE_TESTS:
+                               config->flags |= PAKFIRE_BUILD_DISABLE_TESTS;
+                               break;
+
+                       case ARG_ID:
+                               config->id = optarg;
+                               break;
+
+                       case ARG_NON_INTERACTIVE:
+                               config->flags &= ~PAKFIRE_BUILD_INTERACTIVE;
+                               break;
+
+                       case ARG_TARGET:
+                               config->target = optarg;
+                               break;
+
+                       case '?':
+                               return -EINVAL;
+
+                       default:
+                               break;
+               }
+       }
+
+       return 0;
+}
+
+int cli_build(struct pakfire* pakfire, int argc, char* argv[]) {
+       struct pakfire_build* build = NULL;
+       struct config config = {
+               .id     = NULL,
+               .target = NULL,
+               .flags  = PAKFIRE_BUILD_INTERACTIVE,
+       };
+       int r;
+
+       // Parse commandline
+       r = parse_argv(&config, argc, argv);
+       if (r)
+               return r;
+
+       // Setup the build environment
+       r = pakfire_build_create(&build, pakfire, config.id, config.flags);
+       if (r) {
+               fprintf(stderr, "Could not setup the build environment: %m\n");
+               goto ERROR;
+       }
+
+       // Set target
+       if (config.target) {
+               r = pakfire_build_set_target(build, config.target);
+               if (r) {
+                       fprintf(stderr, "Could not set target directory %s: %m\n", config.target);
+                       goto ERROR;
+               }
+       }
+
+       // Process all packages
+       for (int i = optind; i < argc; i++) {
+               // XXX implement dist
+
+               // Run the build
+               r = pakfire_build_exec(build, argv[i]);
+               if (r) {
+                       fprintf(stderr, "Could not build %s\n", argv[i]);
+                       goto ERROR;
+               }
+       }
+
+ERROR:
+       if (build)
+               pakfire_build_unref(build);
+
+       return r;
+}
diff --git a/src/cli/lib/build.h b/src/cli/lib/build.h
new file mode 100644 (file)
index 0000000..8e12208
--- /dev/null
@@ -0,0 +1,28 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_CLI_BUILD_H
+#define PAKFIRE_CLI_BUILD_H
+
+#include <pakfire/pakfire.h>
+
+int cli_build(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_BUILD_H */
index fa57051dd5c9ecb78ada407707e78329caeaaa98..86fc4f50368a801bfb5a5ce006e82aa643675256 100644 (file)
@@ -28,6 +28,7 @@
 #include <pakfire/pakfire.h>
 #include <pakfire/string.h>
 
+#include "lib/build.h"
 #include "lib/clean.h"
 #include "lib/command.h"
 #include "lib/dist.h"
@@ -56,6 +57,7 @@ struct config {
 
 static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) {
        static const struct command commands[] = {
+               { "build",    0, cli_build },
                { "clean",    0, cli_clean },
                { "dist",     0, cli_dist },
                { "info",     0, cli_info },