From: Michael Tremer Date: Sat, 30 Sep 2023 11:52:38 +0000 (+0000) Subject: build: Send all build-related stuff to the build logger X-Git-Tag: 0.9.30~1591 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b49cad5152fc996b870113892018775a621f419;p=pakfire.git build: Send all build-related stuff to the build logger Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 03b4cbf9f..269655477 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -132,9 +132,11 @@ struct pakfire_build { #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; @@ -170,12 +172,12 @@ static int __pakfire_build_setup_repo(struct pakfire* pakfire, 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; } @@ -187,14 +189,14 @@ static int __pakfire_build_setup_repo(struct pakfire* pakfire, // 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; } @@ -206,7 +208,7 @@ static int __pakfire_build_setup_repo(struct pakfire* pakfire, 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; } } @@ -255,19 +257,19 @@ static int pakfire_build_read_script(struct pakfire_build* build, 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; } @@ -290,7 +292,7 @@ static int pakfire_build_run_script( 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); @@ -302,9 +304,8 @@ static int pakfire_build_run_script( // 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); @@ -313,6 +314,7 @@ static int pakfire_build_run_script( } struct pakfire_find_deps_ctx { + struct pakfire_build* build; struct pakfire_package* pkg; int dep; struct pakfire_scriptlet* scriptlet; @@ -418,7 +420,7 @@ static int pakfire_build_process_deps(struct pakfire* pakfire, 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) { @@ -454,18 +456,18 @@ static int pakfire_build_process_deps(struct pakfire* pakfire, // 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; } @@ -474,21 +476,21 @@ static int pakfire_build_process_deps(struct pakfire* pakfire, // 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) @@ -508,6 +510,7 @@ static int pakfire_build_find_deps(struct pakfire_build* build, 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, @@ -535,7 +538,7 @@ static int pakfire_build_find_deps(struct pakfire_build* build, 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; } @@ -674,7 +677,7 @@ static int pakfire_build_package_add_files(struct pakfire_build* build, 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)) @@ -686,7 +689,7 @@ static int pakfire_build_package_add_files(struct pakfire_build* build, // 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; } @@ -743,6 +746,7 @@ static int pakfire_build_add_scriptlet_requires(struct pakfire_build* build, int r; struct pakfire_find_deps_ctx ctx = { + .build = build, .pkg = pkg, .dep = PAKFIRE_PKG_PREREQUIRES, .scriptlet = scriptlet, @@ -778,14 +782,14 @@ static int pakfire_build_package_add_scriptlet(struct pakfire_build* build, // 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; } @@ -844,8 +848,8 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par 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); @@ -855,7 +859,7 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par // 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; } @@ -913,7 +917,7 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par // 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; } @@ -938,11 +942,13 @@ 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; @@ -950,7 +956,7 @@ static int pakfire_build_package_dump(struct pakfire* pakfire, 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); @@ -958,7 +964,7 @@ static int pakfire_build_packages(struct pakfire_build* build, // 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; } @@ -993,7 +999,7 @@ static int pakfire_build_packages(struct pakfire_build* build, 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; @@ -1022,26 +1028,24 @@ static int pakfire_build_stage(struct pakfire_build* build, // 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) { @@ -1085,7 +1089,7 @@ static int pakfire_build_post_process_files(struct pakfire_build* build, 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); @@ -1212,7 +1216,7 @@ static int __pakfire_build_post_check_files( // 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; } @@ -1243,7 +1247,7 @@ static int pakfire_build_run_post_build_checks(struct pakfire_build* build) { // 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; } @@ -1739,7 +1743,7 @@ static int pakfire_build_install_packages( // 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; } @@ -1823,10 +1827,10 @@ static int pakfire_build_read_makefile(struct pakfire_build* build, 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; @@ -1873,7 +1877,7 @@ static int pakfire_build_perform(struct pakfire_build* build, // 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; } @@ -1895,9 +1899,11 @@ 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); } @@ -1919,9 +1925,9 @@ static int pakfire_build_check_unpackaged_files(struct pakfire_build* build) { 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; @@ -1966,12 +1972,12 @@ static int pakfire_build_install_test(struct pakfire_build* build) { // 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; } @@ -2104,7 +2110,7 @@ static int pakfire_build_install_source_package( 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; } @@ -2114,7 +2120,7 @@ static int pakfire_build_install_source_package( // 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; } @@ -2170,7 +2176,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p // 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; } @@ -2182,21 +2188,21 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p // 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; } @@ -2213,7 +2219,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p // 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; } @@ -2232,7 +2238,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p 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)