]> git.ipfire.org Git - pakfire.git/commitdiff
build: Compile filelists for packaging
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 May 2021 14:38:50 +0000 (14:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 May 2021 14:38:50 +0000 (14:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 5ea118fa818c8b2591cb8c0fd6ca5aff9f957b0a..b79a7a6b8bdcfa19de5ce8b8de6e56d488ae3ef0 100644 (file)
@@ -50,11 +50,101 @@ static const char* stages[] = {
        "\n" \
        "exit 0\n"
 
+static int append_to_array(const char*** array, const char* s) {
+       unsigned int length = 0;
+
+       // Determine the length of the existing array
+       if (*array) {
+               for (const char** element = *array; *element; element++)
+                       length++;
+       }
+
+       // Allocate space
+       *array = reallocarray(*array, length + 2, sizeof(**array));
+       if (!*array)
+               return 1;
+
+       // Append s and terminate the array
+       (*array)[length] = s;
+       (*array)[length + 1] = NULL;
+
+       return 0;
+}
+
+static int pakfire_build_package_add_files(Pakfire pakfire, PakfireParser makefile,
+               const char* namespace, struct pakfire_packager* packager) {
+       PakfireFilelist filelist = NULL;
+       char path[PATH_MAX];
+       int r = 1;
+
+       char** files = NULL;
+       const char** includes = NULL;
+       const char** excludes = NULL;
+
+       // Fetch filelist from makefile
+       files = pakfire_parser_get_split(makefile, namespace, "files", '\n');
+
+       // No files to package?
+       if (!files)
+               return 0;
+
+       // Fetch buildroot
+       char* buildroot = pakfire_parser_get(makefile, NULL, "BUILDROOT");
+       if (!buildroot)
+               goto ERROR;
+
+       // Convert to absolute path
+       pakfire_make_path(pakfire, path, buildroot);
+
+       // Split into includes and excludes
+       for (char** file = files; *file; file++) {
+               if (**file == '!')
+                       r = append_to_array(&excludes, *file);
+               else
+                       r = append_to_array(&includes, *file);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Allocate a new filelist
+       r = pakfire_filelist_create(&filelist, pakfire);
+       if (r)
+               goto ERROR;
+
+       // Scan for files
+       r = pakfire_filelist_scan(filelist, path, includes, excludes);
+       if (r)
+               goto ERROR;
+
+       size_t length = pakfire_filelist_size(filelist);
+       DEBUG(pakfire, "%zu file(s) found\n", length);
+
+       // XXX package everything
+
+ERROR:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+       if (files) {
+               for (char** file = files; *file; file++)
+                       free(*file);
+               free(files);
+       }
+       if (includes)
+               free(includes);
+       if (excludes)
+               free(excludes);
+       if (buildroot)
+               free(buildroot);
+
+       return r;
+}
+
 static int pakfire_build_package(Pakfire pakfire, PakfireParser makefile,
                const char* namespace, const char* target) {
        PakfireRepo repo = NULL;
        PakfirePackage pkg = NULL;
        struct pakfire_packager* packager = NULL;
+
        int r = 1;
 
        // Expand the handle into the package name
@@ -88,6 +178,11 @@ static int pakfire_build_package(Pakfire pakfire, PakfireParser makefile,
        if (r)
                goto ERROR;
 
+       // Add files
+       r = pakfire_build_package_add_files(pakfire, makefile, namespace, packager);
+       if (r)
+               goto ERROR;
+
 #ifdef ENABLE_DEBUG
        char* dump = pakfire_package_dump(pkg, PAKFIRE_PKG_DUMP_LONG);
        if (dump) {