X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fccanlint.c;h=7747a4976e7cd1ea748191ff5246480806cb027b;hp=2fdb8863cea9dc79c291518bb89c668a653e80c5;hb=ec73dece4ef3bc4d9664aae6c2fa7c5cc26da7d3;hpb=756407b43540926c39181e5c61425d5daf1970db diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index 2fdb8863..7747a497 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -46,10 +46,6 @@ bool keep_results = false; static bool targeting = false; static unsigned int timeout; -/* These are overridden at runtime if we can find config.h */ -const char *compiler = NULL; -const char *cflags = NULL; - const char *config_header; const char *ccan_dir; @@ -93,10 +89,11 @@ static const char *dep_failed(struct manifest *m) return "dependency couldn't run"; } -static bool cannot_run(struct dgraph_node *node, void *unused) +static bool cannot_run(struct dgraph_node *node, void *all) { struct ccanlint *c = container_of(node, struct ccanlint, node); c->can_run = dep_failed; + return true; } @@ -606,10 +603,11 @@ int main(int argc, char *argv[]) unsigned int i; const char *prefix = ""; char *cwd = path_cwd(NULL), *dir; - struct dgraph_node all; + struct ccanlint top; /* cannot_run may try to set ->can_run */ + const char *override_compiler = NULL, *override_cflags = NULL; /* Empty graph node to which we attach everything else. */ - dgraph_init_node(&all); + dgraph_init_node(&top.node); opt_register_early_noarg("--verbose|-v", opt_inc_intval, &verbose, "verbose mode (up to -vvvv)"); @@ -628,12 +626,13 @@ int main(int argc, char *argv[]) opt_register_arg("--timeout ", opt_set_uintval, NULL, &timeout, "ignore (terminate) tests that are slower than this"); - opt_register_arg("-t|--target ", opt_set_target, NULL, &all, + opt_register_arg("-t|--target ", opt_set_target, NULL, + &top.node, "only run one test (and its prerequisites)"); opt_register_arg("--compiler ", opt_set_const_charp, - NULL, &compiler, "set the compiler"); + NULL, &override_compiler, "set the compiler"); opt_register_arg("--cflags ", opt_set_const_charp, - NULL, &cflags, "set the compiler flags"); + NULL, &override_cflags, "set the compiler flags"); opt_register_noarg("-?|-h|--help", opt_usage_and_exit, "\nA program for checking and guiding development" " of CCAN modules.", @@ -658,7 +657,7 @@ int main(int argc, char *argv[]) opt_parse(&argc, argv, opt_log_stderr_exit); if (!targeting) - strmap_iterate(&tests, add_to_all, &all); + strmap_iterate(&tests, add_to_all, &top.node); if (argc == 1) dir = cwd; @@ -668,22 +667,30 @@ int main(int argc, char *argv[]) ccan_dir = find_ccan_dir(dir); if (!ccan_dir) errx(1, "Cannot find ccan/ base directory in %s", dir); - config_header = read_config_header(ccan_dir, &compiler, &cflags, - verbose > 1); + config_header = read_config_header(ccan_dir, verbose > 1); + + /* We do this after read_config_header has set compiler & cflags */ + if (override_cflags) + cflags = override_cflags; + if (override_compiler) + compiler = override_compiler; if (argc == 1) - pass = test_module(&all, cwd, "", summary); + pass = test_module(&top.node, cwd, "", summary); else { for (i = 1; i < argc; i++) { dir = path_canon(NULL, take(path_join(NULL, cwd, argv[i]))); + if (!dir) + err(1, "Cannot get canonical name of '%s'", + argv[i]); prefix = path_join(NULL, ccan_dir, "ccan"); prefix = path_rel(NULL, take(prefix), dir); prefix = tal_strcat(NULL, take(prefix), ": "); - pass &= test_module(&all, dir, prefix, summary); - reset_tests(&all); + pass &= test_module(&top.node, dir, prefix, summary); + reset_tests(&top.node); } } return pass ? 0 : 1;