]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/tests_compile_coverage.c
tools: fix up warnings with -Wwrite-strings.
[ccan] / tools / ccanlint / tests / tests_compile_coverage.c
index 115ae94a15e50a7f4050f2b307e5bdb18295b944..ea46e79e1bc3d8df15cac0aeb2889ca526ff4e81 100644 (file)
@@ -2,6 +2,7 @@
 #include <tools/tools.h>
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
+#include <ccan/foreach/foreach.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -37,9 +38,9 @@ static bool build_module_objs_with_coverage(struct manifest *m, bool keep,
                char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
 
                i->cov_compiled = maybe_temp_file(m, "", keep, fullfile);
-               if (!compile_object(m, fullfile, ccan_dir, "",
+               if (!compile_object(m, fullfile, ccan_dir, compiler, cflags,
                                    i->cov_compiled, &err)) {
-                       score_file_error(score, i, 0, err);
+                       score_file_error(score, i, 0, "%s", err);
                        talloc_free(i->cov_compiled);
                        i->cov_compiled = NULL;
                        return false;
@@ -92,11 +93,12 @@ static char *cov_compile(const void *ctx,
                         bool keep)
 {
        char *output;
+       char *f = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
 
        file->cov_compiled = maybe_temp_file(ctx, "", keep, file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
                              obj_list(m, modobjs),
-                             COVERAGE_CFLAGS,
+                             compiler, f,
                              lib_list(m), file->cov_compiled, &output)) {
                talloc_free(file->cov_compiled);
                file->cov_compiled = NULL;
@@ -114,26 +116,23 @@ static void do_compile_coverage_tests(struct manifest *m,
 {
        char *cmdout, *modobjs = NULL;
        struct ccan_file *i;
+       struct list_head *h;
 
        if (!list_empty(&m->api_tests)
            && !build_module_objs_with_coverage(m, keep, score, &modobjs)) {
-               score->error = "Failed to compile module objects with coverage";
+               score->error = talloc_strdup(score,
+                            "Failed to compile module objects with coverage");
                return;
        }
 
-       list_for_each(&m->run_tests, i, list) {
-               cmdout = cov_compile(m, m, i, NULL, keep);
-               if (cmdout) {
-                       score->error = "Failed to compile test with coverage";
-                       score_file_error(score, i, 0, cmdout);
-               }
-       }
-
-       list_for_each(&m->api_tests, i, list) {
-               cmdout = cov_compile(m, m, i, modobjs, keep);
-               if (cmdout) {
-                       score->error = "Failed to compile test with coverage";
-                       score_file_error(score, i, 0, cmdout);
+       foreach_ptr(h, &m->run_tests, &m->api_tests) {
+               list_for_each(h, i, list) {
+                       cmdout = cov_compile(m, m, i, NULL, keep);
+                       if (cmdout) {
+                               score_file_error(score, i, 0,
+                                 "Failed to compile test with coverage: %s",
+                                 cmdout);
+                       }
                }
        }
        if (!score->error) {