]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/compulsory_tests/build.c
ccanlint: fix error with --target=build
[ccan] / tools / ccanlint / compulsory_tests / build.c
index d2b22ac5ef51726cc2c06c14d97b19239d1e6e5e..fee79b10c82499574482e2f5913258e19d9107fd 100644 (file)
@@ -13,6 +13,7 @@
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
+#include "build.h"
 
 static const char *can_build(struct manifest *m)
 {
@@ -33,40 +34,50 @@ static char *obj_list(const struct manifest *m)
        return list;
 }
 
-static void *do_build(struct manifest *m)
+char *build_module(struct manifest *m, bool keep, char **errstr)
 {
-       char *filename, *err;
+       char *name = link_objects(m, m->basename, false, obj_list(m), errstr);
+       if (name) {
+               if (keep) {
+                       char *realname = talloc_asprintf(m, "%s.o", m->dir);
+                       /* We leave this object file around, all built. */
+                       if (!move_file(name, realname))
+                               err(1, "Renaming %s to %s", name, realname);
+                       name = realname;
+               }
+       }
+       return name;
+}
+
+static void do_build(struct manifest *m,
+                    bool keep,
+                    unsigned int *timeleft,
+                    struct score *score)
+{
+       char *errstr;
 
        if (list_empty(&m->c_files)) {
                /* No files?  No score, but we "pass". */
-               build.total_score = 0;
-               return NULL;
+               score->total = 0;
+               score->pass = true;
+               return;
        }
-       filename = link_objects(m, obj_list(m), &err);
-       if (filename) {
-               char *realname = talloc_asprintf(m, "%s.o", m->dir);
-               /* We leave this object file around, all built. */
-               if (!move_file(filename, realname))
-                       return talloc_asprintf(m, "Failed to rename %s to %s",
-                                              filename, realname);
-               return NULL;
+
+       m->compiled = build_module(m, keep, &errstr);
+       if (!m->compiled) {
+               score_file_error(score, NULL, 0, errstr);
+               return;
        }
-       return err;
-}
 
-static const char *describe_build(struct manifest *m, void *check_result)
-{
-       return talloc_asprintf(check_result, 
-                              "The object file for the module didn't build:\n"
-                              "%s", (char *)check_result);
+       score->pass = true;
+       score->score = score->total;
 }
 
 struct ccanlint build = {
-       .name = "Module can be built",
-       .total_score = 1,
+       .key = "build",
+       .name = "Module can be built from object files",
        .check = do_build,
-       .describe = describe_build,
        .can_run = can_build,
 };
 
-REGISTER_TEST(build, &depends_built, NULL);
+REGISTER_TEST(build, &build_objs, NULL);