};
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 },
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;
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 =
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;
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
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;
}
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 */
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;
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;
#include <pakfire/pakfire.h>
#include <pakfire/repo.h>
+#include "config.h"
#include "pakfire.h"
#include "progressbar.h"
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) {
ERROR:
if (config)
pakfire_config_unref(config);
- if (f)
- fclose(f);
return r;
}
#ifndef PAKFIRE_CLI_PAKFIRE_H
#define PAKFIRE_CLI_PAKFIRE_H
+#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/pakfire.h>
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 */
#define MAX_PACKAGES 128
struct cli_local_args {
- const char* distro;
-
enum {
SHELL_ENABLE_SNAPSHOT = (1 << 0),
} flags;
"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 },
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;
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;