From: Michael Tremer Date: Sun, 5 Jan 2025 15:38:12 +0000 (+0000) Subject: CLI: Only pass distro globally for all build commands X-Git-Tag: 0.9.30~527 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=24e9c0e0b5303e95931e23484eb192e6feb69286;p=pakfire.git CLI: Only pass distro globally for all build commands Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/build.c b/src/cli/lib/build.c index 274c79300..d7512823c 100644 --- a/src/cli/lib/build.c +++ b/src/cli/lib/build.c @@ -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; diff --git a/src/cli/lib/config.c b/src/cli/lib/config.c index a948e3a95..83fa22019 100644 --- a/src/cli/lib/config.c +++ b/src/cli/lib/config.c @@ -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; } diff --git a/src/cli/lib/config.h b/src/cli/lib/config.h index 2e63c92a8..b74dec244 100644 --- a/src/cli/lib/config.h +++ b/src/cli/lib/config.h @@ -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 */ diff --git a/src/cli/lib/image_create.c b/src/cli/lib/image_create.c index d79292c14..50f7d700b 100644 --- a/src/cli/lib/image_create.c +++ b/src/cli/lib/image_create.c @@ -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; diff --git a/src/cli/lib/pakfire.c b/src/cli/lib/pakfire.c index fccef1c14..bed149474 100644 --- a/src/cli/lib/pakfire.c +++ b/src/cli/lib/pakfire.c @@ -25,6 +25,7 @@ #include #include +#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; } diff --git a/src/cli/lib/pakfire.h b/src/cli/lib/pakfire.h index 553b146bd..5214e39b2 100644 --- a/src/cli/lib/pakfire.h +++ b/src/cli/lib/pakfire.h @@ -21,6 +21,7 @@ #ifndef PAKFIRE_CLI_PAKFIRE_H #define PAKFIRE_CLI_PAKFIRE_H +#include #include #include @@ -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 */ diff --git a/src/cli/lib/shell.c b/src/cli/lib/shell.c index d3271bb3e..cc6df2e8a 100644 --- a/src/cli/lib/shell.c +++ b/src/cli/lib/shell.c @@ -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;