#define BUILD_INFO_ERRNO(build, r, arg...) BUILD_LOG_ERRNO(build, LOG_INFO, r, ## arg)
#define BUILD_ERROR_ERRNO(build, r, arg...) BUILD_LOG_ERRNO(build, LOG_ERR, r, ## arg)
+#define BUILD_DEBUG_ERRNO(build, r, arg...) BUILD_LOG_ERRNO(build, LOG_DEBUG, r, ## arg)
#define BUILD_INFO(build, arg...) BUILD_INFO_ERRNO(build, 0, ## arg)
#define BUILD_ERROR(build, arg...) BUILD_ERROR_ERRNO(build, 0, ## arg)
+#define BUILD_DEBUG(build, arg...) BUILD_DEBUG_ERRNO(build, 0, ## arg)
static int pakfire_build_has_flag(struct pakfire_build* build, int flag) {
return build->flags & flag;
const char* name = pakfire_repo_get_name(repo);
- DEBUG(pakfire, "Exporting repository configuration for '%s'\n", name);
+ BUILD_DEBUG(build, "Exporting repository configuration for '%s'\n", name);
// Make path for configuration file
r = pakfire_path(build->pakfire, path, PAKFIRE_CONFIG_DIR "/repos/%s.repo", name);
if (r) {
- ERROR(pakfire, "Could not make repository configuration path for %s: %m\n", name);
+ BUILD_ERROR(build, "Could not make repository configuration path for %s: %m\n", name);
goto ERROR;
}
// Open the repository configuration
f = fopen(path, "w");
if (!f) {
- ERROR(pakfire, "Could not open %s for writing: %m\n", path);
+ BUILD_ERROR(build, "Could not open %s for writing: %m\n", path);
goto ERROR;
}
// Write repository configuration
r = pakfire_repo_write_config(repo, f);
if (r) {
- ERROR(pakfire, "Could not write repository configuration for %s: %m\n", name);
+ BUILD_ERROR(build, "Could not write repository configuration for %s: %m\n", name);
goto ERROR;
}
if (pakfire_path_exists(_path)) {
r = pakfire_jail_bind(build->jail, _path, _path, MS_RDONLY);
if (r) {
- ERROR(pakfire, "Could not bind-mount the repository at %s: %m\n", _path);
+ BUILD_ERROR(build, "Could not bind-mount the repository at %s: %m\n", _path);
goto ERROR;
}
}
goto ERROR;
}
- DEBUG(build->pakfire, "Reading script from %s...\n", path);
+ BUILD_DEBUG(build, "Reading script from %s...\n", path);
// Open the file
f = fopen(path, "r");
if (!f) {
- ERROR(build->pakfire, "Could not open script %s: %m\n", path);
+ BUILD_ERROR(build, "Could not open script %s: %m\n", path);
goto ERROR;
}
// Read the file into a the buffer
r = pakfire_read_file_into_buffer(f, buffer, length);
if (r) {
- ERROR(build->pakfire, "Could not read script: %m\n");
+ BUILD_ERROR(build, "Could not read script: %m\n");
goto ERROR;
}
char* script = NULL;
size_t length = 0;
- DEBUG(build->pakfire, "Running build script '%s'...\n", filename);
+ BUILD_DEBUG(build, "Running build script '%s'...\n", filename);
// Read the script
r = pakfire_build_read_script(build, filename, &script, &length);
// Execute the script
r = pakfire_jail_exec_script(build->jail, script, length, args,
communicate_in, communicate_out, data);
- if (r) {
- ERROR(build->pakfire, "Script '%s' failed with status %d\n", filename, r);
- }
+ if (r)
+ BUILD_ERROR(build, "Script '%s' failed with status %d\n", filename, r);
if (script)
free(script);
}
struct pakfire_find_deps_ctx {
+ struct pakfire_build* build;
struct pakfire_package* pkg;
int dep;
struct pakfire_scriptlet* scriptlet;
if (r)
return r;
- DEBUG(pakfire, "Processing dependency: %s\n", dep);
+ BUILD_DEBUG(ctx->build, "Processing dependency: %s\n", dep);
// Filter out any dependencies that are provided by this package
if (ctx->dep == PAKFIRE_PKG_REQUIRES) {
// Fetch the error message
r = pcre2_get_error_message(r, (PCRE2_UCHAR*)error, sizeof(error));
if (r < 0) {
- ERROR(pakfire, "Could not fetch PCRE error message: %m\n");
+ BUILD_ERROR(ctx->build, "Could not fetch PCRE error message: %m\n");
r = 1;
goto ERROR;
}
- ERROR(pakfire, "Could not match the filter: %s\n", error);
+ BUILD_ERROR(ctx->build, "Could not match the filter: %s\n", error);
r = 1;
goto ERROR;
// Match!
} else {
- DEBUG(pakfire, "Skipping dependency that has been filtered: %s\n", dep);
+ BUILD_DEBUG(ctx->build, "Skipping dependency that has been filtered: %s\n", dep);
r = 0;
goto ERROR;
}
// Add dependency
r = pakfire_package_add_dep(ctx->pkg, ctx->dep, buffer);
if (r) {
- ERROR(pakfire, "Could not process dependency '%s': %m\n", buffer);
+ BUILD_ERROR(ctx->build, "Could not process dependency '%s': %m\n", buffer);
return r;
}
break;
- // Send everything else to the default logger
+ // Send everything else to the build logger
default:
- ERROR(pakfire, "%s\n", buffer);
+ BUILD_ERROR(ctx->build, "%s\n", buffer);
break;
}
goto ERROR;
SKIP:
- DEBUG(pakfire, "Skipping dependency that is provided by the package itself: %s\n", dep);
+ BUILD_DEBUG(ctx->build, "Skipping dependency that is provided by the package itself: %s\n", dep);
ERROR:
if (match)
struct pakfire_filelist* filelist, int class, const pcre2_code* filter) {
// Construct the context
struct pakfire_find_deps_ctx ctx = {
+ .build = build,
.pkg = pkg,
.dep = dep,
.class = class,
r = pakfire_build_run_script(build, script, args,
pakfire_build_send_filelist, pakfire_build_process_deps, &ctx);
if (r)
- ERROR(build->pakfire, "%s returned with error %d\n", script, r);
+ BUILD_ERROR(build, "%s returned with error %d\n", script, r);
return r;
}
if (r)
goto ERROR;
- DEBUG(build->pakfire, "%zu file(s) found\n", pakfire_filelist_length(filelist));
+ BUILD_DEBUG(build, "%zu file(s) found\n", pakfire_filelist_length(filelist));
// Nothing to do if the filelist is empty
if (pakfire_filelist_is_empty(filelist))
// Find dependencies
r = pakfire_build_find_dependencies(build, makefile, namespace, pkg, filelist);
if (r) {
- ERROR(build->pakfire, "Finding dependencies failed: %m\n");
+ BUILD_ERROR(build, "Finding dependencies failed: %m\n");
goto ERROR;
}
int r;
struct pakfire_find_deps_ctx ctx = {
+ .build = build,
.pkg = pkg,
.dep = PAKFIRE_PKG_PREREQUIRES,
.scriptlet = scriptlet,
// Add it to the package
r = pakfire_packager_add_scriptlet(packager, scriptlet);
if (r) {
- ERROR(build->pakfire, "Could not add scriptlet %s\n", type);
+ BUILD_ERROR(build, "Could not add scriptlet %s\n", type);
goto ERROR;
}
// Add scriptlet requirements
r = pakfire_build_add_scriptlet_requires(build, pkg, scriptlet);
if (r) {
- ERROR(build->pakfire, "Could not add scriptlet requirements: %m\n");
+ BUILD_ERROR(build, "Could not add scriptlet requirements: %m\n");
goto ERROR;
}
goto ERROR;
}
- INFO(build->pakfire, "Building package '%s'...\n", name);
- DEBUG(build->pakfire, " buildroot = %s\n", buildroot);
+ BUILD_INFO(build, "Building package '%s'...\n", name);
+ BUILD_DEBUG(build, " buildroot = %s\n", buildroot);
// Fetch build architecture
const char* arch = pakfire_get_arch(build->pakfire);
// Fetch package from makefile
r = pakfire_parser_create_package(makefile, &pkg, NULL, namespace, arch);
if (r) {
- ERROR(build->pakfire, "Could not create package from makefile: %m\n");
+ BUILD_ERROR(build, "Could not create package from makefile: %m\n");
goto ERROR;
}
// Write the finished package
r = pakfire_packager_finish_to_directory(packager, path, NULL);
if (r) {
- ERROR(build->pakfire, "pakfire_packager_finish() failed: %m\n");
+ BUILD_ERROR(build, "pakfire_packager_finish() failed: %m\n");
goto ERROR;
}
static int pakfire_build_package_dump(struct pakfire* pakfire,
struct pakfire_package* pkg, void* p) {
+ struct pakfire_build* build = p;
+
char* dump = pakfire_package_dump(pkg, PAKFIRE_PKG_DUMP_LONG);
if (!dump)
return 1;
- INFO(pakfire, "%s\n", dump);
+ BUILD_INFO(build, "%s\n", dump);
free(dump);
return 0;
static int pakfire_build_packages(struct pakfire_build* build,
struct pakfire_parser* makefile) {
- DEBUG(build->pakfire, "Creating packages...");
+ BUILD_INFO(build, "Creating packages...");
int r = 1;
const char* buildroot = pakfire_relpath(build->pakfire, build->buildroot);
// Fetch a list all all packages
char** packages = pakfire_parser_list_namespaces(makefile, "packages.package:*");
if (!packages) {
- ERROR(build->pakfire, "Could not find any packages: %m\n");
+ BUILD_ERROR(build, "Could not find any packages: %m\n");
goto ERROR;
}
goto ERROR;
// Dump them all
- r = pakfire_packagelist_walk(build->packages, pakfire_build_package_dump, NULL);
+ r = pakfire_packagelist_walk(build->packages, pakfire_build_package_dump, build);
if (r)
goto ERROR;
// Create the build script
char* script = pakfire_parser_expand(makefile, "build", template);
if (!script) {
- ERROR(build->pakfire, "Could not generate the build script for stage '%s': %m\n",
- stage);
+ BUILD_ERROR(build, "Could not generate the build script for stage '%s': %m\n", stage);
goto ERROR;
}
- INFO(build->pakfire, "Running build stage '%s'\n", stage);
+ BUILD_INFO(build, "Running build stage '%s'\n", stage);
// Import environment
// XXX is this a good idea?
r = pakfire_jail_import_env(build->jail, (const char**)envp);
if (r) {
- ERROR(build->pakfire, "Could not import environment: %m\n");
+ BUILD_ERROR(build, "Could not import environment: %m\n");
goto ERROR;
}
// Run the script
r = pakfire_jail_exec_script(build->jail, script, strlen(script), NULL, NULL, NULL, NULL);
- if (r) {
- ERROR(build->pakfire, "Build stage '%s' failed with status %d\n", stage, r);
- }
+ if (r)
+ BUILD_ERROR(build, "Build stage '%s' failed with status %d\n", stage, r);
ERROR:
if (envp) {
if (!pakfire_filelist_is_empty(removees)) {
if (description)
- INFO(build->pakfire, "%s\n", description);
+ BUILD_INFO(build, "%s\n", description);
// Show all files which will be removed
pakfire_filelist_dump(removees, PAKFIRE_FILE_DUMP_FULL|PAKFIRE_FILE_DUMP_ISSUES);
// Check file for issues
r = pakfire_file_check(file, &issues);
if (r) {
- ERROR(pakfire, "%s: File Check failed: %m\n", pakfire_file_get_path(file));
+ //BUILD_ERROR(build, "%s: File Check failed: %m\n", pakfire_file_get_path(file));
return r;
}
// Create a filelist of all files in the build
r = pakfire_filelist_create(&filelist, build->pakfire);
if (r) {
- ERROR(build->pakfire, "Could not create filelist: %m\n");
+ BUILD_ERROR(build, "Could not create filelist: %m\n");
goto ERROR;
}
// Solve the transaction
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
- ERROR(build->pakfire, "Could not install build dependencies:\n%s\n", problems);
+ BUILD_ERROR(build, "Could not install build dependencies:\n%s\n", problems);
goto ERROR;
}
r = pakfire_read_makefile(parser, build->pakfire, path, &error);
if (r) {
if (error) {
- ERROR(build->pakfire, "Could not parse makefile %s: %s\n", path,
+ BUILD_ERROR(build, "Could not parse makefile %s: %s\n", path,
pakfire_parser_error_get_message(error));
} else {
- ERROR(build->pakfire, "Could not parse makefile %s: %m\n", path);
+ BUILD_ERROR(build, "Could not parse makefile %s: %m\n", path);
}
goto ERROR;
// Run post build checks
r = pakfire_build_run_post_build_checks(build);
if (r) {
- ERROR(build->pakfire, "Post build checks failed\n");
+ BUILD_ERROR(build, "Post build checks failed\n");
goto ERROR;
}
static int __pakfire_build_unpackaged_file(struct pakfire* pakfire,
struct pakfire_file* file, void* p) {
+ struct pakfire_build* build = p;
+
char* s = pakfire_file_dump(file, PAKFIRE_FILE_DUMP_FULL);
if (s) {
- ERROR(pakfire, "%s\n", s);
+ BUILD_ERROR(build, "%s\n", s);
free(s);
}
goto ERROR;
if (!pakfire_filelist_is_empty(filelist)) {
- ERROR(build->pakfire, "Unpackaged files found:\n");
+ BUILD_ERROR(build, "Unpackaged files found:\n");
- r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, NULL, 0);
+ r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, build, 0);
if (r)
goto ERROR;
// Dependency Error
case 2:
- ERROR(build->pakfire, "Install test failed:\n%s\n", problems);
+ BUILD_ERROR(build, "Install test failed:\n%s\n", problems);
break;
// Any other errors
default:
- ERROR(build->pakfire, "Install test failed: %m\n");
+ BUILD_ERROR(build, "Install test failed: %m\n");
goto ERROR;
}
r = pakfire_transaction_solve(transaction, 0, &problems);
if (r) {
if (problems)
- ERROR(build->pakfire, "Could not install the source package:\n%s\n", problems);
+ BUILD_ERROR(build, "Could not install the source package:\n%s\n", problems);
goto ERROR;
}
// Sanity check to see if we actually try to install anything
if (!changes) {
- ERROR(build->pakfire, "The source package did not get installed\n");
+ BUILD_ERROR(build, "The source package did not get installed\n");
r = 1;
goto ERROR;
}
// Perform an install check to see whether we can build this at all
r = pakfire_package_installcheck(package, &problems, 0);
if (r) {
- ERROR(build->pakfire, "Cannot build %s:\n%s\n", nevra, problems);
+ BUILD_ERROR(build, "Cannot build %s:\n%s\n", nevra, problems);
goto ERROR;
}
// Install the source package
r = pakfire_build_install_source_package(build, package);
if (r) {
- ERROR(build->pakfire, "Could not install the source package: %m\n");
+ BUILD_ERROR(build, "Could not install the source package: %m\n");
goto ERROR;
}
// Mount the ccache
r = pakfire_build_mount_ccache(build);
if (r) {
- ERROR(build->pakfire, "Could not mount the ccache: %m\n");
+ BUILD_ERROR(build, "Could not mount the ccache: %m\n");
goto ERROR;
}
// Create BUILDROOT
buildroot = pakfire_mkdtemp(build->buildroot);
if (!buildroot) {
- ERROR(build->pakfire, "Could not create BUILDROOT: %m\n");
+ BUILD_ERROR(build, "Could not create BUILDROOT: %m\n");
goto ERROR;
}
// Create the packages
r = pakfire_build_packages(build, makefile);
if (r) {
- ERROR(build->pakfire, "Could not create packages: %m\n");
+ BUILD_ERROR(build, "Could not create packages: %m\n");
goto ERROR;
}
if (r)
goto ERROR;
- INFO(build->pakfire, "Build successfully completed in %s\n", duration);
+ BUILD_INFO(build, "Build successfully completed in %s\n", duration);
ERROR:
if (makefile)