]> git.ipfire.org Git - pakfire.git/commitdiff
build: Abort if there are any unpackaged files
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Sep 2022 19:15:47 +0000 (19:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Sep 2022 19:15:47 +0000 (19:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index e26a3f0a493696a20fd78f14d4016cd62aec82f1..1b026d4badf27f3bd3b0deb41a9703c632f31073 100644 (file)
@@ -519,6 +519,7 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par
        }
 
        INFO(build->pakfire, "Building package '%s'...\n", name);
+       DEBUG(build->pakfire, "  buildroot = %s\n", buildroot);
 
        // Fetch build architecture
        const char* arch = pakfire_get_arch(build->pakfire);
@@ -1220,6 +1221,60 @@ ERROR:
        return r;
 }
 
+static int __pakfire_build_unpackaged_file(struct pakfire* pakfire,
+               struct pakfire_file* file, void* p) {
+       char* s = pakfire_file_dump(file);
+       if (s)
+               ERROR(pakfire, "%s\n", s);
+
+       return 0;
+}
+
+static int pakfire_build_check_unpackaged_files(struct pakfire_build* build) {
+       struct pakfire_filelist* filelist = NULL;
+       int r;
+
+       // Create a new filelist
+       r = pakfire_filelist_create(&filelist, build->pakfire);
+       if (r)
+               goto ERROR;
+
+       // Scan for all files in BUILDROOT
+       r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL);
+       if (r)
+               goto ERROR;
+
+       const size_t length = pakfire_filelist_size(filelist);
+
+       if (length) {
+               ERROR(build->pakfire, "Unpackaged files found:\n");
+
+               r = pakfire_filelist_walk(filelist, __pakfire_build_unpackaged_file, NULL);
+               if (r)
+                       goto ERROR;
+
+               // Report an error
+               r = 1;
+       }
+
+ERROR:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+
+       return r;
+}
+
+static int pakfire_build_post_check(struct pakfire_build* build) {
+       int r;
+
+       // Check for unpackaged files
+       r = pakfire_build_check_unpackaged_files(build);
+       if (r)
+               return r;
+
+       return 0;
+}
+
 PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
        struct pakfire_archive* archive = NULL;
        struct pakfire_package* package = NULL;
@@ -1291,6 +1346,11 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
                goto ERROR;
        }
 
+       // Perform post build checks
+       r = pakfire_build_post_check(build);
+       if (r)
+               goto ERROR;
+
 ERROR:
        if (makefile)
                pakfire_parser_unref(makefile);