+ cmdline_exclude = btree_new(btree_strcmp);
+ info_exclude = btree_new(btree_strcmp);
+
+ opt_register_arg("--dir|-d", opt_set_charp, opt_show_charp, &dir,
+ "use this directory");
+ opt_register_noarg("-n|--safe-mode", opt_set_bool, &safe_mode,
+ "do not compile anything");
+ opt_register_noarg("-l|--list-tests", list_tests, NULL,
+ "list tests ccanlint performs (and exit)");
+ opt_register_noarg("--test-dep-graph", test_dependency_graph, NULL,
+ "print dependency graph of tests in Graphviz .dot format");
+ opt_register_arg("-k|--keep <testname>", keep_test, NULL, NULL,
+ "keep results of <testname>"
+ " (can be used multiple times, or 'all')");
+ opt_register_noarg("--summary|-s", opt_set_bool, &summary,
+ "simply give one line summary");
+ opt_register_noarg("--verbose|-v", opt_inc_intval, &verbose,
+ "verbose mode (up to -vvvv)");
+ opt_register_arg("-x|--exclude <testname>", skip_test, NULL, NULL,
+ "exclude <testname> (can be used multiple times)");
+ opt_register_arg("-t|--timeout <milleseconds>", opt_set_uintval,
+ NULL, &timeout,
+ "ignore (terminate) tests that are slower than this");
+ opt_register_arg("--target <testname>", opt_set_charp,
+ NULL, &target,
+ "only run one test (and its prerequisites)");
+ opt_register_arg("--compiler <compiler>", opt_set_charp,
+ NULL, &compiler, "set the compiler");
+ opt_register_arg("--cflags <flags>", opt_set_charp,
+ NULL, &cflags, "set the compiler flags");
+ opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
+ "\nA program for checking and guiding development"
+ " of CCAN modules.",
+ "This usage message");
+
+ /* We move into temporary directory, so gcov dumps its files there. */
+ if (chdir(temp_dir(talloc_autofree_context())) != 0)
+ err(1, "Error changing to %s temporary dir", temp_dir(NULL));
+
+ opt_parse(&argc, argv, opt_log_stderr_exit);
+
+ if (dir[0] != '/')
+ dir = talloc_asprintf_append(NULL, "%s/%s", base_dir, dir);
+ while (strends(dir, "/"))
+ dir[strlen(dir)-1] = '\0';
+ if (dir != base_dir)
+ prefix = talloc_append_string(talloc_basename(NULL, dir), ": ");
+ if (verbose >= 3)
+ compile_verbose = true;
+ if (verbose >= 4)
+ tools_verbose = true;
+
+ m = get_manifest(talloc_autofree_context(), dir);
+ read_config_header();
+
+ /* Create a symlink from temp dir back to src dir's test directory. */
+ if (symlink(talloc_asprintf(m, "%s/test", dir),
+ talloc_asprintf(m, "%s/test", temp_dir(NULL))) != 0)
+ err(1, "Creating test symlink in %s", temp_dir(NULL));
+
+ if (target) {
+ struct ccanlint *test;
+
+ test = find_test(target);
+ if (!test)
+ errx(1, "Unknown test to run '%s'", target);
+ skip_unrelated_tests(test);
+ }
+
+ /* If you don't pass the compulsory tests, you get a score of 0. */
+ while ((i = get_next_test(&compulsory_tests)) != NULL) {
+ if (!run_test(i, summary, &score, &total_score, m)) {
+ printf("%sTotal score: 0/%u\n", prefix, total_score);
+ errx(1, "%s%s failed", prefix, i->name);
+ }
+ }