]> git.ipfire.org Git - pakfire.git/commitdiff
package: Add source information
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 13:34:32 +0000 (13:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 May 2022 13:34:32 +0000 (13:34 +0000)
This patch adds support for storing the source package name, evr and
architecture in the metadata.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/package.c
src/libpakfire/archive.c
src/libpakfire/build.c
src/libpakfire/db.c
src/libpakfire/dist.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/libpakfire.sym
src/libpakfire/package.c

index 63639f9e2e52ea72aac25f3266a3f12c9440b458..5c79c01c799e40c1f4e6d0ce1a8f98d972bddd3a 100644 (file)
@@ -673,6 +673,54 @@ static PyObject* Package_dump(PackageObject* self, PyObject *args, PyObject* kwd
        return PyUnicode_FromString(package_dump);
 }
 
+static PyObject* Package_get_source_package(PackageObject* self) {
+       const char* source_package = pakfire_package_get_source_package(self->package);
+
+       return PyUnicode_FromString(source_package);
+}
+
+static PyObject* Package_get_source_name(PackageObject* self) {
+       const char* source_name = pakfire_package_get_source_name(self->package);
+
+       return PyUnicode_FromString(source_name);
+}
+
+static PyObject* Package_set_source_name(PackageObject* self, PyObject* value) {
+       const char* source_name = PyUnicode_AsUTF8(value);
+
+       pakfire_package_set_source_name(self->package, source_name);
+
+       Py_RETURN_NONE;
+}
+
+static PyObject* Package_get_source_evr(PackageObject* self) {
+       const char* source_evr = pakfire_package_get_source_evr(self->package);
+
+       return PyUnicode_FromString(source_evr);
+}
+
+static PyObject* Package_set_source_evr(PackageObject* self, PyObject* value) {
+       const char* source_evr = PyUnicode_AsUTF8(value);
+
+       pakfire_package_set_source_evr(self->package, source_evr);
+
+       Py_RETURN_NONE;
+}
+
+static PyObject* Package_get_source_arch(PackageObject* self) {
+       const char* source_arch = pakfire_package_get_source_arch(self->package);
+
+       return PyUnicode_FromString(source_arch);
+}
+
+static PyObject* Package_set_source_arch(PackageObject* self, PyObject* value) {
+       const char* source_arch = PyUnicode_AsUTF8(value);
+
+       pakfire_package_set_source_arch(self->package, source_arch);
+
+       Py_RETURN_NONE;
+}
+
 static struct PyMethodDef Package_methods[] = {
        {
                "dump",
@@ -824,6 +872,34 @@ static struct PyGetSetDef Package_getsetters[] = {
                NULL,
                NULL
        },
+       {
+               "source_package",
+               (getter)Package_get_source_package,
+               NULL,
+               NULL,
+               NULL
+       },
+       {
+               "source_name",
+               (getter)Package_get_source_name,
+               (setter)Package_set_source_name,
+               NULL,
+               NULL
+       },
+       {
+               "source_evr",
+               (getter)Package_get_source_evr,
+               (setter)Package_set_source_evr,
+               NULL,
+               NULL
+       },
+       {
+               "source_arch",
+               (getter)Package_get_source_arch,
+               (setter)Package_set_source_arch,
+               NULL,
+               NULL
+       },
 
        // Dependencies
        {
index fe393834f19caef83075e77aade6dbe00b0d361a..4198212909060b3ba55417b3674c95f453d5b431 100644 (file)
@@ -2165,6 +2165,21 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv
        if (build_time)
                pakfire_package_set_build_time(pkg, build_time);
 
+       // Source package
+       const char* source_name = pakfire_archive_metadata_get(archive, "build", "source-name");
+       if (source_name)
+               pakfire_package_set_source_name(pkg, source_name);
+
+       // Source EVR
+       const char* source_evr = pakfire_archive_metadata_get(archive, "build", "source-evr");
+       if (source_evr)
+               pakfire_package_set_source_evr(pkg, source_evr);
+
+       // Source arch
+       const char* source_arch = pakfire_archive_metadata_get(archive, "build", "source-arch");
+       if (source_arch)
+               pakfire_package_set_source_arch(pkg, source_arch);
+
        // Dependencies
        const struct dependencies {
                const char* type;
index d3cf93d5563ae5454f74af82b7e8b1e1f85a89de..5e4d15c8b742baa8f03c4441e80a3eba9ccb339e 100644 (file)
@@ -479,6 +479,19 @@ static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser*
        // Set build ID
        pakfire_package_set_build_id_from_uuid(pkg, build_id);
 
+       // Set source package
+       const char* source_name = pakfire_parser_get(makefile, NULL, "name");
+       if (source_name)
+               pakfire_package_set_source_name(pkg, source_name);
+
+       // Set source EVR
+       const char* source_evr = pakfire_parser_get(makefile, NULL, "evr");
+       if (source_evr)
+               pakfire_package_set_source_evr(pkg, source_evr);
+
+       // Set source arch
+       pakfire_package_set_source_arch(pkg, "src");
+
        // Create a packager
        r = pakfire_packager_create(&packager, pakfire, pkg);
        if (r)
index 9b21a8b15377b1275f1f94b6e7ebd57c795245e1..23a878fe9becea7df7ae0da4d8b73a954a9e1ef0 100644 (file)
@@ -367,7 +367,10 @@ static int pakfire_db_create_schema(struct pakfire_db* db) {
                        "build_time     INTEGER, "
                        "installed      INTEGER, "
                        "userinstalled  INTEGER, "
-                       "repository     TEXT"
+                       "repository     TEXT, "
+                       "source_name    TEXT, "
+                       "source_evr     TEXT, "
+                       "source_arch    TEXT"
                ")");
        if (r)
                return 1;
@@ -1241,10 +1244,52 @@ int pakfire_db_add_package(struct pakfire_db* db,
        if (r)
                goto ERROR;
 
-       const char* sql = "INSERT INTO packages(name, evr, arch, groups, filename, size, "
-               "inst_size, digest, license, summary, description, uuid, "
-               "vendor, build_host, build_time, installed, repository, userinstalled) "
-               "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?)";
+       const char* sql = "INSERT INTO "
+               "packages("
+                       "name, "
+                       "evr, "
+                       "arch, "
+                       "groups, "
+                       "filename, "
+                       "size, "
+                       "inst_size, "
+                       "digest, "
+                       "license, "
+                       "summary, "
+                       "description, "
+                       "uuid, "
+                       "vendor, "
+                       "build_host, "
+                       "build_time, "
+                       "installed, "
+                       "repository, "
+                       "userinstalled, "
+                       "source_name, "
+                       "source_evr, "
+                       "source_arch"
+               ") VALUES("
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "CURRENT_TIMESTAMP, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?, "
+                       "?"
+               ")";
 
        // Prepare the statement
        r = sqlite3_prepare_v2(db->handle, sql, strlen(sql), &stmt, NULL);
@@ -1429,6 +1474,42 @@ int pakfire_db_add_package(struct pakfire_db* db,
                goto ERROR;
        }
 
+       // Source package name
+       const char* source_name = pakfire_package_get_source_name(pkg);
+       if (source_name) {
+               r = sqlite3_bind_text(stmt, 18, source_name, -1, NULL);
+               if (r)
+                       goto ERROR;
+       } else {
+               r = sqlite3_bind_null(stmt, 18);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Source EVR
+       const char* source_evr = pakfire_package_get_source_evr(pkg);
+       if (source_evr) {
+               r = sqlite3_bind_text(stmt, 19, source_evr, -1, NULL);
+               if (r)
+                       goto ERROR;
+       } else {
+               r = sqlite3_bind_null(stmt, 19);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Source arch
+       const char* source_arch = pakfire_package_get_source_arch(pkg);
+       if (source_arch) {
+               r = sqlite3_bind_text(stmt, 20, source_arch, -1, NULL);
+               if (r)
+                       goto ERROR;
+       } else {
+               r = sqlite3_bind_null(stmt, 20);
+               if (r)
+                       goto ERROR;
+       }
+
        // Run query
        do {
                r = sqlite3_step(stmt);
@@ -1754,6 +1835,21 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r
                }
        }
 
+       // Source package
+       const char* source_name = (const char*)sqlite3_column_text(stmt, 28);
+       if (source_name)
+               pakfire_package_set_source_name(pkg, source_name);
+
+       // Source EVR
+       const char* source_evr = (const char*)sqlite3_column_text(stmt, 29);
+       if (source_evr)
+               pakfire_package_set_source_evr(pkg, source_evr);
+
+       // Source arch
+       const char* source_arch = (const char*)sqlite3_column_text(stmt, 30);
+       if (source_arch)
+               pakfire_package_set_source_arch(pkg, source_arch);
+
        // Success
        r = 0;
 
@@ -1779,9 +1875,24 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo) {
 
        const char* sql =
                "SELECT "
-                       "name, evr, arch, id, groups, filename, size, inst_size, "
-                       "digest, license, summary, description, uuid, vendor, "
-                       "build_host, build_time, strftime('%s', installed) AS installed, userinstalled, "
+                       "name, "
+                       "evr, "
+                       "arch, "
+                       "id, "
+                       "groups, "
+                       "filename, "
+                       "size, "
+                       "inst_size, "
+                       "digest, "
+                       "license, "
+                       "summary, "
+                       "description, "
+                       "uuid, "
+                       "vendor, "
+                       "build_host, "
+                       "build_time, "
+                       "strftime('%s', installed) AS installed, "
+                       "userinstalled, "
                        "("
                                "SELECT group_concat(path, '\n') FROM files WHERE files.pkg = packages.id"
                        ") AS files, "
@@ -1820,7 +1931,10 @@ int pakfire_db_load(struct pakfire_db* db, struct pakfire_repo* repo) {
                        "("
                                "SELECT group_concat(dependency, '\n') FROM dependencies d "
                                        "WHERE d.pkg = packages.id AND d.type = 'enhances'"
-                       ") AS enhances "
+                       ") AS enhances, "
+                       "source_name, "
+                       "source_evr, "
+                       "source_arch "
                "FROM "
                        "packages"
                ";";
index 94664778c624988068c0c9c178abded7b2f043c7..a2f686c8cccb6d2505607648155604d79f047c04 100644 (file)
@@ -51,6 +51,9 @@ static int pakfire_makefile_set_defaults(struct pakfire* pakfire,
        // Set epoch
        pakfire_parser_set(parser, NULL, "epoch", "0", 0);
 
+       // Set EVR
+       pakfire_parser_set(parser, NULL, "evr", "%{epoch}:%{version}-%{_release}", 0);
+
        // Set vendor
        pakfire_parser_set(parser, NULL, "vendor", "%{DISTRO_VENDOR}", 0);
 
index 30c1a4702b15969521ac6a6cfa859562007b3323..7ad9f04165f189939ff76e03f0630eef9703007b 100644 (file)
@@ -91,6 +91,13 @@ time_t pakfire_package_get_build_time(struct pakfire_package* pkg);
 void pakfire_package_set_build_time(struct pakfire_package* pkg, time_t build_time);
 time_t pakfire_package_get_install_time(struct pakfire_package* pkg);
 void pakfire_package_set_install_time(struct pakfire_package* pkg, time_t install_time);
+const char* pakfire_package_get_source_package(struct pakfire_package* pkg);
+const char* pakfire_package_get_source_name(struct pakfire_package* pkg);
+void pakfire_package_set_source_name(struct pakfire_package* pkg, const char* name);
+const char* pakfire_package_get_source_evr(struct pakfire_package* pkg);
+void pakfire_package_set_source_evr(struct pakfire_package* pkg, const char* evr);
+const char* pakfire_package_get_source_arch(struct pakfire_package* pkg);
+void pakfire_package_set_source_arch(struct pakfire_package* pkg, const char* arch);
 
 char** pakfire_package_get_provides(struct pakfire_package* pkg);
 char** pakfire_package_get_prerequires(struct pakfire_package* pkg);
index 884f0329e19b9e90a2784b29d601d1b496d5f5ee..9d380bc6f5f90401b90b181f28073623f65a5287 100644 (file)
@@ -172,6 +172,10 @@ global:
        pakfire_package_get_requires;
        pakfire_package_get_reverse_requires;
        pakfire_package_get_size;
+       pakfire_package_get_source_arch;
+       pakfire_package_get_source_evr;
+       pakfire_package_get_source_name;
+       pakfire_package_get_source_package;
        pakfire_package_get_suggests;
        pakfire_package_get_summary;
        pakfire_package_get_supplements;
@@ -198,6 +202,9 @@ global:
        pakfire_package_set_maintainer;
        pakfire_package_set_name;
        pakfire_package_set_path;
+       pakfire_package_set_source_arch;
+       pakfire_package_set_source_evr;
+       pakfire_package_set_source_name;
        pakfire_package_set_summary;
        pakfire_package_set_url;
        pakfire_package_set_uuid;
index 2ec931f53be0fca97eac3377c99da06a0b773ca3..77343182bd66223c5d0a8147dd96a938a48c04e1 100644 (file)
@@ -53,6 +53,7 @@ struct pakfire_package {
        struct pakfire_repo* repo;
 
        char nevra[NAME_MAX];
+       char source_nevra[NAME_MAX];
 
        char filename[NAME_MAX];
        char path[PATH_MAX];
@@ -742,6 +743,51 @@ PAKFIRE_EXPORT void pakfire_package_set_install_time(struct pakfire_package* pkg
        pakfire_package_set_num(pkg, SOLVABLE_INSTALLTIME, install_time);
 }
 
+PAKFIRE_EXPORT const char* pakfire_package_get_source_package(struct pakfire_package* pkg) {
+       if (!*pkg->source_nevra) {
+               const char* name = pakfire_package_get_source_name(pkg);
+               const char* evr  = pakfire_package_get_source_evr(pkg);
+               const char* arch = pakfire_package_get_source_arch(pkg);
+
+               // Return nothing if we don't have all information
+               if (!name || !evr || !arch)
+                       return NULL;
+
+               // Format package name
+               pakfire_string_format(pkg->source_nevra, "%s-%s.%s", name, evr, arch);
+       }
+
+       return pkg->source_nevra;
+}
+
+PAKFIRE_EXPORT const char* pakfire_package_get_source_name(struct pakfire_package* pkg) {
+       return pakfire_package_get_string(pkg, SOLVABLE_SOURCENAME);
+}
+
+PAKFIRE_EXPORT void pakfire_package_set_source_name(struct pakfire_package* pkg, const char* name) {
+       pakfire_package_set_string(pkg, SOLVABLE_SOURCENAME, name);
+}
+
+PAKFIRE_EXPORT const char* pakfire_package_get_source_evr(struct pakfire_package* pkg) {
+       return pakfire_package_get_string(pkg, SOLVABLE_SOURCEEVR);
+}
+
+PAKFIRE_EXPORT void pakfire_package_set_source_evr(struct pakfire_package* pkg, const char* evr) {
+       // Skip empty epoch
+       if (pakfire_string_startswith(evr, "0:"))
+               evr += 2;
+
+       pakfire_package_set_string(pkg, SOLVABLE_SOURCEEVR, evr);
+}
+
+PAKFIRE_EXPORT const char* pakfire_package_get_source_arch(struct pakfire_package* pkg) {
+       return pakfire_package_get_string(pkg, SOLVABLE_SOURCEARCH);
+}
+
+PAKFIRE_EXPORT void pakfire_package_set_source_arch(struct pakfire_package* pkg, const char* arch) {
+       pakfire_package_set_string(pkg, SOLVABLE_SOURCEARCH, arch);
+}
+
 static char** pakfire_package_get_relationlist(
                struct pakfire_package* pkg, Id type, Id marker) {
        char** array = NULL;
@@ -1105,6 +1151,11 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags
                                break;
                }
 
+               // Source package
+               const char* source_package = pakfire_package_get_source_package(pkg);
+               if (source_package)
+                       pakfire_package_dump_add_line(&string, _("Source Package"), source_package);
+
                // Build time
                time_t build_time = pakfire_package_get_build_time(pkg);
                pakfire_package_dump_add_line_date(&string, _("Build Time"), build_time);
@@ -1507,6 +1558,30 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg,
                        goto ERROR;
        }
 
+       // Source package name
+       const char* name = pakfire_package_get_source_name(pkg);
+       if (name) {
+               r = pakfire_json_add_string(pkg->pakfire, object, "source-name", name);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Source package EVR
+       const char* evr = pakfire_package_get_source_evr(pkg);
+       if (evr) {
+               r = pakfire_json_add_string(pkg->pakfire, object, "source-evr", evr);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Source package arch
+       const char* arch = pakfire_package_get_source_arch(pkg);
+       if (arch) {
+               r = pakfire_json_add_string(pkg->pakfire, object, "source-arch", arch);
+               if (r)
+                       goto ERROR;
+       }
+
        // Add object
        r = json_object_object_add(md, "build", object);
        if (r)