From: Michael Tremer Date: Sat, 19 Oct 2024 13:58:47 +0000 (+0000) Subject: cli: pakfire-builder: Add command to call the linter X-Git-Tag: 0.9.30~986 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b8789ed3c9fbe104b5f4987cfdebedd47996555;p=pakfire.git cli: pakfire-builder: Add command to call the linter Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 91d82ae75..cae8ae886 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 000000000..a94fad59f --- /dev/null +++ b/src/cli/lib/lint.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#include +#include + +#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 index 000000000..8490b1173 --- /dev/null +++ b/src/cli/lib/lint.h @@ -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 . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CLI_LINT_H +#define PAKFIRE_CLI_LINT_H + +int cli_lint(void* data, int argc, char* argv[]); + +#endif /* PAKFIRE_CLI_LINT_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index 8887a28f4..6731d14cf 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -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" diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index d2c893681..0a9fcff87 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -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; +} diff --git a/src/libpakfire/include/pakfire/archive.h b/src/libpakfire/include/pakfire/archive.h index bf75bdc78..55b71ff74 100644 --- a/src/libpakfire/include/pakfire/archive.h +++ b/src/libpakfire/include/pakfire/archive.h @@ -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 diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 02829ce5e..df584b1f7 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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;