]> git.ipfire.org Git - pakfire.git/commitdiff
build: Replace (most of) the legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 17:05:11 +0000 (17:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 17:05:11 +0000 (17:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index a056e3d433a2a9cbd523526f21e13fa105351cc5..9445a29d9c30958bbdf4fea7b72fda4a85a81642 100644 (file)
@@ -316,7 +316,7 @@ static int pakfire_build_read_script(struct pakfire_build* build,
        // Compose the source path
        r = pakfire_path_append(path, PAKFIRE_SCRIPTS_DIR, filename);
        if (r) {
-               ERROR(build->pakfire, "Could not compose path for script '%s': %m\n", filename);
+               CTX_ERROR(build->ctx, "Could not compose path for script '%s': %m\n", filename);
                goto ERROR;
        }
 
@@ -357,7 +357,7 @@ static int pakfire_build_run_script(
        // Read the script
        r = pakfire_build_read_script(build, filename, &script, &length);
        if (r) {
-               ERROR(build->pakfire, "Could not read script %s: %m\n", filename);
+               CTX_ERROR(build->ctx, "Could not read script %s: %m\n", filename);
                return r;
        }
 
@@ -396,7 +396,7 @@ static int pakfire_build_make_filter(struct pakfire_build* build, pcre2_code** r
        if (!pattern || !*pattern)
                goto ERROR;
 
-       DEBUG(build->pakfire, "Found filter for %s: %s\n", filter, pattern);
+       CTX_DEBUG(build->ctx, "Found filter for %s: %s\n", filter, pattern);
 
        // Compile the regular expression
        r = pakfire_compile_regex(build->pakfire, regex, pattern);
@@ -574,7 +574,7 @@ static int pakfire_build_find_deps(struct pakfire_build* build,
 
        // Skip calling the script if class doesn't match
        if (class && !pakfire_filelist_matches_class(filelist, class)) {
-               DEBUG(build->pakfire, "Skipping calling %s as class does not match\n", script);
+               CTX_DEBUG(build->ctx, "Skipping calling %s as class does not match\n", script);
                return 0;
        }
 
@@ -607,7 +607,7 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
        r = pakfire_build_make_filter(build, &filter_provides,
                makefile, namespace, "filter_provides");
        if (r) {
-               ERROR(build->pakfire, "Provides filter is broken: %m\n");
+               CTX_ERROR(build->ctx, "Provides filter is broken: %m\n");
                goto ERROR;
        }
 
@@ -615,7 +615,7 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
        r = pakfire_build_make_filter(build, &filter_requires,
                makefile, namespace, "filter_requires");
        if (r) {
-               ERROR(build->pakfire, "Requires filter is broken: %m\n");
+               CTX_ERROR(build->ctx, "Requires filter is broken: %m\n");
                goto ERROR;
        }
 
@@ -901,7 +901,7 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par
        // Expand the handle into the package name
        char* name = pakfire_parser_expand(makefile, "packages", namespace);
        if (!name) {
-               ERROR(build->pakfire, "Could not get package name: %m\n");
+               CTX_ERROR(build->ctx, "Could not get package name: %m\n");
                goto ERROR;
        }
 
@@ -1031,7 +1031,7 @@ static int pakfire_build_packages(struct pakfire_build* build,
        for (char** package = packages; *package; package++)
                num_packages++;
 
-       DEBUG(build->pakfire, "Found %u package(s)\n", num_packages);
+       CTX_DEBUG(build->ctx, "Found %u package(s)\n", num_packages);
 
        // Build packages in reverse order
        for (int i = num_packages - 1; i >= 0; i--) {
@@ -1317,7 +1317,7 @@ static int pakfire_build_run_post_build_checks(struct pakfire_build* build) {
 
        // If the filelist is empty, we can are done
        if (pakfire_filelist_is_empty(filelist)) {
-               DEBUG(build->pakfire, "Empty BUILDROOT. Skipping post build checks...\n");
+               CTX_DEBUG(build->ctx, "Empty BUILDROOT. Skipping post build checks...\n");
                r = 0;
                goto ERROR;
        }
@@ -1408,7 +1408,7 @@ static int pakfire_build_parse_id(struct pakfire_build* build, const char* id) {
        if (id) {
                r = uuid_parse(id, build->id);
                if (r) {
-                       ERROR(build->pakfire, "Could not parse build ID '%s'\n", id);
+                       CTX_ERROR(build->ctx, "Could not parse build ID '%s'\n", id);
                        return -EINVAL;
                }
 
@@ -1434,7 +1434,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
        // Compose path
        r = pakfire_string_format(path, "pakfire/build-%s", build->_id);
        if (r) {
-               ERROR(build->pakfire, "Could not compose path for cgroup: %m\n");
+               CTX_ERROR(build->ctx, "Could not compose path for cgroup: %m\n");
                goto ERROR;
        }
 
@@ -1442,7 +1442,7 @@ static int pakfire_build_setup_cgroup(struct pakfire_build* build) {
        r = pakfire_cgroup_open(&build->cgroup, build->ctx, path,
                PAKFIRE_CGROUP_ENABLE_ACCOUNTING);
        if (r) {
-               ERROR(build->pakfire, "Could not create cgroup for build %s: %m\n", build->_id);
+               CTX_ERROR(build->ctx, "Could not create cgroup for build %s: %m\n", build->_id);
                goto ERROR;
        }
 
@@ -1493,21 +1493,21 @@ static int pakfire_build_setup_jail(struct pakfire_build* build) {
        // Create a new jail
        r = pakfire_jail_create(&build->jail, build->pakfire);
        if (r) {
-               ERROR(build->pakfire, "Could not create jail for build %s: %m\n", build->_id);
+               CTX_ERROR(build->ctx, "Could not create jail for build %s: %m\n", build->_id);
                return r;
        }
 
        // Connect the jail to our cgroup
        r = pakfire_jail_set_cgroup(build->jail, build->cgroup);
        if (r) {
-               ERROR(build->pakfire, "Could not set cgroup for jail: %m\n");
+               CTX_ERROR(build->ctx, "Could not set cgroup for jail: %m\n");
                return r;
        }
 
        // Build everything with a slightly lower priority
        r = pakfire_jail_nice(build->jail, 5);
        if (r) {
-               ERROR(build->pakfire, "Could not set nice level: %m\n");
+               CTX_ERROR(build->ctx, "Could not set nice level: %m\n");
                return r;
        }
 
@@ -1532,7 +1532,7 @@ static int pakfire_build_mount_ccache(struct pakfire_build* build) {
        // Make sure the path exists
        r = pakfire_mkdir(build->ccache_path, 0755);
        if (r) {
-               ERROR(build->pakfire, "Could not create %s: %m\n", build->ccache_path);
+               CTX_ERROR(build->ctx, "Could not create %s: %m\n", build->ccache_path);
                return r;
        }
 
@@ -1546,12 +1546,12 @@ static int pakfire_build_setup_ccache(struct pakfire_build* build) {
 
        // Check if we want a ccache
        if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_CCACHE)) {
-               DEBUG(build->pakfire, "ccache usage has been disabled for this build\n");
+               CTX_DEBUG(build->ctx, "ccache usage has been disabled for this build\n");
 
                // Set CCACHE_DISABLE=1 so that if ccache is installed, it will disable itself
                r = pakfire_jail_set_env(build->jail, "CCACHE_DISABLE", "1");
                if (r) {
-                       ERROR(build->pakfire, "Could not disable ccache: %m\n");
+                       CTX_ERROR(build->ctx, "Could not disable ccache: %m\n");
                        return r;
                }
 
@@ -1561,14 +1561,14 @@ static int pakfire_build_setup_ccache(struct pakfire_build* build) {
        // Set CCACHE_DIR
        r = pakfire_jail_set_env(build->jail, "CCACHE_DIR", CCACHE_DIR);
        if (r) {
-               ERROR(build->pakfire, "Could not set ccache directory: %m\n");
+               CTX_ERROR(build->ctx, "Could not set ccache directory: %m\n");
                return r;
        }
 
        // Set CCACHE_TEMPDIR
        r = pakfire_jail_set_env(build->jail, "CCACHE_TEMPDIR", "/tmp");
        if (r) {
-               ERROR(build->pakfire, "Could not set ccache tempdir: %m\n");
+               CTX_ERROR(build->ctx, "Could not set ccache tempdir: %m\n");
                return r;
        }
 
@@ -1588,7 +1588,7 @@ static int pakfire_build_setup_repo(struct pakfire_build* build) {
        // Create a new repository
        r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_RESULT);
        if (r) {
-               ERROR(build->pakfire, "Could not create repository %s: %m", PAKFIRE_REPO_RESULT);
+               CTX_ERROR(build->ctx, "Could not create repository %s: %m", PAKFIRE_REPO_RESULT);
                return r;
        }
 
@@ -1598,7 +1598,7 @@ static int pakfire_build_setup_repo(struct pakfire_build* build) {
        // Create a temporary directory
        const char* p = pakfire_mkdtemp(path);
        if (!p) {
-               ERROR(build->pakfire, "Could not create a the build repository: %m\n");
+               CTX_ERROR(build->ctx, "Could not create a the build repository: %m\n");
                return 1;
        }
 
@@ -1619,7 +1619,7 @@ static int pakfire_build_set_time_start(struct pakfire_build* build) {
        // Fetch current time
        r = clock_gettime(CLOCK_MONOTONIC, &build->time_start);
        if (r < 0)
-               ERROR(build->pakfire, "Could not fetch start time: %m\n");
+               CTX_ERROR(build->ctx, "Could not fetch start time: %m\n");
 
        return r;
 }
@@ -1779,7 +1779,7 @@ static int pakfire_build_init(struct pakfire_build* build) {
 
        // Don't do it again
        if (build->init) {
-               DEBUG(build->pakfire, "Build environment has already been initialized\n");
+               CTX_DEBUG(build->ctx, "Build environment has already been initialized\n");
                return 0;
        }
 
@@ -2056,7 +2056,7 @@ static int pakfire_build_copy_packages(struct pakfire_build* build) {
        struct pakfire_repo* local = NULL;
        int r = 0;
 
-       DEBUG(build->pakfire, "Copying built packages\n");
+       CTX_DEBUG(build->ctx, "Copying built packages\n");
 
        // Fetch local repository
        local = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
@@ -2174,7 +2174,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
 
        // Check if this package can be build in this environment
        if (!pakfire_package_supports_build_arch(package, arch)) {
-               ERROR(build->pakfire, "%s does not support being built on %s\n", nevra, arch);
+               CTX_ERROR(build->ctx, "%s does not support being built on %s\n", nevra, arch);
                r = -ENOTSUP;
                goto ERROR;
        }
@@ -2276,7 +2276,7 @@ static int pakfire_build_mkimage_install_deps(struct pakfire_build* build,
        // Create a new transaction
        r = pakfire_transaction_create(&transaction, build->pakfire, 0);
        if (r) {
-               ERROR(build->pakfire, "Could not create transaction: %m\n");
+               CTX_ERROR(build->ctx, "Could not create transaction: %m\n");
                goto ERROR;
        }
 
@@ -2284,14 +2284,14 @@ static int pakfire_build_mkimage_install_deps(struct pakfire_build* build,
        r = pakfire_transaction_request(transaction,
                        PAKFIRE_JOB_INSTALL, requires, PAKFIRE_JOB_ESSENTIAL);
        if (r) {
-               ERROR(build->pakfire, "Could not add '%s' to the transaction: %m\n", requires);
+               CTX_ERROR(build->ctx, "Could not add '%s' to the transaction: %m\n", requires);
                goto ERROR;
        }
 
        // Solve the request
        r = pakfire_transaction_solve(transaction, 0, &problems);
        if (r) {
-               ERROR(build->pakfire, "Could not solve the request:\n%s\n", problems);
+               CTX_ERROR(build->ctx, "Could not solve the request:\n%s\n", problems);
                goto ERROR;
        }
 
@@ -2318,7 +2318,7 @@ static int pakfire_build_collect_packages(struct pakfire_build* build, const cha
        // Create a new transaction
        r = pakfire_transaction_create(&transaction, build->pakfire, 0);
        if (r) {
-               ERROR(build->pakfire, "Could not create transaction: %m\n");
+               CTX_ERROR(build->ctx, "Could not create transaction: %m\n");
                goto ERROR;
        }
 
@@ -2327,20 +2327,20 @@ static int pakfire_build_collect_packages(struct pakfire_build* build, const cha
        r = pakfire_transaction_request(transaction,
                        PAKFIRE_JOB_INSTALL, "ipfire-release", PAKFIRE_JOB_ESSENTIAL);
        if (r) {
-               ERROR(build->pakfire, "Could not install 'ipfire-release': %m\n");
+               CTX_ERROR(build->ctx, "Could not install 'ipfire-release': %m\n");
                goto ERROR;
        }
 
        // Solve the transaction
        r = pakfire_transaction_solve(transaction, 0, &problems);
        if (r) {
-               ERROR(build->pakfire, "Could not solve request:\n%s\n", problems);
+               CTX_ERROR(build->ctx, "Could not solve request:\n%s\n", problems);
                goto ERROR;
        }
 
        // Empty transaction?
        if (!pakfire_transaction_count(transaction)) {
-               ERROR(build->pakfire, "The transaction is unexpectedly empty\n");
+               CTX_ERROR(build->ctx, "The transaction is unexpectedly empty\n");
                r = 1;
                goto ERROR;
        }
@@ -2348,25 +2348,25 @@ static int pakfire_build_collect_packages(struct pakfire_build* build, const cha
        // Dump the transaction
        p = pakfire_transaction_dump(transaction, 80);
        if (!p) {
-               ERROR(build->pakfire, "Could not dump the transaction: %m\n");
+               CTX_ERROR(build->ctx, "Could not dump the transaction: %m\n");
                r = 1;
                goto ERROR;
        }
 
        // Log the dump
-       INFO(build->pakfire, "%s\n", p);
+       CTX_INFO(build->ctx, "%s\n", p);
 
        // Download all packages
        r = pakfire_transaction_download(transaction);
        if (r) {
-               ERROR(build->pakfire, "Could not download the transaction: %m\n");
+               CTX_ERROR(build->ctx, "Could not download the transaction: %m\n");
                goto ERROR;
        }
 
        // Create a repository with all packages in this transaction
        r = pakfire_transaction_compose_repo(transaction, NULL, path);
        if (r) {
-               ERROR(build->pakfire, "Could not create repository: %m\n");
+               CTX_ERROR(build->ctx, "Could not create repository: %m\n");
                goto ERROR;
        }
 
@@ -2404,7 +2404,7 @@ PAKFIRE_EXPORT int pakfire_build_mkimage(struct pakfire_build* build,
        // Allocate a temporary file
        t = pakfire_mktemp(path, 0600);
        if (!t) {
-               ERROR(build->pakfire, "Could not allocate a temporary file: %m\n");
+               CTX_ERROR(build->ctx, "Could not allocate a temporary file: %m\n");
                r = 1;
                goto ERROR;
        }
@@ -2469,6 +2469,8 @@ int pakfire_build_clean(struct pakfire* pakfire, int flags) {
        struct pakfire_repo* local = NULL;
        int r = 0;
 
+       #warning Requires the legacy logger here... :(
+
        // Fetch local repository
        local = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
        if (!local) {
@@ -2508,7 +2510,7 @@ static int pakfire_build_install(struct pakfire_build* build, const char** packa
        // Solve the transaction
        r = pakfire_transaction_solve(transaction, 0, &problems);
        if (r) {
-               ERROR(build->pakfire, "Could not install packages:\n%s\n", problems);
+               CTX_ERROR(build->ctx, "Could not install packages:\n%s\n", problems);
                goto ERROR;
        }