From 2e08789ef6e0bad7aed30f7e16db603c10f1b382 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 Perhaps get rid of the "extra" field, and define the first (key, value) tuple as (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 | 20 +++++++++- src/main.c | 41 +++++++++++++------ 3 files changed, 127 insertions(+), 35 deletions(-) diff --git a/src/buildinfo.c b/src/buildinfo.c index b00b16578..387aecb29 100644 --- a/src/buildinfo.c +++ b/src/buildinfo.c @@ -2,50 +2,107 @@ #include "ac_cfg.h" -static -const char *const libavrdude_buildinfo[] = { - AVRDUDE_FULL_VERSION, - "buildsystem: " AVRDUDE_BUILDSYSTEM, + +const avr_buildinfo libavrdude_buildinfo = { + {"libavrdude", AVRDUDE_FULL_VERSION, NULL}, + { + {"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 20f47bf5d..9f2485cab 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1184,7 +1184,25 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM 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_package { + const char *const name; + const char *const version; + const char *const extra; +} avr_buildinfo_package; + +typedef struct avr_buildinfo_item { + const char *const key; + const char *const value; +} avr_buildinfo_item; + +typedef struct avr_buildinfo { + avr_buildinfo_package package; + 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 5ebc5f38f..fb1b32b6f 100644 --- a/src/main.c +++ b/src/main.c @@ -220,17 +220,31 @@ 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, NULL}, + { + {"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]); + if (buildinfo->package.extra) { + msg_info(" * %s %s [%s]\n", + buildinfo->package.name, buildinfo->package.version, + buildinfo->package.extra); + } else { + msg_info(" * %s %s\n", + buildinfo->package.name, buildinfo->package.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); + } } } @@ -242,12 +256,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]); + } }