]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/tests_compile.c
ccanlint: read config.h to get compilation flags at runtime.
[ccan] / tools / ccanlint / tests / tests_compile.c
index 4d8686798c0aa12040defb489cd28ebc4d7acd1b..13a8f0dbaadfb92c22232a3ccf802d2cbc157e04 100644 (file)
@@ -66,10 +66,12 @@ static bool compile(const void *ctx,
                    bool link_with_module,
                    bool keep, char **output)
 {
+       char *f = talloc_asprintf(ctx, "%s%s",
+                                 fail ? "-DFAIL " : "", cflags);
+
        file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
-                             obj_list(m, link_with_module),
-                             fail ? "-DFAIL" : "",
+                             obj_list(m, link_with_module), compiler, f,
                              lib_list(m), file->compiled, output)) {
                talloc_free(file->compiled);
                return false;
@@ -90,12 +92,14 @@ static void do_compile_tests(struct manifest *m,
                list_for_each(list, i, list) {
                        if (!compile(score, m, i, false, list == &m->api_tests,
                                     keep, &cmdout)) {
-                               score->error = "Failed to compile tests";
-                               score_file_error(score, i, 0, cmdout);
+                               score_file_error(score, i, 0,
+                                                "Compile failed:\n%s",
+                                                cmdout);
                                errors = true;
                        } else if (!streq(cmdout, "")) {
-                               score->error = "Test compiled with warnings";
-                               score_file_error(score, i, 0, cmdout);
+                               score_file_error(score, i, 0,
+                                                "Compile gave warnings:\n%s",
+                                                cmdout);
                                warnings = true;
                        }
                }
@@ -108,19 +112,22 @@ static void do_compile_tests(struct manifest *m,
        /* For historical reasons, "fail" often means "gives warnings" */
        list_for_each(&m->compile_fail_tests, i, list) {
                if (!compile(score, m, i, false, false, false, &cmdout)) {
-                       score->error = "Failed to compile without -DFAIL";
-                       score_file_error(score, i, 0, cmdout);
+                       score_file_error(score, i, 0,
+                                        "Compile without -DFAIL failed:\n%s",
+                                        cmdout);
                        return;
                }
                if (!streq(cmdout, "")) {
-                       score->error = "Compile with warnigns without -DFAIL";
-                       score_file_error(score, i, 0, cmdout);
+                       score_file_error(score, i, 0,
+                                        "Compile gave warnings"
+                                        " without -DFAIL:\n%s",
+                                        cmdout);
                        return;
                }
                if (compile(score, m, i, true, false, false, &cmdout)
                    && streq(cmdout, "")) {
-                       score->error = "Compiled successfully with -DFAIL?";
-                       score_file_error(score, i, 0, NULL);
+                       score_file_error(score, i, 0,
+                                        "Compiled successfully with -DFAIL?");
                        return;
                }
        }