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

index e94fd4fe04bcddaa991db80a57ac4e2043a2c9a4..2e0356494d982196b2cef8a55aa92366fdf29dbb 100644 (file)
@@ -435,6 +435,8 @@ libcli_la_SOURCES = \
        src/cli/lib/clean.h \
        src/cli/lib/command.c \
        src/cli/lib/command.h \
+       src/cli/lib/dist.c \
+       src/cli/lib/dist.h \
        src/cli/lib/dump.c \
        src/cli/lib/dump.h \
        src/cli/lib/info.c \
diff --git a/src/cli/lib/dist.c b/src/cli/lib/dist.c
new file mode 100644 (file)
index 0000000..876cc64
--- /dev/null
@@ -0,0 +1,100 @@
+/*#############################################################################
+#                                                                             #
+# 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 <limits.h>
+#include <stdlib.h>
+
+#include "command.h"
+#include "dist.h"
+
+#include <pakfire/dist.h>
+#include <pakfire/pakfire.h>
+
+#define MAX_MAKEFILES 128
+
+struct config {
+       const char* resultdir;
+};
+
+static void help(void) {
+       printf(
+               "%s [OPTIONS...] dist MAKEFILES...\n\n"
+               "Options:\n"
+               "  -h --help                 Show help\n",
+               program_invocation_short_name
+       );
+
+       exit(0);
+}
+
+static int parse_argv(int argc, char* argv[]) {
+       static const struct option options[] = {
+               { "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 '?':
+                               return -EINVAL;
+
+                       default:
+                               break;
+               }
+       }
+
+       return 0;
+}
+
+int cli_dist(struct pakfire* pakfire, int argc, char* argv[]) {
+       struct config config = {
+               .resultdir = NULL,
+       };
+       char cwd[PATH_MAX];
+       int r;
+
+       // Parse commandline
+       r = parse_argv(argc, argv);
+       if (r)
+               return r;
+
+       // Set result directory to PWD
+       if (!config.resultdir)
+               config.resultdir = getcwd(cwd, sizeof(cwd));
+
+       // Run for all arguments
+       for (int i = optind; i < argc; i++) {
+               r = pakfire_dist(pakfire, argv[i], config.resultdir, NULL);
+               if (r)
+                       break;
+       }
+
+       return r;
+}
diff --git a/src/cli/lib/dist.h b/src/cli/lib/dist.h
new file mode 100644 (file)
index 0000000..97f5583
--- /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_DIST_H
+#define PAKFIRE_CLI_DIST_H
+
+#include <pakfire/pakfire.h>
+
+int cli_dist(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_DIST_H */
index d7a85901b73bf4cc9303f50a918303198846d9df..fa57051dd5c9ecb78ada407707e78329caeaaa98 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "lib/clean.h"
 #include "lib/command.h"
+#include "lib/dist.h"
 #include "lib/info.h"
 #include "lib/provides.h"
 #include "lib/repolist.h"
@@ -56,6 +57,7 @@ struct config {
 static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) {
        static const struct command commands[] = {
                { "clean",    0, cli_clean },
+               { "dist",     0, cli_dist },
                { "info",     0, cli_info },
                { "provides", 0, cli_provides },
                { "repolist", 0, cli_repolist },