]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire-builder: Add command to call the linter
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 13:58:47 +0000 (13:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 19 Oct 2024 13:58:47 +0000 (13:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/lint.c [new file with mode: 0644]
src/cli/lib/lint.h [new file with mode: 0644]
src/cli/pakfire-builder.c
src/libpakfire/archive.c
src/libpakfire/include/pakfire/archive.h
src/libpakfire/libpakfire.sym

index 91d82ae75ddc4fcf66b842de15445434e72387ea..cae8ae886f7c595093cc2949c4bb1b8bf7e05cca 100644 (file)
@@ -498,6 +498,8 @@ libcli_la_SOURCES = \
        src/cli/lib/info.h \
        src/cli/lib/install.h \
        src/cli/lib/install.c \
+       src/cli/lib/lint.c \
+       src/cli/lib/lint.h \
        src/cli/lib/pakfire.c \
        src/cli/lib/pakfire.h \
        src/cli/lib/progressbar.c \
diff --git a/src/cli/lib/lint.c b/src/cli/lib/lint.c
new file mode 100644 (file)
index 0000000..a94fad5
--- /dev/null
@@ -0,0 +1,116 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2024 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 <argp.h>
+
+#include <pakfire/archive.h>
+#include <pakfire/pakfire.h>
+
+#include "command.h"
+#include "lint.h"
+#include "pakfire.h"
+
+static const char* args_doc = "lint [OPTIONS...] ARCHIVES...";
+
+static const char* doc = "Lint archives";
+
+#define MAX_ARCHIVES 128
+
+struct config {
+       // Archives
+       char* archives[MAX_ARCHIVES];
+       unsigned int num_archives;
+};
+
+static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
+       struct config* config = data;
+
+       switch (key) {
+               case ARGP_KEY_ARG:
+                       if (config->num_archives >= MAX_ARCHIVES)
+                               return -ENOBUFS;
+
+                       config->archives[config->num_archives++] = arg;
+                       break;
+
+               default:
+                       return ARGP_ERR_UNKNOWN;
+       }
+
+       return 0;
+}
+
+static int do_lint(struct pakfire* pakfire, const char* path) {
+       struct pakfire_archive* archive = NULL;
+       int r;
+
+       // Open the archive
+       r = pakfire_archive_open(&archive, pakfire, path);
+       if (r < 0) {
+               fprintf(stderr, "Could not open %s: %s\n", path, strerror(-r));
+               goto ERROR;
+       }
+
+       // Perform the linting...
+       r = pakfire_archive_lint(archive);
+       if (r < 0) {
+               fprintf(stderr, "Could not lint %s: %s\n", path, strerror(-r));
+               goto ERROR;
+       }
+
+ERROR:
+       if (archive)
+               pakfire_archive_unref(archive);
+
+       return r;
+}
+
+int cli_lint(void* data, int argc, char* argv[]) {
+       struct pakfire* pakfire = NULL;
+       int r;
+
+       struct cli_config* cli_config = data;
+
+       struct config config = {};
+
+       // Parse the command line
+       r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config);
+       if (r)
+               goto ERROR;
+
+       // Setup Pakfire
+       r = cli_setup_pakfire(&pakfire, cli_config);
+       if (r)
+               goto ERROR;
+
+       // Lint all archives
+       for (unsigned int i = 0; i < config.num_archives; i++) {
+               r = do_lint(pakfire, config.archives[i]);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+ERROR:
+       if (pakfire)
+               pakfire_unref(pakfire);
+
+       return r;
+}
+
diff --git a/src/cli/lib/lint.h b/src/cli/lib/lint.h
new file mode 100644 (file)
index 0000000..8490b11
--- /dev/null
@@ -0,0 +1,26 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2024 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_LINT_H
+#define PAKFIRE_CLI_LINT_H
+
+int cli_lint(void* data, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_LINT_H */
index 8887a28f4026efc4ac4393b4b547b55922c3711f..6731d14cfaa853063991d91743fdf6de9f5bafc7 100644 (file)
@@ -37,6 +37,7 @@
 #include "lib/dist.h"
 #include "lib/image.h"
 #include "lib/info.h"
+#include "lib/lint.h"
 #include "lib/pakfire.h"
 #include "lib/progressbar.h"
 #include "lib/provides.h"
@@ -75,6 +76,7 @@ static const struct command commands[] = {
        { "dist",     cli_dist,     1, -1, 0 },
        { "image",    cli_image,   -1, -1, 0 },
        { "info",     cli_info,     1, -1, 0 },
+       { "lint",     cli_lint,     1, -1, 0 },
        { "provides", cli_provides, 1, -1, 0 },
        { "repo",     cli_repo,    -1, -1, 0 },
        { "repolist", cli_repolist, 0,  0, 0 },
@@ -90,6 +92,7 @@ const char* args_doc =
        "clean\n"
        "dist MAKEFILES...\n"
        "image ...\n"
+       "lint [ARCHIVE...]\n"
        "provides PATTERN\n"
        "repo compose PATH PACKAGES...\n"
        "repolist\n"
index d2c8936819a841cec14992a9605792beef998bae..0a9fcff879fa059b10e1ff8e47b1446839e77999 100644 (file)
@@ -42,6 +42,7 @@
 #include <pakfire/filelist.h>
 #include <pakfire/i18n.h>
 #include <pakfire/jail.h>
+#include <pakfire/linter.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/pakfire.h>
@@ -1447,3 +1448,24 @@ int pakfire_archive_apply_systemd_sysusers(struct pakfire_archive* archive) {
 
        return 0;
 }
+
+PAKFIRE_EXPORT int pakfire_archive_lint(struct pakfire_archive* archive) {
+       struct pakfire_linter* linter = NULL;
+       int r;
+
+       // Create a new linter
+       r = pakfire_linter_create(&linter, archive->ctx, archive);
+       if (r < 0)
+               goto ERROR;
+
+       // Lint, lint, lint...
+       r = pakfire_linter_lint(linter);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (linter)
+               pakfire_linter_unref(linter);
+
+       return r;
+}
index bf75bdc783e5da7bde9006df0ca581b640945679..55b71ff74c22cbabb1ea65df91d8789541b84b8e 100644 (file)
@@ -55,6 +55,8 @@ ssize_t pakfire_archive_get_size(struct pakfire_archive* archive);
 int pakfire_archive_make_package(struct pakfire_archive* archive,
        struct pakfire_repo* repo, struct pakfire_package** package);
 
+int pakfire_archive_lint(struct pakfire_archive* archive);
+
 #ifdef PAKFIRE_PRIVATE
 
 #include <pakfire/pakfire.h>
index 02829ce5eb1d53215c2a9948f6e8bb555194d5fb..df584b1f7afc364773e36fee4c62bbf9d3211998 100644 (file)
@@ -68,6 +68,7 @@ global:
        pakfire_archive_get_format;
        pakfire_archive_get_path;
        pakfire_archive_get_size;
+       pakfire_archive_lint;
        pakfire_archive_make_package;
        pakfire_archive_open;
        pakfire_archive_read;