Skip to content

Commit

Permalink
pkg_external_libs_version: new function
Browse files Browse the repository at this point in the history
Make libpkg expose itself its external libraries so the frontend
does not have to know about them
  • Loading branch information
bapt committed Nov 14, 2024
1 parent a9eccd9 commit 740f5c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions external/libcurl/Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ VPATH+= $(top_srcdir)/external/curl/lib/vauth
VPATH+= $(top_srcdir)/external/curl/lib/vquic

SRCS= \
version.c \
asyn-thread.c \
base64.c \
bufref.c \
Expand Down
3 changes: 3 additions & 0 deletions libpkg/pkg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ struct pkg_kv {
char *value;
};

typedef pkgvec_t(struct pkg_kv *) pkg_kvl_t;

/**
* The system-wide pkg(8) status: ie. is it a) installed or otherwise
* available on the sysem, b) database (local.sqlite) initialised and
Expand Down Expand Up @@ -1734,6 +1736,7 @@ struct pkg_kv *pkg_kvlist_next(struct pkg_kvlist_iterator *it);
struct pkg_stringlist_iterator *pkg_stringlist_iterator(struct pkg_stringlist *l);
const char *pkg_stringlist_next(struct pkg_stringlist_iterator *it);
struct pkg_el *pkg_get_element(struct pkg *p, pkg_attr a);
pkg_kvl_t *pkg_external_libs_version(void);

static inline void
pkg_get_s(struct pkg *p, pkg_attr a, const char **val)
Expand Down
20 changes: 20 additions & 0 deletions libpkg/pkg_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
#endif
#include <ucl.h>

#include <curl/curl.h>

#include <archive.h>
#include <sqlite3.h>
#include <openssl/crypto.h>

#include "pkg.h"
#include "private/pkg.h"
#include "private/event.h"
Expand Down Expand Up @@ -599,6 +605,20 @@ pkg_libversion(void)
return PKGVERSION;
}

pkg_kvl_t *
pkg_external_libs_version(void)
{
pkg_kvl_t *kvl = xcalloc(1, sizeof(*kvl));

pkgvec_push(kvl, pkg_kv_new("libcurl", curl_version()));
pkgvec_push(kvl, pkg_kv_new("libarchive", archive_version_string()));
pkgvec_push(kvl, pkg_kv_new("sqlite", sqlite3_libversion()));
pkgvec_push(kvl, pkg_kv_new("openssl", OpenSSL_version(OPENSSL_VERSION)));

return (kvl);
}


int
pkg_initialized(void)
{
Expand Down
15 changes: 6 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@
#include <pkg.h>
#include <tllist.h>
#include <xmalloc.h>
#include <curl/curl.h>

#include <archive.h>
#include <sqlite3.h>
#include <openssl/crypto.h>

#include "pkgcli.h"

Expand Down Expand Up @@ -371,6 +366,8 @@ static void
show_version_info(int version)
{
char *config;
pkg_kvl_t *lib;

if (version > 1)
printf("%-24s: ", "Version");

Expand All @@ -380,10 +377,10 @@ show_version_info(int version)
exit(EXIT_SUCCESS);

printf("%-24s: %s\n", "libpkg", pkg_libversion());
printf("%-24s: %s\n", "libcurl", curl_version());
printf("%-24s: %s\n", "libarchive", archive_version_string());
printf("%-24s: %s\n", "sqlite", sqlite3_libversion());
printf("%-24s: %s\n", "openssl", OpenSSL_version(OPENSSL_VERSION));

lib = pkg_external_lib_version();
for (size_t i = 0; i < lib->len; i++)
printf("%-24s: %s\n", lib->d[i]->key, lib->d[i]->value);

config = pkg_config_dump();
printf("%s\n", config);
Expand Down

0 comments on commit 740f5c1

Please sign in to comment.