+++ /dev/null
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-#include "build.h"
-
-static const char *can_build(struct manifest *m)
-{
- if (safe_mode)
- return "Safe mode enabled";
- return NULL;
-}
-
-static bool expect_obj_file(struct manifest *m)
-{
- /* If it has C files, we expect an object file built from them. */
- return !list_empty(&m->c_files);
-}
-
-static char *build_subdir_objs(struct manifest *m,
- const char *flags,
- enum compile_type ctype)
-{
- struct ccan_file *i;
-
- list_for_each(&m->c_files, i, list) {
- char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
- char *output;
-
- i->compiled[ctype] = maybe_temp_file(m, "", false, fullfile);
- if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
- i->compiled[ctype], &output)) {
- talloc_free(i->compiled[ctype]);
- i->compiled[ctype] = NULL;
- return talloc_asprintf(m,
- "Dependency %s"
- " did not build:\n%s",
- m->basename, output);
- }
- }
- return NULL;
-}
-
-char *build_submodule(struct manifest *m, const char *flags,
- enum compile_type ctype)
-{
- char *errstr;
-
- if (m->compiled[ctype])
- return NULL;
-
- if (!expect_obj_file(m))
- return NULL;
-
- if (verbose >= 2)
- printf(" Building dependency %s\n", m->dir);
-
- errstr = build_subdir_objs(m, flags, ctype);
- if (errstr)
- return errstr;
-
- m->compiled[ctype] = build_module(m, false, ctype, &errstr);
- if (!m->compiled[ctype])
- return errstr;
- return NULL;
-}
-
-static void check_depends_built(struct manifest *m,
- bool keep,
- unsigned int *timeleft, struct score *score)
-{
- struct manifest *i;
-
- list_for_each(&m->deps, i, list) {
- char *errstr = build_submodule(i, cflags, COMPILE_NORMAL);
-
- if (errstr) {
- score->error = talloc_asprintf(score,
- "Dependency %s"
- " did not build:\n%s",
- i->basename, errstr);
- return;
- }
- }
-
- score->pass = true;
- score->score = score->total;
-}
-
-struct ccanlint depends_build = {
- .key = "depends_build",
- .name = "Module's CCAN dependencies can be found or built",
- .check = check_depends_built,
- .can_run = can_build,
- .needs = "depends_exist"
-};
-
-REGISTER_TEST(depends_build);
+++ /dev/null
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/grab_file/grab_file.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-
-static const char *can_build(struct manifest *m)
-{
- if (safe_mode)
- return "Safe mode enabled";
- return NULL;
-}
-
-static struct ccan_file *main_header(struct manifest *m)
-{
- struct ccan_file *f;
-
- list_for_each(&m->h_files, f, list) {
- if (strstarts(f->name, m->basename)
- && strlen(f->name) == strlen(m->basename) + 2)
- return f;
- }
- /* Should not happen: we depend on has_main_header */
- abort();
-}
-
-static void check_includes_build(struct manifest *m,
- bool keep,
- unsigned int *timeleft, struct score *score)
-{
- char *contents;
- char *tmpsrc, *tmpobj, *cmdout;
- int fd;
- struct ccan_file *mainh = main_header(m);
-
- tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
- tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
-
- fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
- if (fd < 0)
- err(1, "Creating temporary file %s", tmpsrc);
-
- contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
- m->basename, m->basename);
- if (write(fd, contents, strlen(contents)) != strlen(contents))
- err(1, "writing to temporary file %s", tmpsrc);
- close(fd);
-
- if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
- tmpobj, &cmdout)) {
- score->pass = true;
- score->score = score->total;
- } else {
- score->error = talloc_asprintf(score,
- "#include of the main header file:\n%s",
- cmdout);
- }
-}
-
-struct ccanlint main_header_compiles = {
- .key = "main_header_compiles",
- .name = "Modules main header compiles",
- .check = check_includes_build,
- .can_run = can_build,
- .needs = "depends_exist main_header_exists"
-};
-
-REGISTER_TEST(main_header_compiles);
+++ /dev/null
-#include <tools/ccanlint/ccanlint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <ccan/str/str.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/noerr/noerr.h>
-
-static void check_has_main_header(struct manifest *m,
- bool keep,
- unsigned int *timeleft, struct score *score)
-{
- struct ccan_file *f;
-
- list_for_each(&m->h_files, f, list) {
- if (strstarts(f->name, m->basename)
- && strlen(f->name) == strlen(m->basename) + 2) {
- score->pass = true;
- score->score = score->total;
- return;
- }
- }
- score->error = talloc_asprintf(score,
- "You have no %s/%s.h header file.\n\n"
- "CCAN modules have a name, the same as the directory name. They're\n"
- "expected to have an interface in the header of the same name.\n",
- m->basename, m->basename);
-}
-
-struct ccanlint main_header_exists = {
- .key = "main_header_exists",
- .name = "Module has main header file",
- .check = check_has_main_header,
- .needs = ""
-};
-
-REGISTER_TEST(main_header_exists);
+++ /dev/null
-#include <tools/ccanlint/ccanlint.h>
-#include <tools/tools.h>
-#include <ccan/talloc/talloc.h>
-#include <ccan/str/str.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <err.h>
-#include <string.h>
-#include <ctype.h>
-
-static const char *can_build(struct manifest *m)
-{
- if (safe_mode)
- return "Safe mode enabled";
- return NULL;
-}
-
-static char *obj_list(const struct manifest *m)
-{
- char *list = talloc_strdup(m, "");
- struct manifest *i;
-
- /* Other CCAN deps. */
- list_for_each(&m->deps, i, list) {
- if (i->compiled[COMPILE_NORMAL])
- list = talloc_asprintf_append(list, "%s ",
- i->compiled
- [COMPILE_NORMAL]);
- }
- return list;
-}
-
-static char *lib_list(const struct manifest *m)
-{
- unsigned int i, num;
- char **libs = get_libs(m, ".",
- &num, &m->info_file->compiled[COMPILE_NORMAL]);
- char *ret = talloc_strdup(m, "");
-
- for (i = 0; i < num; i++)
- ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
- return ret;
-}
-
-static void check_use_build(struct manifest *m,
- bool keep,
- unsigned int *timeleft, struct score *score)
-{
- char *contents;
- char *tmpfile, *cmdout;
- char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
- int fd;
-
- tmpfile = maybe_temp_file(m, ".c", keep, basename);
-
- fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
- if (fd < 0)
- err(1, "Creating temporary file %s", tmpfile);
-
- contents = talloc_asprintf(tmpfile,
- "#include <ccan/%s/%s.h>\n"
- "int main(void)\n"
- "{\n"
- " return 0;\n"
- "}\n",
- m->basename, m->basename);
- if (write(fd, contents, strlen(contents)) != strlen(contents))
- err(1, "Failure writing to temporary file %s", tmpfile);
- close(fd);
-
- if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
- compiler, cflags, lib_list(m),
- maybe_temp_file(m, "", keep, tmpfile),
- &cmdout)) {
- score->pass = true;
- score->score = score->total;
- } else {
- score->error = cmdout;
- }
-}
-
-struct ccanlint module_links = {
- .key = "module_links",
- .name = "Module can be linked against trivial program",
- .check = check_use_build,
- .can_run = can_build,
- .needs = "module_builds depends_build"
-};
-
-REGISTER_TEST(module_links);
--- /dev/null
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+#include "../compulsory_tests/build.h"
+
+static const char *can_build(struct manifest *m)
+{
+ if (safe_mode)
+ return "Safe mode enabled";
+ return NULL;
+}
+
+static bool expect_obj_file(struct manifest *m)
+{
+ /* If it has C files, we expect an object file built from them. */
+ return !list_empty(&m->c_files);
+}
+
+static char *build_subdir_objs(struct manifest *m,
+ const char *flags,
+ enum compile_type ctype)
+{
+ struct ccan_file *i;
+
+ list_for_each(&m->c_files, i, list) {
+ char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
+ char *output;
+
+ i->compiled[ctype] = maybe_temp_file(m, "", false, fullfile);
+ if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
+ i->compiled[ctype], &output)) {
+ talloc_free(i->compiled[ctype]);
+ i->compiled[ctype] = NULL;
+ return talloc_asprintf(m,
+ "Dependency %s"
+ " did not build:\n%s",
+ m->basename, output);
+ }
+ }
+ return NULL;
+}
+
+char *build_submodule(struct manifest *m, const char *flags,
+ enum compile_type ctype)
+{
+ char *errstr;
+
+ if (m->compiled[ctype])
+ return NULL;
+
+ if (!expect_obj_file(m))
+ return NULL;
+
+ if (verbose >= 2)
+ printf(" Building dependency %s\n", m->dir);
+
+ errstr = build_subdir_objs(m, flags, ctype);
+ if (errstr)
+ return errstr;
+
+ m->compiled[ctype] = build_module(m, false, ctype, &errstr);
+ if (!m->compiled[ctype])
+ return errstr;
+ return NULL;
+}
+
+static void check_depends_built(struct manifest *m,
+ bool keep,
+ unsigned int *timeleft, struct score *score)
+{
+ struct manifest *i;
+
+ list_for_each(&m->deps, i, list) {
+ char *errstr = build_submodule(i, cflags, COMPILE_NORMAL);
+
+ if (errstr) {
+ score->error = talloc_asprintf(score,
+ "Dependency %s"
+ " did not build:\n%s",
+ i->basename, errstr);
+ return;
+ }
+ }
+
+ score->pass = true;
+ score->score = score->total;
+}
+
+struct ccanlint depends_build = {
+ .key = "depends_build",
+ .name = "Module's CCAN dependencies can be found or built",
+ .check = check_depends_built,
+ .can_run = can_build,
+ .needs = "depends_exist"
+};
+
+REGISTER_TEST(depends_build);
--- /dev/null
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/grab_file/grab_file.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+
+static const char *can_build(struct manifest *m)
+{
+ if (safe_mode)
+ return "Safe mode enabled";
+ return NULL;
+}
+
+static struct ccan_file *main_header(struct manifest *m)
+{
+ struct ccan_file *f;
+
+ list_for_each(&m->h_files, f, list) {
+ if (strstarts(f->name, m->basename)
+ && strlen(f->name) == strlen(m->basename) + 2)
+ return f;
+ }
+ /* Should not happen: we depend on has_main_header */
+ abort();
+}
+
+static void check_includes_build(struct manifest *m,
+ bool keep,
+ unsigned int *timeleft, struct score *score)
+{
+ char *contents;
+ char *tmpsrc, *tmpobj, *cmdout;
+ int fd;
+ struct ccan_file *mainh = main_header(m);
+
+ tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
+ tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
+
+ fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
+ if (fd < 0)
+ err(1, "Creating temporary file %s", tmpsrc);
+
+ contents = talloc_asprintf(tmpsrc, "#include <ccan/%s/%s.h>\n",
+ m->basename, m->basename);
+ if (write(fd, contents, strlen(contents)) != strlen(contents))
+ err(1, "writing to temporary file %s", tmpsrc);
+ close(fd);
+
+ if (compile_object(score, tmpsrc, ccan_dir, compiler, cflags,
+ tmpobj, &cmdout)) {
+ score->pass = true;
+ score->score = score->total;
+ } else {
+ score->error = talloc_asprintf(score,
+ "#include of the main header file:\n%s",
+ cmdout);
+ }
+}
+
+struct ccanlint main_header_compiles = {
+ .key = "main_header_compiles",
+ .name = "Modules main header compiles",
+ .check = check_includes_build,
+ .can_run = can_build,
+ .needs = "depends_exist main_header_exists"
+};
+
+REGISTER_TEST(main_header_compiles);
--- /dev/null
+#include <tools/ccanlint/ccanlint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <ccan/str/str.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/noerr/noerr.h>
+
+static void check_has_main_header(struct manifest *m,
+ bool keep,
+ unsigned int *timeleft, struct score *score)
+{
+ struct ccan_file *f;
+
+ list_for_each(&m->h_files, f, list) {
+ if (strstarts(f->name, m->basename)
+ && strlen(f->name) == strlen(m->basename) + 2) {
+ score->pass = true;
+ score->score = score->total;
+ return;
+ }
+ }
+ score->error = talloc_asprintf(score,
+ "You have no %s/%s.h header file.\n\n"
+ "CCAN modules have a name, the same as the directory name. They're\n"
+ "expected to have an interface in the header of the same name.\n",
+ m->basename, m->basename);
+}
+
+struct ccanlint main_header_exists = {
+ .key = "main_header_exists",
+ .name = "Module has main header file",
+ .check = check_has_main_header,
+ .needs = ""
+};
+
+REGISTER_TEST(main_header_exists);
--- /dev/null
+#include <tools/ccanlint/ccanlint.h>
+#include <tools/tools.h>
+#include <ccan/talloc/talloc.h>
+#include <ccan/str/str.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <err.h>
+#include <string.h>
+#include <ctype.h>
+
+static const char *can_build(struct manifest *m)
+{
+ if (safe_mode)
+ return "Safe mode enabled";
+ return NULL;
+}
+
+static char *obj_list(const struct manifest *m)
+{
+ char *list = talloc_strdup(m, "");
+ struct manifest *i;
+
+ /* Other CCAN deps. */
+ list_for_each(&m->deps, i, list) {
+ if (i->compiled[COMPILE_NORMAL])
+ list = talloc_asprintf_append(list, "%s ",
+ i->compiled
+ [COMPILE_NORMAL]);
+ }
+ return list;
+}
+
+static char *lib_list(const struct manifest *m)
+{
+ unsigned int i, num;
+ char **libs = get_libs(m, ".",
+ &num, &m->info_file->compiled[COMPILE_NORMAL]);
+ char *ret = talloc_strdup(m, "");
+
+ for (i = 0; i < num; i++)
+ ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
+ return ret;
+}
+
+static void check_use_build(struct manifest *m,
+ bool keep,
+ unsigned int *timeleft, struct score *score)
+{
+ char *contents;
+ char *tmpfile, *cmdout;
+ char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
+ int fd;
+
+ tmpfile = maybe_temp_file(m, ".c", keep, basename);
+
+ fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
+ if (fd < 0)
+ err(1, "Creating temporary file %s", tmpfile);
+
+ contents = talloc_asprintf(tmpfile,
+ "#include <ccan/%s/%s.h>\n"
+ "int main(void)\n"
+ "{\n"
+ " return 0;\n"
+ "}\n",
+ m->basename, m->basename);
+ if (write(fd, contents, strlen(contents)) != strlen(contents))
+ err(1, "Failure writing to temporary file %s", tmpfile);
+ close(fd);
+
+ if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
+ compiler, cflags, lib_list(m),
+ maybe_temp_file(m, "", keep, tmpfile),
+ &cmdout)) {
+ score->pass = true;
+ score->score = score->total;
+ } else {
+ score->error = cmdout;
+ }
+}
+
+struct ccanlint module_links = {
+ .key = "module_links",
+ .name = "Module can be linked against trivial program",
+ .check = check_use_build,
+ .can_run = can_build,
+ .needs = "module_builds depends_build"
+};
+
+REGISTER_TEST(module_links);