#include "build.h"
#include "color.h"
#include "command.h"
+#include "config.h"
#include "pakfire.h"
#include <pakfire/build.h>
#define MAX_MAKEFILES 32
struct config {
+ const char* distro;
const char* id;
const char* target;
enum {
};
enum {
- OPT_DISABLE_CCACHE = 1,
- OPT_DISABLE_SNAPSHOT = 2,
- OPT_DISABLE_TESTS = 3,
- OPT_ID = 4,
- OPT_NON_INTERACTIVE = 5,
- OPT_TARGET = 6,
+ 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,
};
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 config* config = data;
switch (key) {
+ case OPT_DISTRO:
+ config->distro = arg;
+ break;
+
case OPT_DISABLE_CCACHE:
config->flags &= ~BUILD_ENABLE_CCACHE;
break;
int cli_build(void* data, int argc, char* argv[]) {
struct cli_config* cli_config = data;
struct pakfire_build* build = NULL;
+ struct pakfire_config* c = NULL;
struct config config = {
+ .distro = NULL,
.id = NULL,
.target = NULL,
.flags =
if (!(config.flags & BUILD_ENABLE_TESTS))
build_flags |= PAKFIRE_BUILD_DISABLE_TESTS;
+ // Read distro configuration
+ r = cli_read_distro_config(&c, cli_config->ctx, config.distro);
+ if (r < 0)
+ goto ERROR;
+
// Setup the build environment
- r = pakfire_build_create(&build, cli_config->ctx, cli_config->arch, config.id, build_flags);
+ r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, config.id, build_flags);
if (r) {
fprintf(stderr, "Could not setup the build environment: %m\n");
goto ERROR;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (c)
+ pakfire_config_unref(c);
return r;
}
#include <pakfire/ctx.h>
#include <pakfire/config.h>
+#include <pakfire/string.h>
#include "config.h"
return distro;
}
+
+int cli_read_distro_config(struct pakfire_config** config,
+ struct pakfire_ctx* ctx, const char* distro) {
+ struct pakfire_config* c = NULL;
+ char path[PATH_MAX];
+ int r;
+
+ // Fetch default
+ if (!distro)
+ distro = cli_get_default_distro(ctx);
+
+ // XXX hard-coded path
+
+ // Make the path
+ r = pakfire_string_format(path, "/etc/pakfire/distros/%s.conf", distro);
+ 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);
+ if (r < 0)
+ goto ERROR;
+
+ // Return the configuration
+ *config = c;
+ return 0;
+
+ERROR:
+ if (c)
+ pakfire_config_unref(c);
+
+ return r;
+}
#ifndef PAKFIRE_CLI_CONFIG_H
#define PAKFIRE_CLI_CONFIG_H
+#include <pakfire/config.h>
#include <pakfire/ctx.h>
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);
+
#endif /* PAKFIRE_CLI_CONFIG_H */
#include <pakfire/pakfire.h>
#include "command.h"
+#include "config.h"
#include "image_create.h"
#include "pakfire.h"
struct config {
+ const char* distro;
const char* type;
const char* 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 config* config = data;
switch (key) {
+ case OPT_DISTRO:
+ config->distro = arg;
+ break;
+
case ARGP_KEY_ARG:
if (!config->type)
config->type = arg;
int cli_image_create(void* data, int argc, char* argv[]) {
struct cli_config* cli_config = data;
+ struct pakfire_config* c = NULL;
struct pakfire_build* build = NULL;
FILE* f = NULL;
int r;
};
// Parse the command line
- r = cli_parse(NULL, NULL, args_doc, doc, parse, 0, argc, argv, &config);
+ r = cli_parse(options, NULL, args_doc, doc, parse, 0, argc, argv, &config);
if (r)
goto ERROR;
+ // Read the distro configuration
+ r = cli_read_distro_config(&c, cli_config->ctx, config.distro);
+ if (r < 0)
+ goto ERROR;
+
f = fopen(config.path, "w");
if (!f) {
fprintf(stderr, "Could not open %s: %m\n", config.path);
}
// Setup the build environment
- r = pakfire_build_create(&build, cli_config->ctx, cli_config->arch, NULL, 0);
+ r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, NULL, 0);
if (r)
goto ERROR;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (c)
+ pakfire_config_unref(c);
if (f)
fclose(f);
#include <argp.h>
#include "command.h"
+#include "config.h"
#include "pakfire.h"
#include "shell.h"
#define MAX_PACKAGES 128
struct config {
+ const char* distro;
+
enum {
SHELL_ENABLE_SNAPSHOT = (1 << 0),
} flags;
"Creates a build environment and launches an interactive shell in it";
enum {
- OPT_DISABLE_SNAPSHOT = 1,
- OPT_INSTALL = 2,
+ OPT_DISTRO = 1,
+ OPT_DISABLE_SNAPSHOT = 2,
+ OPT_INSTALL = 3,
};
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 config* config = data;
switch (key) {
+ case OPT_DISTRO:
+ config->distro = arg;
+ break;
+
case OPT_DISABLE_SNAPSHOT:
config->flags &= ~SHELL_ENABLE_SNAPSHOT;
break;
int cli_shell(void* data, int argc, char* argv[]) {
struct cli_config* cli_config = data;
+ struct pakfire_config* c = NULL;
struct pakfire_build* build = NULL;
int build_flags = PAKFIRE_BUILD_INTERACTIVE;
int r;
if (config.flags & SHELL_ENABLE_SNAPSHOT)
build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT;
+ // Read distro configuration
+ r = cli_read_distro_config(&c, cli_config->ctx, config.distro);
+ if (r < 0)
+ goto ERROR;
+
// Setup the build environment
- r = pakfire_build_create(&build, cli_config->ctx, cli_config->arch, NULL, build_flags);
+ r = pakfire_build_create(&build, cli_config->ctx, c, cli_config->arch, NULL, build_flags);
if (r) {
fprintf(stderr, "Could not setup the build environment: %m\n");
goto ERROR;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (c)
+ pakfire_config_unref(c);
return r;
}
return r;
}
-static int pakfire_build_setup_pakfire(struct pakfire_build* build, const char* arch) {
+static int pakfire_build_setup_pakfire(
+ struct pakfire_build* build, struct pakfire_config* config, const char* arch) {
int flags = PAKFIRE_FLAGS_BUILD;
int r;
flags |= PAKFIRE_USE_SNAPSHOT;
// Create a new Pakfire instance
- r = pakfire_create(&build->pakfire, build->ctx, NULL, arch, NULL, flags);
+ r = pakfire_create(&build->pakfire, build->ctx, config, arch, NULL, flags);
if (r < 0)
return r;
return 0;
}
-int pakfire_build_create(struct pakfire_build** build,
- struct pakfire_ctx* ctx, const char* arch, const char* id, int flags) {
+int pakfire_build_create(struct pakfire_build** build, struct pakfire_ctx* ctx,
+ struct pakfire_config* config, const char* arch, const char* id, int flags) {
int r;
// Allocate build object
b->flags = flags;
// Setup Pakfire
- r = pakfire_build_setup_pakfire(b, arch);
+ r = pakfire_build_setup_pakfire(b, config, arch);
if (r < 0)
goto ERROR;
#ifndef PAKFIRE_BUILD_H
#define PAKFIRE_BUILD_H
-#include <pakfire/pakfire.h>
+#include <pakfire/config.h>
+#include <pakfire/ctx.h>
struct pakfire_build;
(struct pakfire_build* build, void* data, int priority, int r,
const char* file, int line, const char* function, const char* format, ...);
-int pakfire_build_create(struct pakfire_build** build,
- struct pakfire_ctx* ctx, const char* arch, const char* id, int flags);
+int pakfire_build_create(struct pakfire_build** build, struct pakfire_ctx* ctx,
+ struct pakfire_config* config, const char* arch, const char* id, int flags);
struct pakfire_build* pakfire_build_ref(struct pakfire_build* build);
struct pakfire_build* pakfire_build_unref(struct pakfire_build* build);
static int pakfire_job_child(struct pakfire_job* job) {
struct pakfire_ctx* ctx = NULL;
+ struct pakfire_config* config = NULL;
struct pakfire_build* build = NULL;
char job_id[UUID_STR_LEN];
- FILE* conf = NULL;
+ int build_flags = 0;
int r;
// Fetch our PID
// Setup logging
pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job);
- // Map the configuration
- conf = fmemopen(job->conf, strlen(job->conf), "r");
- if (!conf) {
- ERROR(ctx, "Could not map the configuration into memory: %m\n");
- r = -errno;
+ // Create a new configuration object
+ r = pakfire_config_create(&config);
+ if (r < 0)
goto ERROR;
- }
- int build_flags = 0;
+ // Parse the configuration
+ r = pakfire_config_parse(config, job->conf, -1);
+ if (r < 0) {
+ ERROR(ctx, "Could not parse configuration: %s\n", strerror(-r));
+ goto ERROR;
+ }
// Disable the ccache
if (!(job->flags & PAKFIRE_JOB_CCACHE))
build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
// Create a new build environment
- r = pakfire_build_create(&build, ctx, job->arch, job_id, build_flags);
+ r = pakfire_build_create(&build, ctx, config, job->arch, job_id, build_flags);
if (r) {
ERROR(ctx, "Could not setup the build environment: %m\n");
r = -errno;
ERROR:
if (build)
pakfire_build_unref(build);
+ if (config)
+ pakfire_config_unref(config);
if (ctx)
pakfire_ctx_unref(ctx);
- if (conf)
- fclose(conf);
return r;
}
#ifndef PAKFIRE_STRING_H
#define PAKFIRE_STRING_H
-#ifdef PAKFIRE_PRIVATE
-
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
int pakfire_string_is_url(const char* s);
-#endif
-
#endif /* PAKFIRE_STRING_H */