]> git.ipfire.org Git - pakfire.git/commitdiff
stripper: Build scaffolding for a new stripper
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 23:48:56 +0000 (23:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 23:48:56 +0000 (23:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/build.c
src/libpakfire/include/pakfire/stripper.h [new file with mode: 0644]
src/libpakfire/stripper.c [new file with mode: 0644]

index cae8ae886f7c595093cc2949c4bb1b8bf7e05cca..88e004cd1be599a8a4ee8097ecbe080f354c7a9d 100644 (file)
@@ -229,6 +229,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/snapshot.c \
        src/libpakfire/solution.c \
        src/libpakfire/string.c \
+       src/libpakfire/stripper.c \
        src/libpakfire/transaction.c \
        src/libpakfire/util.c \
        src/libpakfire/xfer.c
@@ -282,6 +283,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/snapshot.h \
        src/libpakfire/include/pakfire/solution.h \
        src/libpakfire/include/pakfire/string.h \
+       src/libpakfire/include/pakfire/stripper.h \
        src/libpakfire/include/pakfire/transaction.h \
        src/libpakfire/include/pakfire/util.h \
        src/libpakfire/include/pakfire/xfer.h
index 521d8069b8fe477d2a125766a547e637161c583f..716cf22bd75d3ba04d774cfbb88ee3a9a68ac33d 100644 (file)
@@ -49,6 +49,7 @@
 #include <pakfire/scriptlet.h>
 #include <pakfire/solution.h>
 #include <pakfire/string.h>
+#include <pakfire/stripper.h>
 #include <pakfire/transaction.h>
 #include <pakfire/util.h>
 
@@ -1323,6 +1324,27 @@ static int pakfire_build_run_post_build_scripts(struct pakfire_build* build) {
        return 0;
 }
 
+static int pakfire_build_strip(struct pakfire_build* build) {
+       struct pakfire_stripper* stripper = NULL;
+       int r;
+
+       // Create a new stripper
+       r = pakfire_stripper_create(&stripper, build->pakfire, build->buildroot);
+       if (r < 0)
+               goto ERROR;
+
+       // Strip!
+       r = pakfire_stripper_run(stripper);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (stripper)
+               pakfire_stripper_unref(stripper);
+
+       return r;
+}
+
 static void pakfire_build_free(struct pakfire_build* build) {
        if (build->packages)
                pakfire_packagelist_unref(build->packages);
@@ -1810,6 +1832,11 @@ static int pakfire_build_perform(struct pakfire_build* build,
        if (r)
                goto ERROR;
 
+       // Run the stripper
+       r = pakfire_build_strip(build);
+       if (r < 0)
+               goto ERROR;
+
        // Done!
        return 0;
 
diff --git a/src/libpakfire/include/pakfire/stripper.h b/src/libpakfire/include/pakfire/stripper.h
new file mode 100644 (file)
index 0000000..84d9dff
--- /dev/null
@@ -0,0 +1,37 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2024 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_STRIPPER_H
+#define PAKFIRE_STRIPPER_H
+
+#ifdef PAKFIRE_PRIVATE
+
+struct pakfire_stripper;
+
+int pakfire_stripper_create(struct pakfire_stripper** stripper,
+       struct pakfire* pakfire, const char* path);
+
+struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper);
+struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper);
+
+int pakfire_stripper_run(struct pakfire_stripper* stripper);
+
+#endif /* PAKFIRE_PRIVATE */
+#endif /* PAKFIRE_STRIPPER_H */
diff --git a/src/libpakfire/stripper.c b/src/libpakfire/stripper.c
new file mode 100644 (file)
index 0000000..d813294
--- /dev/null
@@ -0,0 +1,100 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pakfire/pakfire.h>
+#include <pakfire/string.h>
+#include <pakfire/stripper.h>
+
+struct pakfire_stripper {
+       struct pakfire_ctx* ctx;
+       int nrefs;
+
+       // Pakfire
+       struct pakfire* pakfire;
+
+       // Path
+       char path[PATH_MAX];
+
+       // Filelist
+       struct pakfire_filelist* filelist;
+};
+
+int pakfire_stripper_create(struct pakfire_stripper** stripper,
+               struct pakfire* pakfire, const char* path) {
+       struct pakfire_stripper* s = NULL;
+       int r;
+
+       // Allocate a new object
+       s = calloc(1, sizeof(*s));
+       if (!s)
+               return -errno;
+
+       // Store a reference to the context
+       s->ctx = pakfire_ctx(pakfire);
+
+       // Store a reference to Pakfire
+       s->pakfire = pakfire_ref(pakfire);
+
+       // Initialize the reference counter
+       s->nrefs = 1;
+
+       // Store the path
+       r = pakfire_string_set(s->path, path);
+       if (r < 0)
+               goto ERROR;
+
+       // Return the pointer
+       *stripper = pakfire_stripper_ref(s);
+
+ERROR:
+       if (s)
+               pakfire_stripper_unref(s);
+
+       return r;
+}
+
+static void pakfire_stripper_free(struct pakfire_stripper* stripper) {
+       if (stripper->pakfire)
+               pakfire_unref(stripper->pakfire);
+       if (stripper->ctx)
+               pakfire_ctx_unref(stripper->ctx);
+       free(stripper);
+}
+
+struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper) {
+       ++stripper->nrefs;
+
+       return stripper;
+}
+
+struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper) {
+       if (--stripper->nrefs > 0)
+               return stripper;
+
+       pakfire_stripper_free(stripper);
+       return NULL;
+}
+
+int pakfire_stripper_run(struct pakfire_stripper* stripper) {
+       return 0; // TODO
+}