X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_compile.c;h=c939055857021e93c105c2da2352840902b45698;hb=6aa2f4e347e5d66a392b879fe901bc582099a552;hp=bfa412a68a14d55051588b15de3ed74213096f52;hpb=4640e61b45d8d3cdfc5301bc58ef7c96a42077ec;p=ccan diff --git a/tools/ccanlint/tests/tests_compile.c b/tools/ccanlint/tests/tests_compile.c index bfa412a6..c9390558 100644 --- a/tools/ccanlint/tests/tests_compile.c +++ b/tools/ccanlint/tests/tests_compile.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -27,40 +26,43 @@ static const char *can_build(struct manifest *m) char *test_obj_list(const struct manifest *m, bool link_with_module, enum compile_type ctype, enum compile_type own_ctype) { - char *list = talloc_strdup(m, ""); + char *list = tal_strdup(m, ""); struct ccan_file *i; struct manifest *subm; /* Objects from any other C files. */ list_for_each(&m->other_test_c_files, i, list) - list = talloc_asprintf_append(list, " %s", - i->compiled[ctype]); + tal_append_fmt(&list, " %s", i->compiled[ctype]); /* Our own object files. */ if (link_with_module) list_for_each(&m->c_files, i, list) - list = talloc_asprintf_append(list, " %s", - i->compiled[own_ctype]); + tal_append_fmt(&list, " %s", i->compiled[own_ctype]); - /* Other ccan modules. */ + /* Other ccan modules (normal depends). */ list_for_each(&m->deps, subm, list) { if (subm->compiled[ctype]) - list = talloc_asprintf_append(list, " %s", - subm->compiled[ctype]); + tal_append_fmt(&list, " %s", subm->compiled[ctype]); + } + + /* Other ccan modules (test depends). */ + list_for_each(&m->test_deps, subm, list) { + if (subm->compiled[ctype]) + tal_append_fmt(&list, " %s", subm->compiled[ctype]); } return list; } -char *lib_list(const struct manifest *m, enum compile_type ctype) +char *test_lib_list(const struct manifest *m, enum compile_type ctype) { - unsigned int i, num; - char **libs = get_libs(m, m->dir, &num, - &m->info_file->compiled[ctype]); - char *ret = talloc_strdup(m, ""); + unsigned int i; + char **libs; + char *ret = tal_strdup(m, ""); - for (i = 0; i < num; i++) - ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); + libs = get_libs(m, m->dir, "testdepends", get_or_compile_info); + for (i = 0; libs[i]; i++) + tal_append_fmt(&ret, "-l%s ", libs[i]); return ret; } @@ -69,25 +71,24 @@ static bool compile(const void *ctx, struct ccan_file *file, bool fail, bool link_with_module, - bool keep, enum compile_type ctype, char **output) { char *fname, *flags; - flags = talloc_asprintf(ctx, "%s%s%s", - fail ? "-DFAIL " : "", - cflags, - ctype == COMPILE_NOFEAT - ? " "REDUCE_FEATURES_FLAGS : ""); + flags = tal_fmt(ctx, "%s%s%s", + fail ? "-DFAIL " : "", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); - fname = maybe_temp_file(ctx, "", keep, file->fullname); + fname = temp_file(ctx, "", file->fullname); if (!compile_and_link(ctx, file->fullname, ccan_dir, test_obj_list(m, link_with_module, ctype, ctype), - compiler, flags, lib_list(m, ctype), fname, + compiler, flags, test_lib_list(m, ctype), fname, output)) { - talloc_free(fname); + tal_free(fname); return false; } @@ -99,25 +100,24 @@ static void compile_async(const void *ctx, struct manifest *m, struct ccan_file *file, bool link_with_module, - bool keep, enum compile_type ctype, unsigned int time_ms) { char *flags; - file->compiled[ctype] = maybe_temp_file(ctx, "", keep, file->fullname); - flags = talloc_asprintf(ctx, "%s%s", - cflags, - ctype == COMPILE_NOFEAT - ? " "REDUCE_FEATURES_FLAGS : ""); + file->compiled[ctype] = temp_file(ctx, "", file->fullname); + flags = tal_fmt(ctx, "%s%s", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); compile_and_link_async(file, time_ms, file->fullname, ccan_dir, test_obj_list(m, link_with_module, ctype, ctype), - compiler, flags, lib_list(m, ctype), + compiler, flags, test_lib_list(m, ctype), file->compiled[ctype]); } -static void compile_tests(struct manifest *m, bool keep, +static void compile_tests(struct manifest *m, struct score *score, enum compile_type ctype, unsigned int time_ms) @@ -130,7 +130,7 @@ static void compile_tests(struct manifest *m, bool keep, foreach_ptr(list, &m->compile_ok_tests, &m->run_tests, &m->api_tests) { list_for_each(list, i, list) { compile_async(score, m, i, - list == &m->api_tests, keep, + list == &m->api_tests, ctype, time_ms); } } @@ -155,8 +155,7 @@ static void compile_tests(struct manifest *m, bool keep, /* For historical reasons, "fail" often means "gives warnings" */ list_for_each(&m->compile_fail_tests, i, list) { - if (!compile(score, m, i, false, false, false, - ctype, &cmdout)) { + if (!compile(score, m, i, false, false, ctype, &cmdout)) { score_file_error(score, i, 0, "Compile without -DFAIL failed:\n%s", cmdout); @@ -169,8 +168,7 @@ static void compile_tests(struct manifest *m, bool keep, cmdout); return; } - if (compile(score, m, i, true, false, false, - ctype, &cmdout) + if (compile(score, m, i, true, false, ctype, &cmdout) && streq(cmdout, "")) { score_file_error(score, i, 0, "Compiled successfully with -DFAIL?"); @@ -185,10 +183,9 @@ static void compile_tests(struct manifest *m, bool keep, /* FIXME: If we time out, set *timeleft to 0 */ static void do_compile_tests(struct manifest *m, - bool keep, unsigned int *timeleft, struct score *score) { - compile_tests(m, keep, score, COMPILE_NORMAL, *timeleft); + compile_tests(m, score, COMPILE_NORMAL, *timeleft); } struct ccanlint tests_compile = { @@ -209,11 +206,10 @@ static const char *features_reduced(struct manifest *m) } static void do_compile_tests_without_features(struct manifest *m, - bool keep, unsigned int *timeleft, struct score *score) { - compile_tests(m, keep, score, COMPILE_NOFEAT, *timeleft); + compile_tests(m, score, COMPILE_NOFEAT, *timeleft); } struct ccanlint tests_compile_without_features = { @@ -221,6 +217,6 @@ struct ccanlint tests_compile_without_features = { .name = "Module tests compile (without features)", .check = do_compile_tests_without_features, .can_run = features_reduced, - .needs = "tests_helpers_compile_without_features objects_build_without_features" + .needs = "module_builds tests_helpers_compile_without_features objects_build_without_features" }; REGISTER_TEST(tests_compile_without_features);