]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/compulsory_tests/build_objs.c
ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / compulsory_tests / build_objs.c
index 0768bc6fb70ec685b93e07430e076e582b6648b2..13d34a14e041fb90b2fcbba7df020c06805aec31 100644 (file)
@@ -21,40 +21,48 @@ static const char *can_build(struct manifest *m)
        return NULL;
 }
 
-static void *check_objs_build(struct manifest *m)
+static void check_objs_build(struct manifest *m,
+                            bool keep,
+                            unsigned int *timeleft, struct score *score)
 {
-       char *report = NULL;
        struct ccan_file *i;
+       bool errors = false, warnings = false;
+
+       if (list_empty(&m->c_files))
+               score->total = 0;
+       else
+               score->total = 2;
 
        list_for_each(&m->c_files, i, list) {
-               char *err;
+               char *output;
                char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
 
-               /* One point for each obj file. */
-               build_objs.total_score++;
-
-               i->compiled = compile_object(m, fullfile, ccan_dir, &err);
-               if (!i->compiled) {
-                       if (report)
-                               report = talloc_append_string(report, err);
-                       else
-                               report = err;
+               i->compiled = maybe_temp_file(m, "", keep, fullfile);
+               if (!compile_object(score, fullfile, ccan_dir, "", i->compiled,
+                                   &output)) {
+                       talloc_free(i->compiled);
+                       score->error = "Compiling object files";
+                       score_file_error(score, i, 0, output);
+                       errors = true;
+               } else if (!streq(output, "")) {
+                       score->error = "Compiling object files gave warnings";
+                       score_file_error(score, i, 0, output);
+                       warnings = true;
                }
        }
-       return report;
-}
 
-static const char *describe_objs_build(struct manifest *m, void *check_result)
-{
-       return check_result;
+       if (!errors) {
+               score->pass = true;
+               score->score = score->total - warnings;
+       }
 }
 
-struct ccanlint build_objs = {
-       .key = "build-objs",
+struct ccanlint objects_build = {
+       .key = "objects_build",
        .name = "Module object files can be built",
        .check = check_objs_build,
-       .describe = describe_objs_build,
        .can_run = can_build,
+       .needs = "depends_exist"
 };
 
-REGISTER_TEST(build_objs, &depends_exist, NULL);
+REGISTER_TEST(objects_build);