Skip to content

Commit fedf11b

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

File tree

3 files changed

+116
-35
lines changed

3 files changed

+116
-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,
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,20 @@ 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_item {
1189+
const char *const key;
1190+
const char *const value;
1191+
} avr_buildinfo_item;
1192+
1193+
typedef struct avr_buildinfo {
1194+
const char *const name;
1195+
const char *const version;
1196+
avr_buildinfo_item items[];
1197+
} avr_buildinfo;
1198+
1199+
extern const avr_buildinfo libavrdude_buildinfo;
1200+
11881201

11891202
#ifdef __cplusplus
11901203
}

src/main.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,25 @@ 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,
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+
msg_info(" * %s %s\n",
235+
buildinfo->name, buildinfo->version);
236+
237+
for (unsigned int i=0; buildinfo->items[i].key; ++i) {
238+
if (buildinfo->items[i].value) {
239+
msg_info(" %3u. %s: %s\n", i,
240+
buildinfo->items[i].key, buildinfo->items[i].value);
241+
}
234242
}
235243
}
236244

@@ -242,12 +250,15 @@ static void print_version_message(void)
242250
msg_info("License GPL...\n");
243251
msg_info("This is free software...\n");
244252

245-
msg_info("avrdude %s\n", avrdude_buildinfo[0]);
246-
print_buildinfos(avrdude_buildinfo);
253+
const avr_buildinfo *const all_buildinfos[] = {
254+
&avrdude_buildinfo,
255+
&libavrdude_buildinfo,
256+
NULL,
257+
};
247258

248-
const char *const *libavrdude_buildinfo = avr_get_buildinfo();
249-
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
250-
print_buildinfos(libavrdude_buildinfo);
259+
for (unsigned int i=0; all_buildinfos[i]; ++i) {
260+
print_buildinfo(all_buildinfos[i]);
261+
}
251262
}
252263

253264

0 commit comments

Comments
 (0)