#include "command.h"
#include "pakfire.h"
+#include <pakfire/archive.h>
#include <pakfire/build.h>
+#include <pakfire/package.h>
#include <pakfire/pakfire.h>
+#include <pakfire/path.h>
+#include <pakfire/repo.h>
#define MAX_MAKEFILES 32
pakfire_log_syslog(NULL, priority, file, line, function, format, args);
}
+static int result_callback(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+ struct pakfire_build* build, struct pakfire_archive* archive, void* data) {
+ const struct cli_local_args* local_args = data;
+ struct pakfire_package* pkg = NULL;
+ struct pakfire_repo* local = NULL;
+ char path[PATH_MAX];
+ int r;
+
+ // Fetch the package metadata
+ r = pakfire_archive_make_package(archive, NULL, &pkg);
+ if (r < 0)
+ goto ERROR;
+
+ // Fetch NEVRA
+ const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
+
+ // Fetch the local repository & import the archive
+ local = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
+ if (local) {
+ r = pakfire_repo_import_archive(local, archive);
+ if (r < 0) {
+ ERROR(ctx, "Could not import %s to the local repository: %s\n",
+ nevra, strerror(-r));
+ goto ERROR;
+ }
+ }
+
+ // Copy to the target (if given)
+ if (local_args->target) {
+ // Fetch the filename
+ const char* filename = pakfire_package_get_filename(pkg);
+
+ // Make the absolute target path
+ r = pakfire_path_append(path, local_args->target, filename);
+ if (r < 0)
+ goto ERROR;
+
+ // Copy (or link) the package to the target path
+ r = pakfire_archive_link_or_copy(archive, path);
+ if (r < 0) {
+ ERROR(ctx, "Could not copy %s to %s: %s\n",
+ nevra, path, strerror(-r));
+ goto ERROR;
+ }
+ }
+
+ERROR:
+ if (local)
+ pakfire_repo_unref(local);
+ if (pkg)
+ pakfire_package_unref(pkg);
+
+ return r;
+}
+
int cli_build(void* data, int argc, char* argv[]) {
struct cli_global_args* global_args = data;
struct cli_local_args local_args = {
// Process all packages
for (unsigned int i = 0; i < local_args.num_makefiles; i++) {
// Run the build
- r = pakfire_build_exec(build, local_args.makefiles[i]);
+ r = pakfire_build_exec(build, local_args.makefiles[i], result_callback, &local_args);
if (r) {
fprintf(stderr, "Could not build %s\n", local_args.makefiles[i]);
goto ERROR;
return r;
}
-int pakfire_build_exec(struct pakfire_build* build, const char* path) {
+struct pakfire_build_result {
+ struct pakfire_build* build;
+
+ // Callback
+ pakfire_build_result_callback callback;
+ void* data;
+};
+
+static int pakfire_build_result(struct pakfire_ctx* ctx, struct pakfire_package* pkg,
+ struct pakfire_archive* archive, void* data) {
+ const struct pakfire_build_result* result = data;
+ struct pakfire_build* build = result->build;
+
+ return result->callback(ctx, build->pakfire, build, archive, result->data);
+}
+
+int pakfire_build_exec(struct pakfire_build* build, const char* path,
+ pakfire_build_result_callback result_callback, void* data) {
struct pakfire_package* package = NULL;
struct pakfire_parser* makefile = NULL;
char* problems = NULL;
if (r)
goto ERROR;
- // Copy packages to their destination
- r = pakfire_build_copy_packages(build);
- if (r)
- goto ERROR;
+ // Call the result callback (if any)
+ if (result_callback) {
+ struct pakfire_build_result result = {
+ .build = build,
+ .callback = result_callback,
+ .data = data,
+ };
+
+ r = pakfire_repo_walk_archives(build->repo, pakfire_build_result, &result, 0);
+ if (r < 0)
+ goto ERROR;
+ }
// Log duration
r = pakfire_format_time(duration, pakfire_build_duration(build));
#ifndef PAKFIRE_BUILD_H
#define PAKFIRE_BUILD_H
+#include <pakfire/archive.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
PAKFIRE_BUILD_DISABLE_TESTS = (1 << 3),
};
+typedef int (*pakfire_build_result_callback)(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+ struct pakfire_build* build, struct pakfire_archive* archive, void* data);
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);
-
int pakfire_build_set_ccache_path(struct pakfire_build* build, const char* path);
int pakfire_build_set_target(struct pakfire_build* build, const char* target);
int pakfire_build_shell(struct pakfire_build* build, const char* argv[], const char** packages);
-int pakfire_build_exec(struct pakfire_build* build, const char* path);
+int pakfire_build_exec(struct pakfire_build* build, const char* path,
+ pakfire_build_result_callback result_callback, void* data);
int pakfire_build_mkimage(struct pakfire_build* build,
const char* type, FILE* f);
// XXX need to set target
// Run the build
- r = pakfire_build_exec(build, job->pkg);
+ r = pakfire_build_exec(build, job->pkg, NULL, NULL);
ERROR:
if (build)