From ab7d9dc964177b3731b7c6cae49f9b397ca6f66f Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Wed, 7 Aug 2024 02:40:17 +0200 Subject: [PATCH] XXX POC key value structured buildinfo for avrdude, libavrdude XXX Define the first (key, value) tuple to be (package_name, package_version)? If there is any extra information, we can always later add a (key,value) tuple like e.g. ("git branch", "main") --- src/buildinfo.c | 101 ++++++++++++++++++++++++++++++++++++----------- src/libavrdude.h | 15 ++++++- src/main.c | 35 ++++++++++------ 3 files changed, 116 insertions(+), 35 deletions(-) diff --git a/src/buildinfo.c b/src/buildinfo.c index e551c513e..03cedeb77 100644 --- a/src/buildinfo.c +++ b/src/buildinfo.c @@ -2,50 +2,107 @@ #include -static -const char *const libavrdude_buildinfo[] = { - AVRDUDE_FULL_VERSION, - "buildsystem: " AVRDUDE_BUILDSYSTEM, + +const avr_buildinfo libavrdude_buildinfo = { + "libavrdude", AVRDUDE_FULL_VERSION, + { + {"buildsystem", AVRDUDE_BUILDSYSTEM}, + + {"libelf", #ifdef HAVE_LIBELF - "libelf", + "yes" +#else + NULL #endif + }, + + {"libusb", #ifdef HAVE_LIBUSB - "libusb", + "yes" +#else + NULL #endif + }, + + {"libusb_1_0", #ifdef HAVE_LIBUSB_1_0 - "libusb_1_0", + "yes" +#else + NULL #endif + }, + + {"libhidapi", #ifdef HAVE_LIBHIDAPI - "libhidapi", + "yes" +#else + NULL #endif + }, + + {"libhid", #ifdef HAVE_LIBHID - "libhid", + "yes" +#else + NULL #endif + }, + + {"libftdi", #ifdef HAVE_LIBFTDI - "libftdi", + "yes" +#else + NULL #endif + }, + + {"libftdi1", #ifdef HAVE_LIBFTDI1 - "libftdi1", + "yes" +#else + NULL #endif + }, + + {"libreadline", #ifdef HAVE_LIBREADLINE - "libreadline", + "yes" +#else + NULL #endif + }, + + {"libserialport", #ifdef HAVE_LIBSERIALPORT - "libserialport", + "yes" +#else + NULL #endif + }, + + {"parport", #ifdef HAVE_PARPORT - "parport", + "yes" +#else + NULL #endif + }, + + {"linuxgpio", #ifdef HAVE_LINUXGPIO - "linuxgpio", + "yes" +#else + NULL #endif + }, + + {"linuxspi", #ifdef HAVE_LINUXSPI - "linuxspi", + "yes" +#else + NULL #endif - NULL + }, + {NULL, NULL}, + }, }; - -const char *const *avr_get_buildinfo(void) -{ - return libavrdude_buildinfo; -} diff --git a/src/libavrdude.h b/src/libavrdude.h index b099c53b7..81a459042 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1202,7 +1202,20 @@ extern "C" { int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p); int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p); -const char *const *avr_get_buildinfo(void); + +typedef struct avr_buildinfo_item { + const char *const key; + const char *const value; +} avr_buildinfo_item; + +typedef struct avr_buildinfo { + const char *const name; + const char *const version; + avr_buildinfo_item items[]; +} avr_buildinfo; + +extern const avr_buildinfo libavrdude_buildinfo; + #ifdef __cplusplus } diff --git a/src/main.c b/src/main.c index 2cff32e0c..5517b9f95 100644 --- a/src/main.c +++ b/src/main.c @@ -232,17 +232,25 @@ static char usr_config[PATH_MAX]; // Per-user config file static -const char *const avrdude_buildinfo[] = { - AVRDUDE_FULL_VERSION, - "buildsystem: " AVRDUDE_BUILDSYSTEM, - NULL +const avr_buildinfo avrdude_buildinfo = { + "avrdude", AVRDUDE_FULL_VERSION, + { + {"buildsystem", AVRDUDE_BUILDSYSTEM}, + {NULL, NULL}, + } }; -static void print_buildinfos(const char *const *buildinfo) +static void print_buildinfo(const avr_buildinfo *const buildinfo) { - for (unsigned int i=1; buildinfo[i]; ++i) { - msg_info("%3u. %s\n", i, buildinfo[i]); + msg_info(" * %s %s\n", + buildinfo->name, buildinfo->version); + + for (unsigned int i=0; buildinfo->items[i].key; ++i) { + if (buildinfo->items[i].value) { + msg_info(" %3u. %s: %s\n", i, + buildinfo->items[i].key, buildinfo->items[i].value); + } } } @@ -254,12 +262,15 @@ static void print_version_message(void) msg_info("License GPL...\n"); msg_info("This is free software...\n"); - msg_info("avrdude %s\n", avrdude_buildinfo[0]); - print_buildinfos(avrdude_buildinfo); + const avr_buildinfo *const all_buildinfos[] = { + &avrdude_buildinfo, + &libavrdude_buildinfo, + NULL, + }; - const char *const *libavrdude_buildinfo = avr_get_buildinfo(); - msg_info("libavrdude %s\n", libavrdude_buildinfo[0]); - print_buildinfos(libavrdude_buildinfo); + for (unsigned int i=0; all_buildinfos[i]; ++i) { + print_buildinfo(all_buildinfos[i]); + } }