1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/foreach/foreach.h>
5 #include <ccan/str/str.h>
19 static const char *can_build(struct manifest *m)
22 return "Safe mode enabled";
26 static bool expect_obj_file(struct manifest *m)
28 /* If it has C files, we expect an object file built from them. */
29 return !list_empty(&m->c_files);
32 static char *build_subdir_objs(struct manifest *m,
34 enum compile_type ctype)
38 list_for_each(&m->c_files, i, list) {
39 char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
42 i->compiled[ctype] = temp_file(m, "", fullfile);
43 if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
44 i->compiled[ctype], &output)) {
45 talloc_free(i->compiled[ctype]);
46 i->compiled[ctype] = NULL;
47 return talloc_asprintf(m,
49 " did not build:\n%s",
56 char *build_submodule(struct manifest *m, const char *flags,
57 enum compile_type ctype)
61 if (m->compiled[ctype])
64 if (!expect_obj_file(m))
68 printf(" Building dependency %s\n", m->dir);
70 errstr = build_subdir_objs(m, flags, ctype);
74 m->compiled[ctype] = build_module(m, ctype, &errstr);
75 if (!m->compiled[ctype])
80 static void check_depends_built(struct manifest *m,
81 unsigned int *timeleft, struct score *score)
83 struct list_head *list;
85 foreach_ptr(list, &m->deps, &m->test_deps) {
87 list_for_each(list, i, list) {
90 errstr = build_submodule(i, cflags, COMPILE_NORMAL);
93 score->error = talloc_asprintf(score,
105 score->score = score->total;
108 struct ccanlint depends_build = {
109 .key = "depends_build",
110 .name = "Module's CCAN dependencies can be found or built",
111 .check = check_depends_built,
112 .can_run = can_build,
113 .needs = "depends_exist test_depends_exist"
116 REGISTER_TEST(depends_build);