return NULL;
}
-PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path,
- const char* target, const char* id, int flags) {
- char makefiles[PATH_MAX];
- char cwd[PATH_MAX];
- uuid_t build_id;
- glob_t buffer;
- int r = 1;
-
- // Check for valid input
- if (!path) {
- errno = EINVAL;
- return 1;
- }
-
- DEBUG(pakfire, "Building %s...\n", path);
-
- // Try parsing the Build ID
- if (id) {
- r = uuid_parse(id, build_id);
- if (r) {
- ERROR(pakfire, "Could not parse build ID %s\n", id);
- return r;
- }
+PAKFIRE_EXPORT int pakfire_build_set_target(
+ struct pakfire_build* build, const char* target) {
+ pakfire_string_set(build->target, target);
- // Otherwise initialize the Build ID with something random
- } else {
- uuid_generate_random(build_id);
- }
+ return 0;
+}
- // The default target is the local repository path
- if (!target) {
- struct pakfire_repo* repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
- if (repo) {
- target = pakfire_repo_get_path(repo);
- pakfire_repo_unref(repo);
+PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
+ char makefiles[PATH_MAX];
+ glob_t buffer;
+ int r;
- // If the repository could not be found, just write to the cwd
- } else {
- target = getcwd(cwd, sizeof(cwd));
- }
- }
+ INFO(build->pakfire, "Building %s...\n", path);
// Setup build environment
- r = pakfire_build_setup(pakfire);
+ r = pakfire_build_setup(build->pakfire);
if (r)
return r;
};
// Install the package into the build environment
- r = pakfire_install(pakfire, 0, 0, packages, NULL, PAKFIRE_REQUEST_ESSENTIAL,
+ r = pakfire_install(build->pakfire, 0, 0, packages, NULL, PAKFIRE_REQUEST_ESSENTIAL,
NULL, NULL, NULL);
if (r) {
- ERROR(pakfire, "Could not install %s\n", path);
- goto ERROR;
+ ERROR(build->pakfire, "Could not install %s\n", path);
+ return r;
}
// Where are the makefiles located?
- r = pakfire_make_path(pakfire, makefiles, "/usr/src/packages/*/*.nm");
+ r = pakfire_make_path(build->pakfire, makefiles, "/usr/src/packages/*/*.nm");
if (r < 0)
goto ERROR;
// Find all makefiles
r = glob(makefiles, 0, NULL, &buffer);
if (r) {
- ERROR(pakfire, "glob() on %s failed: %m\n", makefiles);
+ ERROR(build->pakfire, "glob() on %s failed: %m\n", makefiles);
globfree(&buffer);
goto ERROR;
}
// Iterate over all makefiles
for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
- r = pakfire_build_makefile(pakfire, buffer.gl_pathv[i], target, &build_id, flags);
+ r = pakfire_build_makefile(build->pakfire, buffer.gl_pathv[i], build->target,
+ &build->id, build->flags);
if (r) {
- ERROR(pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]);
+ ERROR(build->pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]);
globfree(&buffer);
goto ERROR;
}
return r;
}
+/*
+ Compatibility function to keep the legacy API.
+*/
+PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path,
+ const char* target, const char* id, int flags) {
+ struct pakfire_build* build = NULL;
+ int r;
+
+ // Check if path is set
+ if (!path) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // Create a new build environment
+ r = pakfire_build_create(&build, pakfire, id, flags);
+ if (r)
+ goto ERROR;
+
+ // Set target
+ if (target) {
+ r = pakfire_build_set_target(build, target);
+ if (r)
+ goto ERROR;
+ }
+
+ // Run build
+ r = pakfire_build_exec(build, path);
+
+ERROR:
+ if (build)
+ pakfire_build_unref(build);
+
+ return r;
+}
+
/*
This function enables the local repository so that it can be access by
a pakfire instance running inside the chroot.