Skip to content

Commit fdb0603

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 424ae72 commit fdb0603

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
@@ -1202,7 +1202,20 @@ extern "C" {
12021202
int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);
12031203
int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);
12041204

1205-
const char *const *avr_get_buildinfo(void);
1205+
1206+
typedef struct avr_buildinfo_item {
1207+
const char *const key;
1208+
const char *const value;
1209+
} avr_buildinfo_item;
1210+
1211+
typedef struct avr_buildinfo {
1212+
const char *const name;
1213+
const char *const version;
1214+
avr_buildinfo_item items[];
1215+
} avr_buildinfo;
1216+
1217+
extern const avr_buildinfo libavrdude_buildinfo;
1218+
12061219

12071220
#ifdef __cplusplus
12081221
}

src/main.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,25 @@ static char usr_config[PATH_MAX]; // Per-user config file
232232

233233

234234
static
235-
const char *const avrdude_buildinfo[] = {
236-
AVRDUDE_FULL_VERSION,
237-
"buildsystem: " AVRDUDE_BUILDSYSTEM,
238-
NULL
235+
const avr_buildinfo avrdude_buildinfo = {
236+
"avrdude", AVRDUDE_FULL_VERSION,
237+
{
238+
{"buildsystem", AVRDUDE_BUILDSYSTEM},
239+
{NULL, NULL},
240+
}
239241
};
240242

241243

242-
static void print_buildinfos(const char *const *buildinfo)
244+
static void print_buildinfo(const avr_buildinfo *const buildinfo)
243245
{
244-
for (unsigned int i=1; buildinfo[i]; ++i) {
245-
msg_info("%3u. %s\n", i, buildinfo[i]);
246+
msg_info(" * %s %s\n",
247+
buildinfo->name, buildinfo->version);
248+
249+
for (unsigned int i=0; buildinfo->items[i].key; ++i) {
250+
if (buildinfo->items[i].value) {
251+
msg_info(" %3u. %s: %s\n", i,
252+
buildinfo->items[i].key, buildinfo->items[i].value);
253+
}
246254
}
247255
}
248256

@@ -254,12 +262,15 @@ static void print_version_message(void)
254262
msg_info("License GPL...\n");
255263
msg_info("This is free software...\n");
256264

257-
msg_info("avrdude %s\n", avrdude_buildinfo[0]);
258-
print_buildinfos(avrdude_buildinfo);
265+
const avr_buildinfo *const all_buildinfos[] = {
266+
&avrdude_buildinfo,
267+
&libavrdude_buildinfo,
268+
NULL,
269+
};
259270

260-
const char *const *libavrdude_buildinfo = avr_get_buildinfo();
261-
msg_info("libavrdude %s\n", libavrdude_buildinfo[0]);
262-
print_buildinfos(libavrdude_buildinfo);
271+
for (unsigned int i=0; all_buildinfos[i]; ++i) {
272+
print_buildinfo(all_buildinfos[i]);
273+
}
263274
}
264275

265276

0 commit comments

Comments
 (0)