Skip to content

Commit 2e08789

Browse files
committed
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")
1 parent ae419f5 commit 2e08789

File tree

3 files changed

+127
-35
lines changed

3 files changed

+127
-35
lines changed

src/buildinfo.c

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,107 @@
22

33
#include "ac_cfg.h"
44

5-
static
6-
const char *const libavrdude_buildinfo[] = {
7-
AVRDUDE_FULL_VERSION,
8-
"buildsystem: " AVRDUDE_BUILDSYSTEM,
5+
6+
const avr_buildinfo libavrdude_buildinfo = {
7+
{"libavrdude", AVRDUDE_FULL_VERSION, NULL},
8+
{
9+
{"buildsystem", AVRDUDE_BUILDSYSTEM},
10+
11+
{"libelf",
912
#ifdef HAVE_LIBELF
10-
"libelf",
13+
"yes"
14+
#else
15+
NULL
1116
#endif
17+
},
18+
19+
{"libusb",
1220
#ifdef HAVE_LIBUSB
13-
"libusb",
21+
"yes"
22+
#else
23+
NULL
1424
#endif
25+
},
26+
27+
{"libusb_1_0",
1528
#ifdef HAVE_LIBUSB_1_0
16-
"libusb_1_0",
29+
"yes"
30+
#else
31+
NULL
1732
#endif
33+
},
34+
35+
{"libhidapi",
1836
#ifdef HAVE_LIBHIDAPI
19-
"libhidapi",
37+
"yes"
38+
#else
39+
NULL
2040
#endif
41+
},
42+
43+
{"libhid",
2144
#ifdef HAVE_LIBHID
22-
"libhid",
45+
"yes"
46+
#else
47+
NULL
2348
#endif
49+
},
50+
51+
{"libftdi",
2452
#ifdef HAVE_LIBFTDI
25-
"libftdi",
53+
"yes"
54+
#else
55+
NULL
2656
#endif
57+
},
58+
59+
{"libftdi1",
2760
#ifdef HAVE_LIBFTDI1
28-
"libftdi1",
61+
"yes"
62+
#else
63+
NULL
2964
#endif
65+
},
66+
67+
{"libreadline",
3068
#ifdef HAVE_LIBREADLINE
31-
"libreadline",
69+
"yes"
70+
#else
71+
NULL
3272
#endif
73+
},
74+
75+
{"libserialport",
3376
#ifdef HAVE_LIBSERIALPORT
34-
"libserialport",
77+
"yes"
78+
#else
79+
NULL
3580
#endif
81+
},
82+
83+
{"parport",
3684
#ifdef HAVE_PARPORT
37-
"parport",
85+
"yes"
86+
#else
87+
NULL
3888
#endif
89+
},
90+
91+
{"linuxgpio",
3992
#ifdef HAVE_LINUXGPIO
40-
"linuxgpio",
93+
"yes"
94+
#else
95+
NULL
4196
#endif
97+
},
98+
99+
{"linuxspi",
42100
#ifdef HAVE_LINUXSPI
43-
"linuxspi",
101+
"yes"
102+
#else
103+
NULL
44104
#endif
45-
NULL
105+
},
106+
{NULL, NULL},
107+
},
46108
};
47-
48-
const char *const *avr_get_buildinfo(void)
49-
{
50-
return libavrdude_buildinfo;
51-
}

src/libavrdude.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,25 @@ int avr_page_erase_cached(const PROGRAMMER *pgm, const AVRPART *p, const AVRMEM
11841184
int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);
11851185
int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);
11861186

1187-
const char *const *avr_get_buildinfo(void);
1187+
1188+
typedef struct avr_buildinfo_package {
1189+
const char *const name;
1190+
const char *const version;
1191+
const char *const extra;
1192+
} avr_buildinfo_package;
1193+
1194+
typedef struct avr_buildinfo_item {
1195+
const char *const key;
1196+
const char *const value;
1197+
} avr_buildinfo_item;
1198+
1199+
typedef struct avr_buildinfo {
1200+
avr_buildinfo_package package;
1201+
avr_buildinfo_item items[];
1202+
} avr_buildinfo;
1203+
1204+
extern const avr_buildinfo libavrdude_buildinfo;
1205+
11881206

11891207
#ifdef __cplusplus
11901208
}

src/main.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,31 @@ static char usr_config[PATH_MAX]; // Per-user config file
220220

221221

222222
static
223-
const char *const avrdude_buildinfo[] = {
224-
AVRDUDE_FULL_VERSION,
225-
"buildsystem: " AVRDUDE_BUILDSYSTEM,
226-
NULL
223+
const avr_buildinfo avrdude_buildinfo = {
224+
{"avrdude", AVRDUDE_FULL_VERSION, NULL},
225+
{
226+
{"buildsystem", AVRDUDE_BUILDSYSTEM},
227+
{NULL, NULL},
228+
}
227229
};
228230

229231

230-
static void print_buildinfos(const char *const *buildinfo)
232+
static void print_buildinfo(const avr_buildinfo *const buildinfo)
231233
{
232-
for (unsigned int i=1; buildinfo[i]; ++i) {
233-
msg_info("%3u. %s\n", i, buildinfo[i]);
234+
if (buildinfo->package.extra) {
235+
msg_info(" * %s %s [%s]\n",
236+
buildinfo->package.name, buildinfo->package.version,
237+
buildinfo->package.extra);
238+
} else {
239+
msg_info(" * %s %s\n",
240+
buildinfo->package.name, buildinfo->package.version);
241+
}
242+
243+
for (unsigned int i=0; buildinfo->items[i].key; ++i) {
244+
if (buildinfo->items[i].value) {
245+
msg_info(" %3u. %s: %s\n", i,
246+
buildinfo->items[i].key, buildinfo->items[i].value);
247+
}
234248
}
235249
}
236250

@@ -242,12 +256,15 @@ static void print_version_message(void)
242256
msg_info("License GPL...\n");
243257
msg_info("This is free software...\n");
244258

245-
msg_info("avrdude %s\n", avrdude_buildinfo[0]);
246-
print_buildinfos(avrdude_buildinfo);
259+
const avr_buildinfo *const all_buildinfos[] = {
260+
&avrdude_buildinfo,
261+
&libavrdude_buildinfo,
262+
NULL,
263+
};
247264

248-
const char *const *libavrdude_buildinfo = avr_get_buildinfo();
249-
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
250-
print_buildinfos(libavrdude_buildinfo);
265+
for (unsigned int i=0; all_buildinfos[i]; ++i) {
266+
print_buildinfo(all_buildinfos[i]);
267+
}
251268
}
252269

253270

0 commit comments

Comments
 (0)