}
int cli_build(void* data, int argc, char* argv[]) {
- struct pakfire* pakfire = NULL;
+ struct cli_config* cli_config = data;
struct pakfire_build* build = NULL;
struct config config = {
.id = NULL,
int build_flags = 0;
int r;
- struct cli_config* cli_config = data;
-
// Parse the command line
r = cli_parse(options, NULL, NULL, NULL, parse, 0, argc, argv, &config);
if (r)
// Replace the logger
pakfire_ctx_set_log_callback(cli_config->ctx, log_callback, NULL);
- // Set Pakfire flags
+ // Use the snapshot?
if (config.flags & BUILD_ENABLE_SNAPSHOT)
- cli_config->flags |= PAKFIRE_USE_SNAPSHOT;
-
- // Setup pakfire
- r = cli_setup_pakfire(&pakfire, cli_config);
- if (r)
- goto ERROR;
+ build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT;
// Is the build interactive?
if (config.flags & BUILD_INTERACTIVE)
build_flags |= PAKFIRE_BUILD_DISABLE_TESTS;
// Setup the build environment
- r = pakfire_build_create(&build, pakfire, config.id, build_flags);
+ r = pakfire_build_create(&build, cli_config->ctx, 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 (pakfire)
- pakfire_unref(pakfire);
return r;
}
}
int cli_image_create(void* data, int argc, char* argv[]) {
- struct pakfire* pakfire = NULL;
+ struct cli_config* cli_config = data;
struct pakfire_build* build = NULL;
FILE* f = NULL;
int r;
- struct cli_config* cli_config = data;
-
struct config config = {
.type = NULL,
.path = NULL,
goto ERROR;
}
- // Setup pakfire
- r = cli_setup_pakfire(&pakfire, cli_config);
- if (r)
- goto ERROR;
-
// Setup the build environment
- r = pakfire_build_create(&build, pakfire, NULL, 0);
+ r = pakfire_build_create(&build, cli_config->ctx, cli_config->arch, NULL, 0);
if (r)
goto ERROR;
ERROR:
if (build)
pakfire_build_unref(build);
- if (pakfire)
- pakfire_unref(pakfire);
if (f)
fclose(f);
}
int cli_shell(void* data, int argc, char* argv[]) {
- struct pakfire* pakfire = NULL;
+ struct cli_config* cli_config = data;
struct pakfire_build* build = NULL;
+ int build_flags = PAKFIRE_BUILD_INTERACTIVE;
int r;
- struct cli_config* cli_config = data;
-
struct config config = {
.flags = SHELL_ENABLE_SNAPSHOT,
.argv = {},
// Enable snapshots?
if (config.flags & SHELL_ENABLE_SNAPSHOT)
- cli_config->flags |= PAKFIRE_USE_SNAPSHOT;
-
- // Setup pakfire
- r = cli_setup_pakfire(&pakfire, cli_config);
- if (r)
- goto ERROR;
+ build_flags |= PAKFIRE_BUILD_ENABLE_SNAPSHOT;
// Setup the build environment
- r = pakfire_build_create(&build, pakfire, NULL, PAKFIRE_BUILD_INTERACTIVE);
+ r = pakfire_build_create(&build, cli_config->ctx, 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 (pakfire)
- pakfire_unref(pakfire);
return r;
}
return r;
}
+static int pakfire_build_setup_pakfire(struct pakfire_build* build, const char* arch) {
+ int flags = PAKFIRE_FLAGS_BUILD;
+ int r;
+
+ // Enable snapshot?
+ if (build->flags & PAKFIRE_BUILD_ENABLE_SNAPSHOT)
+ flags |= PAKFIRE_USE_SNAPSHOT;
+
+ // Create a new Pakfire instance
+ r = pakfire_create(&build->pakfire, build->ctx, NULL, arch, NULL, flags);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
int pakfire_build_create(struct pakfire_build** build,
- struct pakfire* pakfire, const char* id, int flags) {
+ struct pakfire_ctx* ctx, const char* arch, const char* id, int flags) {
int r;
// Allocate build object
return 1;
// Reference the context
- b->ctx = pakfire_ctx(pakfire);
-
- // Reference pakfire
- b->pakfire = pakfire_ref(pakfire);
+ b->ctx = pakfire_ctx_ref(ctx);
// Initialize reference counter
b->nrefs = 1;
// Copy flags
b->flags = flags;
+ // Setup Pakfire
+ r = pakfire_build_setup_pakfire(b, arch);
+ if (r < 0)
+ goto ERROR;
+
// Create an environment
r = pakfire_env_create(&b->env, b->ctx);
if (r < 0)
struct pakfire_build;
enum pakfire_build_flags {
- PAKFIRE_BUILD_INTERACTIVE = (1 << 0),
- PAKFIRE_BUILD_DISABLE_CCACHE = (1 << 1),
- PAKFIRE_BUILD_DISABLE_TESTS = (1 << 2),
+ PAKFIRE_BUILD_ENABLE_SNAPSHOT = (1 << 0),
+ PAKFIRE_BUILD_INTERACTIVE = (1 << 1),
+ PAKFIRE_BUILD_DISABLE_CCACHE = (1 << 2),
+ PAKFIRE_BUILD_DISABLE_TESTS = (1 << 3),
};
typedef int (*pakfire_build_log_callback)
const char* file, int line, const char* function, const char* format, ...);
int pakfire_build_create(struct pakfire_build** build,
- struct pakfire* pakfire, const char* id, int flags);
+ struct pakfire_ctx* ctx, 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* pakfire = NULL;
struct pakfire_build* build = NULL;
char job_id[UUID_STR_LEN];
FILE* conf = NULL;
goto ERROR;
}
- // Create a new Pakfire instance
- r = pakfire_create(&pakfire, ctx, NULL, job->arch, conf, PAKFIRE_FLAGS_BUILD);
- if (r) {
- ERROR(ctx, "Could not initialize Pakfire: %m\n");
- r = -errno;
- goto ERROR;
- }
-
int build_flags = 0;
// Disable the ccache
build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
// Create a new build environment
- r = pakfire_build_create(&build, pakfire, job_id, build_flags);
+ r = pakfire_build_create(&build, ctx, 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 (pakfire)
- pakfire_unref(pakfire);
if (ctx)
pakfire_ctx_unref(ctx);
if (conf)