]> git.ozlabs.org Git - ccan/blob - tools/gcov.c
c36f69b09da87500ed9654b82234a33544f39bf4
[ccan] / tools / gcov.c
1 #include "tools.h"
2 #include <stdlib.h>
3 #include <stdarg.h>
4
5 const char *gcov; /* = NULL */
6
7 bool run_gcov(const void *ctx, unsigned int *time_ms, char **output,
8               const char *fmt, ...)
9 {
10         const char *cmd = gcov;
11         char *args;
12         va_list ap;
13         bool rc;
14
15         if (!gcov) {
16 #ifdef __GNUC__
17                 cmd = "gcov";
18 #endif
19         }
20
21         if (!cmd)
22                 return false;
23
24         va_start(ap, fmt);
25         args = tal_vfmt(ctx, fmt, ap);
26         rc = run_command(ctx, time_ms, output, "%s %s", cmd, args);
27         tal_free(args);
28         return rc;
29 }
30
31 const char *gcov_unavailable(void *ctx)
32 {
33         const char *err = NULL;
34
35         /* 
36          * If the user has specified a path, assume they know what
37          * they're doing
38          */
39         if (gcov)
40                 return NULL;
41
42 #ifdef __GNUC__
43         unsigned int timeleft = default_timeout_ms;
44         char *output;
45
46         if (!run_gcov(ctx, &timeleft, &output, "-h")) {
47                 err = tal_fmt(ctx, "No gcov support: %s", output);
48                 tal_free(output);
49         }
50 #else
51         err = "No coverage support for this compiler";
52 #endif
53
54         return err;
55 }