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 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")
  • Loading branch information
ndim committed Sep 4, 2024
1 parent e1b2002 commit 8848265
Show file tree
Hide file tree
Showing 3 changed files with 116 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,
{
{"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;
}
15 changes: 14 additions & 1 deletion src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 23 additions & 12 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

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


Expand Down

0 comments on commit 8848265

Please sign in to comment.