Skip to content

Commit

Permalink
XXX POC key value structured buildinfo for avrdude, libavrdude
Browse files Browse the repository at this point in the history
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")
  • Loading branch information
ndim committed Aug 7, 2024
1 parent ae419f5 commit 2e08789
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 35 deletions.
101 changes: 79 additions & 22 deletions src/buildinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 19 additions & 1 deletion src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
41 changes: 29 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand All @@ -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]);
}
}


Expand Down

0 comments on commit 2e08789

Please sign in to comment.