X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Fcompulsory_tests%2Fcheck_build.c;h=9175b91835f5bb2271f6e645d9040038030c8663;hb=f76c68579cb445177b9957814ba8623a73e5d60e;hp=eb968e11e36d65052ce3d647e88093da16a33c8e;hpb=5f44c8ca0eb66503db51e0df1b65ff173eb42f57;p=ccan diff --git a/tools/ccanlint/compulsory_tests/check_build.c b/tools/ccanlint/compulsory_tests/check_build.c index eb968e11..9175b918 100644 --- a/tools/ccanlint/compulsory_tests/check_build.c +++ b/tools/ccanlint/compulsory_tests/check_build.c @@ -27,16 +27,17 @@ static char *obj_list(const struct manifest *m) struct ccan_file *i; /* Other CCAN deps. */ - list_for_each(&m->dep_objs, i, list) - list = talloc_asprintf_append(list, "%s ", i->name); - + list_for_each(&m->dep_dirs, i, list) { + if (i->compiled) + list = talloc_asprintf_append(list, "%s ", i->compiled); + } return list; } static char *lib_list(const struct manifest *m) { unsigned int i, num; - char **libs = get_libs(m, ".", ".", &num, &m->info_file->compiled); + char **libs = get_libs(m, ".", &num, &m->info_file->compiled); char *ret = talloc_strdup(m, ""); for (i = 0; i < num; i++) @@ -44,18 +45,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; + 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,29 +67,23 @@ 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, 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); + score->error = compile_and_link(m, tmpfile, ccan_dir, obj_list(m), "", + lib_list(m), + maybe_temp_file(m, "", keep, tmpfile)); + if (!score->error) { + score->pass = true; + score->score = score->total; + } } struct ccanlint check_build = { - .name = "Module can be used", - .total_score = 1, + .key = "check-link", + .name = "Module can be linked against trivial program", .check = check_use_build, - .describe = describe_use_build, .can_run = can_build, };