From: Michael Tremer Date: Mon, 24 May 2021 14:38:50 +0000 (+0000) Subject: build: Compile filelists for packaging X-Git-Tag: 0.9.28~1285^2~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73543ae3b7c8cedc4ae471f0ba6a6797a9076b66;p=pakfire.git build: Compile filelists for packaging Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 5ea118fa8..b79a7a6b8 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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) {