X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_build.c;h=b7935f015d6982aa0fca24d9ba4b03585ca1c54f;hp=820cc9fec2eb53edc30ff6b97f892e2090bab66c;hb=1591860d84a9676820e94d8bd75d08a2c24ffef4;hpb=357700fd05c2cf25563a0058fd68f2ffea827e74 diff --git a/tools/ccanlint/compulsory_tests/check_build.c b/tools/ccanlint/compulsory_tests/check_build.c index 820cc9fe..b7935f01 100644 --- a/tools/ccanlint/compulsory_tests/check_build.c +++ b/tools/ccanlint/compulsory_tests/check_build.c @@ -24,12 +24,14 @@ static const char *can_build(struct manifest *m) static char *obj_list(const struct manifest *m) { char *list = talloc_strdup(m, ""); - struct ccan_file *i; + struct manifest *i; /* Other CCAN deps. */ - list_for_each(&m->dep_objs, i, list) - list = talloc_asprintf_append(list, "%s ", i->name); - + list_for_each(&m->deps, i, list) { + if (i->compiled) + list = talloc_asprintf_append(list, "%s ", + i->compiled); + } return list; } @@ -44,18 +46,20 @@ static char *lib_list(const struct manifest *m) return ret; } -static void *check_use_build(struct manifest *m) +static void check_use_build(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { char *contents; - char *tmpfile, *err; + char *tmpfile, *cmdout; + char *basename = talloc_asprintf(m, "%s/example.c", m->dir); int fd; - tmpfile = temp_file(m, ".c"); + tmpfile = maybe_temp_file(m, ".c", keep, basename); fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) - return talloc_asprintf(m, "Creating temporary file: %s", - strerror(errno)); + err(1, "Creating temporary file %s", tmpfile); contents = talloc_asprintf(tmpfile, "#include \n" @@ -64,32 +68,26 @@ static void *check_use_build(struct manifest *m) " return 0;\n" "}\n", m->basename, m->basename); - if (write(fd, contents, strlen(contents)) != strlen(contents)) { - close(fd); - return "Failure writing to temporary file"; - } + if (write(fd, contents, strlen(contents)) != strlen(contents)) + err(1, "Failure writing to temporary file %s", tmpfile); close(fd); - if (!compile_and_link(m, tmpfile, ccan_dir, obj_list(m), "", - lib_list(m), &err)) - return err; - return NULL; -} - -static const char *describe_use_build(struct manifest *m, void *check_result) -{ - return talloc_asprintf(check_result, - "Linking against module:\n" - "%s", (char *)check_result); + if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m), "", + lib_list(m), + maybe_temp_file(m, "", keep, tmpfile), + &cmdout)) { + score->pass = true; + score->score = score->total; + } else { + score->error = cmdout; + } } struct ccanlint check_build = { .key = "check-link", .name = "Module can be linked against trivial program", - .total_score = 1, .check = check_use_build, - .describe = describe_use_build, .can_run = can_build, }; -REGISTER_TEST(check_build, &build, NULL); +REGISTER_TEST(check_build, &build, &depends_built, NULL);