]> git.ipfire.org Git - pakfire.git/commitdiff
CLI: Only pass distro globally for all build commands
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 15:38:12 +0000 (15:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Jan 2025 15:38:12 +0000 (15:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/build.c
src/cli/lib/config.c
src/cli/lib/config.h
src/cli/lib/image_create.c
src/cli/lib/pakfire.c
src/cli/lib/pakfire.h
src/cli/lib/shell.c

index 274c79300d9642800c0df00f960f3501efaa1cc7..d7512823c002adb7d0e09efa61050dd86a9ffb42 100644 (file)
@@ -51,17 +51,15 @@ struct cli_local_args {
 };
 
 enum {
-       OPT_DISTRO           = 1,
-       OPT_DISABLE_CCACHE   = 2,
-       OPT_DISABLE_SNAPSHOT = 3,
-       OPT_DISABLE_TESTS    = 4,
-       OPT_ID               = 5,
-       OPT_NON_INTERACTIVE  = 6,
-       OPT_TARGET           = 7,
+       OPT_DISABLE_CCACHE   = 1,
+       OPT_DISABLE_SNAPSHOT = 2,
+       OPT_DISABLE_TESTS    = 3,
+       OPT_ID               = 4,
+       OPT_NON_INTERACTIVE  = 5,
+       OPT_TARGET           = 6,
 };
 
 static struct argp_option options[] = {
-       { "distro",           OPT_DISTRO,          "DISTRO", 0, "Distribution to build for", 1 },
        { "disable-ccache",   OPT_DISABLE_CCACHE,      NULL, 0, "Disable the ccache",     0 },
        { "disable-snapshot", OPT_DISABLE_SNAPSHOT,    NULL, 0, "Do not use the snapshot", 0 },
        { "disable-tests",    OPT_DISABLE_TESTS,       NULL, 0, "Do not run tests",        0 },
@@ -75,10 +73,6 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        struct cli_local_args* args = data;
 
        switch (key) {
-               case OPT_DISTRO:
-                       args->distro = arg;
-                       break;
-
                case OPT_DISABLE_CCACHE:
                        args->flags &= ~BUILD_ENABLE_CCACHE;
                        break;
@@ -156,7 +150,6 @@ static void log_callback(void* data, int priority, const char* file, int line,
 int cli_build(void* data, int argc, char* argv[]) {
        struct cli_global_args* global_args = data;
        struct cli_local_args local_args = {
-               .distro = NULL,
                .id     = NULL,
                .target = NULL,
                .flags  =
@@ -194,8 +187,8 @@ int cli_build(void* data, int argc, char* argv[]) {
        if (!(local_args.flags & BUILD_ENABLE_TESTS))
                build_flags |= PAKFIRE_BUILD_DISABLE_TESTS;
 
-       // Read distro configuration
-       r = cli_read_distro_config(&config, global_args->ctx, local_args.distro);
+       // Read configuration
+       r = cli_setup_config(&config, global_args);
        if (r < 0)
                goto ERROR;
 
index a948e3a9561179dac23d55aac7fd026adb7ebf4f..83fa22019c6517b3478c5c0eea797272dfdf3899 100644 (file)
@@ -43,16 +43,10 @@ const char* cli_get_default_distro(struct pakfire_ctx* ctx) {
        return distro;
 }
 
-int cli_read_distro_config(struct pakfire_config** config,
-               struct pakfire_ctx* ctx, const char* distro) {
-       struct pakfire_config* c = NULL;
+int cli_read_distro_config(struct pakfire_config* config, const char* distro) {
        char path[PATH_MAX];
        int r;
 
-       // Fetch default
-       if (!distro)
-               distro = cli_get_default_distro(ctx);
-
        // XXX hard-coded path
 
        // Make the path
@@ -60,23 +54,10 @@ int cli_read_distro_config(struct pakfire_config** config,
        if (r < 0)
                return r;
 
-       // Create the configuration
-       r = pakfire_config_create(&c);
-       if (r < 0)
-               goto ERROR;
-
        // Read the configuration
-       r = pakfire_config_read_path(c, path);
+       r = pakfire_config_read_path(config, path);
        if (r < 0)
-               goto ERROR;
+               return r;
 
-       // Return the configuration
-       *config = c;
        return 0;
-
-ERROR:
-       if (c)
-               pakfire_config_unref(c);
-
-       return r;
 }
index 2e63c92a8f9fc6b9c19da5bfb51e54b01a1fd9e1..b74dec2440fdf85b7ec0553d8d46fe4ce38fcba4 100644 (file)
@@ -26,7 +26,6 @@
 
 const char* cli_get_default_distro(struct pakfire_ctx* ctx);
 
-int cli_read_distro_config(
-       struct pakfire_config** config, struct pakfire_ctx* ctx, const char* distro);
+int cli_read_distro_config(struct pakfire_config* config, const char* distro);
 
 #endif /* PAKFIRE_CLI_CONFIG_H */
index d79292c143f45edcdf24c166432f3a275aaeab54..50f7d700bc4481a32caab6b70af32f25d5c69fac 100644 (file)
@@ -38,23 +38,10 @@ static const char* args_doc = "image create TYPE PATH";
 
 static const char* doc = "Creates images";
 
-enum {
-       OPT_DISTRO           = 1,
-};
-
-static struct argp_option options[] = {
-       { "distro", OPT_DISTRO, "DISTRO", 0, "Distribution to build for", 1 },
-       { NULL },
-};
-
 static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        struct cli_local_args* args = data;
 
        switch (key) {
-               case OPT_DISTRO:
-                       args->distro = arg;
-                       break;
-
                case ARGP_KEY_ARG:
                        if (!args->type)
                                args->type = arg;
@@ -73,22 +60,19 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 
 int cli_image_create(void* data, int argc, char* argv[]) {
        struct cli_global_args* global_args = data;
-       struct cli_local_args local_args = {
-               .type = NULL,
-               .path = NULL,
-       };
+       struct cli_local_args local_args = {};
        struct pakfire_config* config = NULL;
        struct pakfire_build* build = NULL;
        FILE* f = NULL;
        int r;
 
        // Parse the command line
-       r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &local_args);
+       r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &local_args);
        if (r)
                goto ERROR;
 
-       // Read the distro configuration
-       r = cli_read_distro_config(&config, global_args->ctx, local_args.distro);
+       // Read configuration
+       r = cli_setup_config(&config, global_args);
        if (r < 0)
                goto ERROR;
 
index fccef1c148fff5b74d5af74faea7458dffb58d10..bed1494748b832f277e53d9afe77572ee84cda6b 100644 (file)
@@ -25,6 +25,7 @@
 #include <pakfire/pakfire.h>
 #include <pakfire/repo.h>
 
+#include "config.h"
 #include "pakfire.h"
 #include "progressbar.h"
 
@@ -43,24 +44,49 @@ static void cli_set_repo_enabled(struct pakfire* pakfire, const char* name, int
        pakfire_repo_unref(repo);
 }
 
-int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args) {
-       struct pakfire_config* config = NULL;
-       struct pakfire* p = NULL;
-       FILE* f = NULL;
+int cli_setup_config(struct pakfire_config** config, struct cli_global_args* args) {
+       struct pakfire_config* c = NULL;
        int r;
 
        // Create a new config object
-       r = pakfire_config_create(&config);
+       r = pakfire_config_create(&c);
        if (r < 0)
                goto ERROR;
 
+       // Open the distro configuration
+       if (args->distro) {
+               r = cli_read_distro_config(c, args->distro);
+               if (r < 0)
+                       goto ERROR;
+
        // Open the regular configuration
-       if (args->config) {
-               r = pakfire_config_read_path(config, args->config);
+       } else if (args->config) {
+               r = pakfire_config_read_path(c, args->config);
                if (r < 0)
                        goto ERROR;
        }
 
+       // Return the configuration
+       *config = c;
+       return 0;
+
+ERROR:
+       if (c)
+               pakfire_config_unref(c);
+
+       return r;
+}
+
+int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args) {
+       struct pakfire_config* config = NULL;
+       struct pakfire* p = NULL;
+       int r;
+
+       // Setup the configuration
+       r = cli_setup_config(&config, args);
+       if (r < 0)
+               goto ERROR;
+
        // Initialize Pakfire
        r = pakfire_create(&p, args->ctx, config, args->root, args->arch, args->flags);
        if (r < 0) {
@@ -82,8 +108,6 @@ int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args) {
 ERROR:
        if (config)
                pakfire_config_unref(config);
-       if (f)
-               fclose(f);
 
        return r;
 }
index 553b146bd4562557481ed969be483b23b5c68892..5214e39b26ce3fe920f5ae6f6ae2f4befd427473 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef PAKFIRE_CLI_PAKFIRE_H
 #define PAKFIRE_CLI_PAKFIRE_H
 
+#include <pakfire/config.h>
 #include <pakfire/ctx.h>
 #include <pakfire/pakfire.h>
 
@@ -43,6 +44,7 @@ struct cli_global_args {
        unsigned int num_disable_repos;
 };
 
+int cli_setup_config(struct pakfire_config** config, struct cli_global_args* args);
 int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args);
 
 #endif /* PAKFIRE_CLI_PAKFIRE_H */
index d3271bb3e458a1e28a5c046e0ac28ae8e5b33ccd..cc6df2e8ac2eced91ccdd94dc865abe5b47d09c1 100644 (file)
@@ -32,8 +32,6 @@
 #define MAX_PACKAGES 128
 
 struct cli_local_args {
-       const char* distro;
-
        enum {
                SHELL_ENABLE_SNAPSHOT = (1 << 0),
        } flags;
@@ -51,13 +49,11 @@ static const char* doc =
        "Creates a build environment and launches an interactive shell in it";
 
 enum {
-       OPT_DISTRO           = 1,
-       OPT_DISABLE_SNAPSHOT = 2,
-       OPT_INSTALL          = 3,
+       OPT_DISABLE_SNAPSHOT = 1,
+       OPT_INSTALL          = 2,
 };
 
 static struct argp_option options[] = {
-       { "distro",           OPT_DISTRO,            "DISTRO", 0, "Distribution to build for", 1 },
        { "disable-snapshot", OPT_DISABLE_SNAPSHOT,      NULL, 0, "Do not use the snapshot", 0 },
        { "install",          OPT_INSTALL,          "PACKAGE", 0, "Install this package", 0 },
        { NULL },
@@ -67,10 +63,6 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        struct cli_local_args* args = data;
 
        switch (key) {
-               case OPT_DISTRO:
-                       args->distro = arg;
-                       break;
-
                case OPT_DISABLE_SNAPSHOT:
                        args->flags &= ~SHELL_ENABLE_SNAPSHOT;
                        break;
@@ -119,8 +111,8 @@ int cli_shell(void* data, int argc, char* argv[]) {
        if (local_args.flags & SHELL_ENABLE_SNAPSHOT)
                build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT;
 
-       // Read distro configuration
-       r = cli_read_distro_config(&config, global_args->ctx, local_args.distro);
+       // Read configuration
+       r = cli_setup_config(&config, global_args);
        if (r < 0)
                goto ERROR;