]> git.ozlabs.org Git - ccan/blob - tools/gcov.c
Makefile: fix fastcheck.
[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 #if defined(__clang__)
17                 cmd = "llvm-cov gcov";
18 #elif defined(__GNUC__)
19                 cmd = "gcov";
20 #endif
21         }
22
23         if (!cmd)
24                 return false;
25
26         va_start(ap, fmt);
27         args = tal_vfmt(ctx, fmt, ap);
28         rc = run_command(ctx, time_ms, output, "%s %s", cmd, args);
29         tal_free(args);
30         return rc;
31 }
32
33 const char *gcov_unavailable(void *ctx)
34 {
35         const char *err = NULL;
36
37         /* 
38          * If the user has specified a path, assume they know what
39          * they're doing
40          */
41         if (gcov)
42                 return NULL;
43
44 #ifdef __GNUC__
45         unsigned int timeleft = default_timeout_ms;
46         char *output;
47
48         if (!run_gcov(ctx, &timeleft, &output, "-h")) {
49                 err = tal_fmt(ctx, "No gcov support: %s", output);
50                 tal_free(output);
51         }
52 #else
53         err = "No coverage support for this compiler";
54 #endif
55
56         return err;
57 }