Browse Source

ccanlint: remove argument to -k/--keep

It's much easier to simply say "keep all", and it simplifies the code
quite a bit.
Rusty Russell 14 years ago
parent
commit
af5b1a1894
42 changed files with 82 additions and 182 deletions
  1. 6 19
      tools/ccanlint/ccanlint.c
  2. 5 5
      tools/ccanlint/ccanlint.h
  3. 2 3
      tools/ccanlint/tests/avoids_cpp_reserved.c
  4. 2 3
      tools/ccanlint/tests/build.h
  5. 0 1
      tools/ccanlint/tests/depends_accurate.c
  6. 2 3
      tools/ccanlint/tests/depends_build.c
  7. 0 1
      tools/ccanlint/tests/depends_build_without_features.c
  8. 0 1
      tools/ccanlint/tests/depends_exist.c
  9. 15 20
      tools/ccanlint/tests/examples_compile.c
  10. 3 5
      tools/ccanlint/tests/examples_exist.c
  11. 0 1
      tools/ccanlint/tests/examples_relevant.c
  12. 1 1
      tools/ccanlint/tests/examples_run.c
  13. 1 2
      tools/ccanlint/tests/hash_if.c
  14. 1 2
      tools/ccanlint/tests/headers_idempotent.c
  15. 2 3
      tools/ccanlint/tests/info_documentation_exists.c
  16. 0 1
      tools/ccanlint/tests/info_exists.c
  17. 0 1
      tools/ccanlint/tests/info_summary_single_line.c
  18. 0 1
      tools/ccanlint/tests/license_comment.c
  19. 0 1
      tools/ccanlint/tests/license_depends_compat.c
  20. 0 1
      tools/ccanlint/tests/license_exists.c
  21. 0 1
      tools/ccanlint/tests/license_file_compat.c
  22. 2 3
      tools/ccanlint/tests/main_header_compiles.c
  23. 0 1
      tools/ccanlint/tests/main_header_exists.c
  24. 3 16
      tools/ccanlint/tests/module_builds.c
  25. 2 3
      tools/ccanlint/tests/module_links.c
  26. 0 1
      tools/ccanlint/tests/no_trailing_whitespace.c
  27. 3 4
      tools/ccanlint/tests/objects_build.c
  28. 6 8
      tools/ccanlint/tests/objects_build_with_stringchecks.c
  29. 1 2
      tools/ccanlint/tests/objects_build_without_features.c
  30. 0 1
      tools/ccanlint/tests/reduce_features.c
  31. 8 14
      tools/ccanlint/tests/tests_compile.c
  32. 4 8
      tools/ccanlint/tests/tests_compile_coverage.c
  33. 0 11
      tools/ccanlint/tests/tests_coverage.c
  34. 0 1
      tools/ccanlint/tests/tests_exist.c
  35. 4 10
      tools/ccanlint/tests/tests_helpers_compile.c
  36. 0 3
      tools/ccanlint/tests/tests_pass.c
  37. 0 5
      tools/ccanlint/tests/tests_pass_valgrind.c
  38. 0 1
      tools/ccanlint/tests/tests_pass_without_features.c
  39. 2 2
      tools/compile.c
  40. 2 2
      tools/depends.c
  41. 2 6
      tools/tools.c
  42. 3 4
      tools/tools.h

+ 6 - 19
tools/ccanlint/ccanlint.c

@@ -42,6 +42,7 @@ struct ccanlint_map {
 int verbose = 0;
 static struct ccanlint_map tests;
 bool safe_mode = false;
+bool keep_results = false;
 static bool targeting = false;
 static unsigned int timeout;
 
@@ -150,7 +151,7 @@ static bool run_test(struct dgraph_node *n, struct run_info *run)
 	}
 
 	timeleft = timeout ? timeout : default_timeout_ms;
-	i->check(run->m, i->keep_results, &timeleft, score);
+	i->check(run->m, &timeleft, score);
 	if (timeout && timeleft == 0) {
 		i->skip = "timeout";
 		if (verbose)
@@ -343,22 +344,9 @@ static int show_tmpdir(const char *dir)
 	return 0;
 }
 
-static bool keep_one_test(const char *member, struct ccanlint *c, void *unused)
+static char *keep_tests(void *unused)
 {
-	c->keep_results = true;
-	return true;
-}
-
-static char *keep_test(const char *testname, void *unused)
-{
-	if (streq(testname, "all")) {
-		strmap_iterate(&tests, keep_one_test, NULL);
-	} else {
-		struct ccanlint *i = find_test(testname);
-		if (!i)
-			errx(1, "No test %s to --keep", testname);
-		keep_one_test(testname, i, NULL);
-	}
+	keep_results = true;
 
 	/* Don't automatically destroy temporary dir. */
 	talloc_set_destructor(temp_dir(NULL), show_tmpdir);
@@ -726,9 +714,8 @@ int main(int argc, char *argv[])
 			 "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("-k|--keep", keep_tests, NULL,
+			 "do not delete ccanlint working files");
 	opt_register_noarg("--summary|-s", opt_set_bool, &summary,
 			   "simply give one line summary");
 	opt_register_arg("-x|--exclude <testname>", exclude_test, NULL, NULL,

+ 5 - 5
tools/ccanlint/ccanlint.h

@@ -93,12 +93,11 @@ struct ccanlint {
 	/* Should we stop immediately if test fails? */
 	bool compulsory;
 
-	/* keep is set if you should keep the results.
-	 * If timeleft is set to 0, means it timed out.
+	/* If timeleft is set to 0, means it timed out.
 	 * score is the result, and a talloc context freed after all our
 	 * depends are done. */
 	void (*check)(struct manifest *m,
-		      bool keep, unsigned int *timeleft, struct score *score);
+		      unsigned int *timeleft, struct score *score);
 
 	/* Can we do something about it? (NULL if not) */
 	void (*handle)(struct manifest *m, struct score *score);
@@ -116,8 +115,6 @@ struct ccanlint {
 	struct dgraph_node node;
 	/* Did we skip a dependency?  If so, must skip this, too. */
 	const char *skip;
-	/* Did the user want to keep these results? */
-	bool keep_results;
 	/* Have we already run this? */
 	bool done;
 };
@@ -267,6 +264,9 @@ void add_info_options(struct ccan_file *info);
 /* Are we happy to compile stuff, or just non-intrusive tests? */
 extern bool safe_mode;
 
+/* Did the user want to keep all the results? */
+extern bool keep_results;
+
 /* Where is the ccan dir?  Available after first manifest. */
 extern const char *ccan_dir;
 

+ 2 - 3
tools/ccanlint/tests/avoids_cpp_reserved.c

@@ -36,7 +36,6 @@ static struct ccan_file *main_header(struct manifest *m)
 }
 
 static void check_headers_no_cpp(struct manifest *m,
-				 bool keep,
 				 unsigned int *timeleft, struct score *score)
 {
 	char *contents;
@@ -44,8 +43,8 @@ static void check_headers_no_cpp(struct manifest *m,
 	int fd;
 	struct ccan_file *mainh = main_header(m);
 
-	tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
-	tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
+	tmpsrc = temp_file(m, "-included.c", mainh->fullname);
+	tmpobj = temp_file(m, ".o", tmpsrc);
 
 	/* We don't fail you for this. */
 	score->pass = true;

+ 2 - 3
tools/ccanlint/tests/build.h

@@ -1,10 +1,9 @@
 #ifndef CCANLINT_BUILD_H
 #define CCANLINT_BUILD_H
-char *build_module(struct manifest *m, bool keep, enum compile_type ctype,
-		   char **errstr);
+char *build_module(struct manifest *m, enum compile_type ctype, char **errstr);
 char *build_submodule(struct manifest *m, const char *flags,
 		      enum compile_type ctype);
 void build_objects(struct manifest *m,
-		   bool keep, struct score *score, const char *flags,
+		   struct score *score, const char *flags,
 		   enum compile_type ctype);
 #endif /* CCANLINT_BUILD_H */

+ 0 - 1
tools/ccanlint/tests/depends_accurate.c

@@ -32,7 +32,6 @@ static bool has_dep(struct manifest *m, const char *depname)
 }
 
 static void check_depends_accurate(struct manifest *m,
-				   bool keep,
 				   unsigned int *timeleft, struct score *score)
 {
 	struct list_head *list;

+ 2 - 3
tools/ccanlint/tests/depends_build.c

@@ -38,7 +38,7 @@ static char *build_subdir_objs(struct manifest *m,
 		char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
 		char *output;
 
-		i->compiled[ctype] = maybe_temp_file(m, "", false, fullfile);
+		i->compiled[ctype] = temp_file(m, "", fullfile);
 		if (!compile_object(m, fullfile, ccan_dir, compiler, flags,
 				    i->compiled[ctype], &output)) {
 			talloc_free(i->compiled[ctype]);
@@ -70,14 +70,13 @@ char *build_submodule(struct manifest *m, const char *flags,
 	if (errstr)
 		return errstr;
 
-	m->compiled[ctype] = build_module(m, false, ctype, &errstr);
+	m->compiled[ctype] = build_module(m, ctype, &errstr);
 	if (!m->compiled[ctype])
 		return errstr;
 	return NULL;
 }
 
 static void check_depends_built(struct manifest *m,
-				bool keep,
 				unsigned int *timeleft, struct score *score)
 {
 	struct manifest *i;

+ 0 - 1
tools/ccanlint/tests/depends_build_without_features.c

@@ -24,7 +24,6 @@ static const char *can_build(struct manifest *m)
 }
 
 static void check_depends_built_without_features(struct manifest *m,
-						 bool keep,
 						 unsigned int *timeleft,
 						 struct score *score)
 {

+ 0 - 1
tools/ccanlint/tests/depends_exist.c

@@ -35,7 +35,6 @@ static bool add_dep(struct manifest *m, const char *dep, struct score *score)
 
 /* FIXME: check this is still true once we reduce features. */
 static void check_depends_exist(struct manifest *m,
-				bool keep,
 				unsigned int *timeleft, struct score *score)
 {
 	unsigned int i;

+ 15 - 20
tools/ccanlint/tests/examples_compile.c

@@ -122,19 +122,16 @@ static char *lib_list(const struct manifest *m)
 static bool compile(const void *ctx,
 		    struct manifest *m,
 		    struct ccan_file *file,
-		    bool keep, char **output)
+		    char **output)
 {
-	file->compiled[COMPILE_NORMAL]
-		= maybe_temp_file(ctx, "", keep, file->fullname);
+	file->compiled[COMPILE_NORMAL] = temp_file(ctx, "", file->fullname);
 	if (!compile_and_link(ctx, file->fullname, ccan_dir,
 			      example_obj_list(m, file),
 			      compiler, cflags,
 			      lib_list(m), file->compiled[COMPILE_NORMAL],
 			      output)) {
-		/* Don't keep failures. */
-		if (keep)
-			unlink(file->compiled[COMPILE_NORMAL]);
-		talloc_free(file->compiled[COMPILE_NORMAL]);
+		/* Don't keep failures, even with --keep */
+		unlink(file->compiled[COMPILE_NORMAL]);
 		file->compiled[COMPILE_NORMAL] = NULL;
 		return false;
 	}
@@ -441,16 +438,15 @@ static char *mangle(struct manifest *m, char **lines)
 
 static struct ccan_file *mangle_example(struct manifest *m,
 					struct ccan_file *example,
-					char **lines,
-					bool keep)
+					char **lines)
 {
 	char *name, *contents;
 	int fd;
 	struct ccan_file *f;
 
-	name = maybe_temp_file(example, ".c", keep, 
-			       talloc_asprintf(m, "%s/mangled-%s",
-					       m->dir, example->name));
+	name = temp_file(example, ".c",
+			 talloc_asprintf(m, "%s/mangled-%s",
+					 m->dir, example->name));
 	f = new_ccan_file(example,
 			  talloc_dirname(example, name),
 			  talloc_basename(example, name));
@@ -491,7 +487,6 @@ static bool has_expected_output(char **lines)
 static unsigned int try_compiling(struct manifest *m,
 				  struct ccan_file *i,
 				  char **prev,
-				  bool keep,
 				  struct ccan_file *mangled[3],
 				  bool res[3],
 				  char *err[3],
@@ -501,7 +496,7 @@ static unsigned int try_compiling(struct manifest *m,
 
 	/* Try standalone. */
 	mangled[0] = i;
-	res[0] = compile(i, m, mangled[0], keep, &err[0]);
+	res[0] = compile(i, m, mangled[0], &err[0]);
 	lines[0] = get_ccan_file_lines(i);
 	if (res[0] && streq(err[0], ""))
 		return 1;
@@ -509,8 +504,8 @@ static unsigned int try_compiling(struct manifest *m,
 	if (prev) {
 		lines[1] = combine(i, get_ccan_file_lines(i), prev);
 
-		mangled[1] = mangle_example(m, i, lines[1], keep);
-		res[1] = compile(i, m, mangled[1], keep, &err[1]);
+		mangled[1] = mangle_example(m, i, lines[1]);
+		res[1] = compile(i, m, mangled[1], &err[1]);
 		if (res[1] && streq(err[1], "")) {
 			return 2;
 		}
@@ -520,13 +515,13 @@ static unsigned int try_compiling(struct manifest *m,
 
 	/* Try standalone. */
 	lines[num] = get_ccan_file_lines(i);
-	mangled[num] = mangle_example(m, i, lines[num], keep);
-	res[num] = compile(i, m, mangled[num], keep, &err[num]);
+	mangled[num] = mangle_example(m, i, lines[num]);
+	res[num] = compile(i, m, mangled[num], &err[num]);
 
 	return num+1;
 }
 
-static void build_examples(struct manifest *m, bool keep,
+static void build_examples(struct manifest *m,
 			   unsigned int *timeleft, struct score *score)
 {
 	struct ccan_file *i;
@@ -549,7 +544,7 @@ static void build_examples(struct manifest *m, bool keep,
 		/* Simplify our dumb parsing. */
 		strip_leading_whitespace(get_ccan_file_lines(i));
 
-		num = try_compiling(m, i, prev, keep, file, res, err, lines);
+		num = try_compiling(m, i, prev, file, res, err, lines);
 
 		/* First look for a compile without any warnings. */
 		for (j = 0; j < num; j++) {

+ 3 - 5
tools/ccanlint/tests/examples_exist.c

@@ -17,7 +17,6 @@
 
 /* Creates and adds an example file. */
 static char *add_example(struct manifest *m, struct ccan_file *source,
-			 bool keep,
 			 struct doc_section *example)
 {
 	char *name;
@@ -34,7 +33,7 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
 	while (strchr(name, ' '))
 		*strchr(name, ' ') = '_';
 
-	name = maybe_temp_file(m, ".c", keep, name);
+	name = temp_file(m, ".c", name);
 	f = new_ccan_file(m, talloc_dirname(m, name), talloc_basename(m, name));
 	talloc_steal(f, name);
 	list_add_tail(&m->examples, &f->list);
@@ -59,7 +58,6 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
 
 /* FIXME: We should have one example per function in header. */
 static void extract_examples(struct manifest *m,
-			     bool keep,
 			     unsigned int *timeleft,
 			     struct score *score)
 {
@@ -70,7 +68,7 @@ static void extract_examples(struct manifest *m,
 	score->total = 2;
 	list_for_each(get_ccan_file_docs(m->info_file), d, list) {
 		if (streq(d->type, "example")) {
-			score->error = add_example(m, m->info_file, keep, d);
+			score->error = add_example(m, m->info_file, d);
 			if (score->error)
 				return;
 			have_info_example = true;
@@ -86,7 +84,7 @@ static void extract_examples(struct manifest *m,
 		mainh = f;
 		list_for_each(get_ccan_file_docs(f), d, list) {
 			if (streq(d->type, "example")) {
-				score->error = add_example(m, f, keep, d);
+				score->error = add_example(m, f, d);
 				if (score->error)
 					return;
 				have_header_example = true;

+ 0 - 1
tools/ccanlint/tests/examples_relevant.c

@@ -15,7 +15,6 @@
 #include <ctype.h>
 
 static void examples_relevant_check(struct manifest *m,
-				    bool keep,
 				    unsigned int *timeleft,
 				    struct score *score)
 {

+ 1 - 1
tools/ccanlint/tests/examples_run.c

@@ -225,7 +225,7 @@ static char *unexpected(struct ccan_file *i, const char *input,
 	return output;
 }
 
-static void run_examples(struct manifest *m, bool keep,
+static void run_examples(struct manifest *m,
 			 unsigned int *timeleft, struct score *score)
 {
 	struct ccan_file *i;

+ 1 - 2
tools/ccanlint/tests/hash_if.c

@@ -17,8 +17,7 @@
 #include <ctype.h>
 
 static void check_hash_if(struct manifest *m,
-				   bool keep,
-				   unsigned int *timeleft, struct score *score)
+			  unsigned int *timeleft, struct score *score)
 {
 	struct list_head *list;
 	const char *explanation =

+ 1 - 2
tools/ccanlint/tests/headers_idempotent.c

@@ -58,7 +58,7 @@ static void handle_idem(struct manifest *m, struct score *score)
 		if (!ask(q))
 			continue;
 
-		tmpname = maybe_temp_file(score, ".h", false, e->file->name);
+		tmpname = temp_file(score, ".h", e->file->name);
 		out = fopen(tmpname, "w");
 		if (!out)
 			err(1, "Opening %s", tmpname);
@@ -174,7 +174,6 @@ static void check_idem(struct ccan_file *f, struct score *score)
 }
 
 static void check_idempotent(struct manifest *m,
-			     bool keep,
 			     unsigned int *timeleft, struct score *score)
 {
 	struct ccan_file *f;

+ 2 - 3
tools/ccanlint/tests/info_documentation_exists.c

@@ -59,9 +59,8 @@ static void create_info_template_doc(struct manifest *m, struct score *score)
 }
 
 static void check_info_documentation_exists(struct manifest *m,
-					 bool keep,
-					 unsigned int *timeleft,
-					 struct score *score)
+					    unsigned int *timeleft,
+					    struct score *score)
 {
 	struct list_head *infodocs = get_ccan_file_docs(m->info_file);
 	struct doc_section *d;

+ 0 - 1
tools/ccanlint/tests/info_exists.c

@@ -13,7 +13,6 @@
 #include <ccan/talloc/talloc.h>
 
 static void check_has_info(struct manifest *m,
-			   bool keep,
 			   unsigned int *timeleft,
 			   struct score *score)
 {

+ 0 - 1
tools/ccanlint/tests/info_summary_single_line.c

@@ -5,7 +5,6 @@
 #include <ccan/str/str.h>
 
 static void check_info_summary_single_line(struct manifest *m,
-					   bool keep,
 					   unsigned int *timeleft,
 					   struct score *score)
 {

+ 0 - 1
tools/ccanlint/tests/license_comment.c

@@ -14,7 +14,6 @@
 #include <ccan/str_talloc/str_talloc.h>
 
 static void check_license_comment(struct manifest *m,
-				  bool keep,
 				  unsigned int *timeleft, struct score *score)
 {
 	struct list_head *list;

+ 0 - 1
tools/ccanlint/tests/license_depends_compat.c

@@ -14,7 +14,6 @@
 #include <ccan/str_talloc/str_talloc.h>
 
 static void check_license_depends_compat(struct manifest *m,
-					 bool keep,
 					 unsigned int *timeleft,
 					 struct score *score)
 {

+ 0 - 1
tools/ccanlint/tests/license_exists.c

@@ -63,7 +63,6 @@ static void handle_license_link(struct manifest *m, struct score *score)
 extern struct ccanlint license_exists;
 
 static void check_has_license(struct manifest *m,
-			      bool keep,
 			      unsigned int *timeleft, struct score *score)
 {
 	char buf[PATH_MAX];

+ 0 - 1
tools/ccanlint/tests/license_file_compat.c

@@ -14,7 +14,6 @@
 #include <ccan/str_talloc/str_talloc.h>
 
 static void check_license_file_compat(struct manifest *m,
-				      bool keep,
 				      unsigned int *timeleft,
 				      struct score *score)
 {

+ 2 - 3
tools/ccanlint/tests/main_header_compiles.c

@@ -36,7 +36,6 @@ static struct ccan_file *main_header(struct manifest *m)
 }
 
 static void check_includes_build(struct manifest *m,
-				 bool keep,
 				 unsigned int *timeleft, struct score *score)
 {
 	char *contents;
@@ -44,8 +43,8 @@ static void check_includes_build(struct manifest *m,
 	int fd;
 	struct ccan_file *mainh = main_header(m);
 
-	tmpsrc = maybe_temp_file(m, "-included.c", keep, mainh->fullname);
-	tmpobj = maybe_temp_file(m, ".o", keep, tmpsrc);
+	tmpsrc = temp_file(m, "-included.c", mainh->fullname);
+	tmpobj = temp_file(m, ".o", tmpsrc);
 
 	fd = open(tmpsrc, O_WRONLY | O_CREAT | O_EXCL, 0600);
 	if (fd < 0)

+ 0 - 1
tools/ccanlint/tests/main_header_exists.c

@@ -13,7 +13,6 @@
 #include <ccan/noerr/noerr.h>
 
 static void check_has_main_header(struct manifest *m,
-				  bool keep,
 				  unsigned int *timeleft, struct score *score)
 {
 	struct ccan_file *f;

+ 3 - 16
tools/ccanlint/tests/module_builds.c

@@ -35,26 +35,13 @@ static char *obj_list(const struct manifest *m, enum compile_type ctype)
 	return list;
 }
 
-char *build_module(struct manifest *m, bool keep,
+char *build_module(struct manifest *m,
 		   enum compile_type ctype, char **errstr)
 {
-	char *name = link_objects(m, m->basename, false, obj_list(m, ctype),
-				  errstr);
-	if (name) {
-		if (keep) {
-			char *realname = talloc_asprintf(m, "%s.o", m->dir);
-			assert(ctype == COMPILE_NORMAL);
-			/* We leave this object file around, all built. */
-			if (!move_file(name, realname))
-				err(1, "Renaming %s to %s", name, realname);
-			name = realname;
-		}
-	}
-	return name;
+	return link_objects(m, m->basename, obj_list(m, ctype), errstr);
 }
 
 static void do_build(struct manifest *m,
-		     bool keep,
 		     unsigned int *timeleft,
 		     struct score *score)
 {
@@ -68,7 +55,7 @@ static void do_build(struct manifest *m,
 	}
 
 	m->compiled[COMPILE_NORMAL]
-		= build_module(m, keep, COMPILE_NORMAL, &errstr);
+		= build_module(m, COMPILE_NORMAL, &errstr);
 	if (!m->compiled[COMPILE_NORMAL]) {
 		score_file_error(score, NULL, 0, "%s", errstr);
 		return;

+ 2 - 3
tools/ccanlint/tests/module_links.c

@@ -49,7 +49,6 @@ static char *lib_list(const struct manifest *m)
 }
 
 static void check_use_build(struct manifest *m,
-			    bool keep,
 			    unsigned int *timeleft, struct score *score)
 {
 	char *contents;
@@ -57,7 +56,7 @@ static void check_use_build(struct manifest *m,
 	char *basename = talloc_asprintf(m, "%s/example.c", m->dir);
 	int fd;
 
-	tmpfile = maybe_temp_file(m, ".c", keep, basename);
+	tmpfile = temp_file(m, ".c", basename);
 
 	fd = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
 	if (fd < 0)
@@ -76,7 +75,7 @@ static void check_use_build(struct manifest *m,
 
 	if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
 			     compiler, cflags, lib_list(m),
-			     maybe_temp_file(m, "", keep, tmpfile),
+			     temp_file(m, "", tmpfile),
 			     &cmdout)) {
 		score->pass = true;
 		score->score = score->total;

+ 0 - 1
tools/ccanlint/tests/no_trailing_whitespace.c

@@ -22,7 +22,6 @@ static char *get_trailing_whitespace(const char *line)
 }
 
 static void check_trailing_whitespace(struct manifest *m,
-				      bool keep,
 				      unsigned int *timeleft,
 				      struct score *score)
 {

+ 3 - 4
tools/ccanlint/tests/objects_build.c

@@ -23,7 +23,7 @@ static const char *can_build(struct manifest *m)
 }
 
 void build_objects(struct manifest *m,
-		   bool keep, struct score *score, const char *flags,
+		   struct score *score, const char *flags,
 		   enum compile_type ctype)
 {
 	struct ccan_file *i;
@@ -38,7 +38,7 @@ void build_objects(struct manifest *m,
 		char *output;
 		char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
 
-		i->compiled[ctype] = maybe_temp_file(m, "", keep, fullfile);
+		i->compiled[ctype] = temp_file(m, "", fullfile);
 		if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
 				    i->compiled[ctype], &output)) {
 			talloc_free(i->compiled[ctype]);
@@ -62,10 +62,9 @@ void build_objects(struct manifest *m,
 }
 
 static void check_objs_build(struct manifest *m,
-			     bool keep,
 			     unsigned int *timeleft, struct score *score)
 {
-	build_objects(m, keep, score, cflags, COMPILE_NORMAL);
+	build_objects(m, score, cflags, COMPILE_NORMAL);
 }
 
 struct ccanlint objects_build = {

+ 6 - 8
tools/ccanlint/tests/objects_build_with_stringchecks.c

@@ -58,14 +58,13 @@ static int start_file(const char *filename)
 static void test_compile(struct score *score,
 			 struct ccan_file *file,
 			 const char *filename,
-			 bool keep,
 			 const char *flags,
 			 bool *errors,
 			 bool *warnings)
 {
 	char *output, *compiled;
 
-	compiled = maybe_temp_file(score, "", keep, filename);
+	compiled = temp_file(score, "", filename);
 	if (!compile_object(score, filename, ccan_dir, compiler, flags,
 			    compiled, &output)) {
 		score_file_error(score, file, 0,
@@ -95,7 +94,7 @@ static struct ccan_file *get_main_header(struct manifest *m)
 }
 
 static void build_objects_with_stringchecks(struct manifest *m,
-					    bool keep, unsigned int *timeleft,
+					    unsigned int *timeleft,
 					    struct score *score)
 {
 	struct ccan_file *i;
@@ -110,21 +109,20 @@ static void build_objects_with_stringchecks(struct manifest *m,
 	if (list_empty(&m->c_files)) {
 		char *line;
 		i = get_main_header(m);
-		tmp = maybe_temp_file(score, ".c", keep, i->fullname);
+		tmp = temp_file(score, ".c", i->fullname);
 		tmpfd = start_file(tmp);
 		line = talloc_asprintf(score, "#include <ccan/%s/%s.h>\n",
 				       m->basename, m->basename);
 		write_str(tmpfd, line);
 		close(tmpfd);
-		test_compile(score, i, tmp, keep, flags, &errors, &warnings);
+		test_compile(score, i, tmp, flags, &errors, &warnings);
 	} else {
 		list_for_each(&m->c_files, i, list) {
-			tmp = maybe_temp_file(score, ".c", keep, i->fullname);
+			tmp = temp_file(score, ".c", i->fullname);
 			tmpfd = start_file(tmp);
 			write_str(tmpfd, get_ccan_file_contents(i));
 			close(tmpfd);
-			test_compile(score, i, tmp, keep, flags,
-				     &errors, &warnings);
+			test_compile(score, i, tmp, flags, &errors, &warnings);
 		}
 	}
 

+ 1 - 2
tools/ccanlint/tests/objects_build_without_features.c

@@ -4,13 +4,12 @@
 #include "build.h"
 
 static void check_objs_build_without_features(struct manifest *m,
-					      bool keep,
 					      unsigned int *timeleft,
 					      struct score *score)
 {
 	const char *flags = talloc_asprintf(score, "%s %s",
 					    REDUCE_FEATURES_FLAGS, cflags);
-	build_objects(m, keep, score, flags, COMPILE_NOFEAT);
+	build_objects(m, score, flags, COMPILE_NOFEAT);
 }
 
 struct ccanlint objects_build_without_features = {

+ 0 - 1
tools/ccanlint/tests/reduce_features.c

@@ -129,7 +129,6 @@ static struct htable_option *get_config_options(struct manifest *m)
 }
 
 static void do_reduce_features(struct manifest *m,
-			       bool keep,
 			       unsigned int *timeleft, struct score *score)
 {
 	struct htable_option *options_used, *options_avail, *options;

+ 8 - 14
tools/ccanlint/tests/tests_compile.c

@@ -69,7 +69,6 @@ static bool compile(const void *ctx,
 		    struct ccan_file *file,
 		    bool fail,
 		    bool link_with_module,
-		    bool keep,
 		    enum compile_type ctype,
 		    char **output)
 {
@@ -81,7 +80,7 @@ static bool compile(const void *ctx,
 				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),
@@ -99,13 +98,12 @@ 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);
+	file->compiled[ctype] = temp_file(ctx, "", file->fullname);
 	flags = talloc_asprintf(ctx, "%s%s",
 				cflags,
 				ctype == COMPILE_NOFEAT
@@ -117,7 +115,7 @@ static void compile_async(const void *ctx,
 			       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 +128,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 +153,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 +166,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 +181,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 +204,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 = {

+ 4 - 8
tools/ccanlint/tests/tests_compile_coverage.c

@@ -32,13 +32,11 @@ static void cov_compile(const void *ctx,
 			unsigned int time_ms,
 			struct manifest *m,
 			struct ccan_file *file,
-			bool link_with_module,
-			bool keep)
+			bool link_with_module)
 {
 	char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
 
-	file->compiled[COMPILE_COVERAGE]
-		= maybe_temp_file(ctx, "", keep, file->fullname);
+	file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
 	compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
 			       test_obj_list(m, link_with_module,
 					     COMPILE_NORMAL,
@@ -50,7 +48,6 @@ static void cov_compile(const void *ctx,
 
 /* FIXME: Coverage from testable examples as well. */
 static void do_compile_coverage_tests(struct manifest *m,
-				      bool keep,
 				      unsigned int *timeleft,
 				      struct score *score)
 {
@@ -62,7 +59,7 @@ static void do_compile_coverage_tests(struct manifest *m,
 
 	/* For API tests, we need coverage version of module. */
 	if (!list_empty(&m->api_tests)) {
-		build_objects(m, keep, score, f, COMPILE_COVERAGE);
+		build_objects(m, score, f, COMPILE_COVERAGE);
 		if (!score->pass) {
 			score->error = talloc_strdup(score,
 						     "Failed to compile module objects with coverage");
@@ -72,8 +69,7 @@ static void do_compile_coverage_tests(struct manifest *m,
 
 	foreach_ptr(h, &m->run_tests, &m->api_tests) {
 		list_for_each(h, i, list) {
-			cov_compile(m, *timeleft, m, i, h == &m->api_tests,
-				    keep);
+			cov_compile(m, *timeleft, m, i, h == &m->api_tests);
 		}
 	}
 

+ 0 - 11
tools/ccanlint/tests/tests_coverage.c

@@ -127,7 +127,6 @@ static void analyze_coverage(struct manifest *m, bool full_gcov,
 }
 
 static void do_run_coverage_tests(struct manifest *m,
-				  bool keep,
 				  unsigned int *timeleft, struct score *score)
 {
 	struct ccan_file *i;
@@ -144,16 +143,6 @@ static void do_run_coverage_tests(struct manifest *m,
 				 full_gcov ? "" : "-n",
 				 outdir);
 
-	/* Unlink these files afterwards. */
-	if (!keep) {
-		talloc_set_destructor(talloc_asprintf(score,
-						      "%s/run.gcno", outdir),
-				      unlink_file_destructor);
-		talloc_set_destructor(talloc_asprintf(score,
-						      "%s/run.gcda", outdir),
-				      unlink_file_destructor);
-	}
-
 	/* Run them all. */
 	foreach_ptr(list, &m->run_tests, &m->api_tests) {
 		list_for_each(list, i, list) {

+ 0 - 1
tools/ccanlint/tests/tests_exist.c

@@ -94,7 +94,6 @@ static void handle_no_tests(struct manifest *m, struct score *score)
 }
 
 static void check_tests_exist(struct manifest *m,
-			    bool keep,
 			    unsigned int *timeleft, struct score *score)
 {
 	struct stat st;

+ 4 - 10
tools/ccanlint/tests/tests_helpers_compile.c

@@ -23,19 +23,17 @@ static const char *can_run(struct manifest *m)
 }
 
 static bool compile(struct manifest *m,
-		    bool keep,
 		    struct ccan_file *cfile,
 		    const char *flags,
 		    enum compile_type ctype,
 		    char **output)
 {
-	cfile->compiled[ctype] = maybe_temp_file(m, ".o", keep, cfile->fullname);
+	cfile->compiled[ctype] = temp_file(m, ".o", cfile->fullname);
 	return compile_object(m, cfile->fullname, ccan_dir, compiler, flags,
 			      cfile->compiled[ctype], output);
 }
 
 static void compile_test_helpers(struct manifest *m,
-				 bool keep,
 				 unsigned int *timeleft,
 				 struct score *score,
 				 const char *flags,
@@ -52,7 +50,7 @@ static void compile_test_helpers(struct manifest *m,
 	list_for_each(&m->other_test_c_files, i, list) {
 		char *cmdout;
 
-		if (!compile(m, keep, i, flags, ctype, &cmdout)) {
+		if (!compile(m, i, flags, ctype, &cmdout)) {
 			errors = true;
 			score_file_error(score, i, 0, "Compile failed:\n%s",
 					 cmdout);
@@ -70,12 +68,10 @@ static void compile_test_helpers(struct manifest *m,
 }
 
 static void do_compile_test_helpers(struct manifest *m,
-				    bool keep,
 				    unsigned int *timeleft,
 				    struct score *score)
 {
-	compile_test_helpers(m, keep, timeleft, score, cflags,
-			     COMPILE_NORMAL);
+	compile_test_helpers(m, timeleft, score, cflags, COMPILE_NORMAL);
 }
 
 struct ccanlint tests_helpers_compile = {
@@ -96,7 +92,6 @@ static const char *features_reduced(struct manifest *m)
 }
 
 static void do_compile_test_helpers_without_features(struct manifest *m,
-						     bool keep,
 						     unsigned int *timeleft,
 						     struct score *score)
 {
@@ -105,8 +100,7 @@ static void do_compile_test_helpers_without_features(struct manifest *m,
 	flags = talloc_asprintf(score, "%s %s", cflags,
 				REDUCE_FEATURES_FLAGS);
 
-	compile_test_helpers(m, keep, timeleft, score, flags,
-			     COMPILE_NOFEAT);
+	compile_test_helpers(m, timeleft, score, flags, COMPILE_NOFEAT);
 }
 
 struct ccanlint tests_helpers_compile_without_features = {

+ 0 - 3
tools/ccanlint/tests/tests_pass.c

@@ -63,8 +63,6 @@ static void run_test(void *ctx,
 			i->valgrind_log = talloc_asprintf(m,
 					  "%s.valgrind-log",
 					  i->compiled[COMPILE_NORMAL]);
-			talloc_set_destructor(i->valgrind_log,
-					      unlink_file_destructor);
 
 			run_command_async(i, *timeleft,
 					  "valgrind -q"
@@ -83,7 +81,6 @@ static void run_test(void *ctx,
 }
 
 static void do_run_tests(struct manifest *m,
-			 bool keep,
 			 unsigned int *timeleft,
 			 struct score *score)
 {

+ 0 - 5
tools/ccanlint/tests/tests_pass_valgrind.c

@@ -146,7 +146,6 @@ static const char *concat(struct score *score, char *bits[])
 
 /* FIXME: Run examples, too! */
 static void do_run_tests_vg(struct manifest *m,
-			    bool keep,
 			    unsigned int *timeleft,
 			    struct score *score)
 {
@@ -170,9 +169,6 @@ static void do_run_tests_vg(struct manifest *m,
 				continue;
 			}
 
-			if (keep)
-				talloc_set_destructor(i->valgrind_log, NULL);
-
 			output = grab_file(i, i->valgrind_log, NULL);
 			/* No valgrind errors? */
 			if (!output || output[0] == '\0') {
@@ -191,7 +187,6 @@ static void do_run_tests_vg(struct manifest *m,
 }
 
 static void do_leakcheck_vg(struct manifest *m,
-			    bool keep,
 			    unsigned int *timeleft,
 			    struct score *score)
 {

+ 0 - 1
tools/ccanlint/tests/tests_pass_without_features.c

@@ -17,7 +17,6 @@
 
 /* We don't do these under valgrind: too slow! */
 static void do_run_tests_no_features(struct manifest *m,
-				     bool keep,
 				     unsigned int *timeleft,
 				     struct score *score)
 {

+ 2 - 2
tools/compile.c

@@ -5,10 +5,10 @@
 bool compile_verbose = false;
 
 /* Compile multiple object files into a single.  Returns NULL if fails. */
-char *link_objects(const void *ctx, const char *basename, bool in_pwd,
+char *link_objects(const void *ctx, const char *basename,
 		   const char *objs, char **errmsg)
 {
-	char *file = maybe_temp_file(ctx, ".o", in_pwd, basename);
+	char *file = temp_file(ctx, ".o", basename);
 
 	if (compile_verbose)
 		printf("Linking objects into %s\n", file);

+ 2 - 2
tools/depends.c

@@ -48,7 +48,7 @@ static char *compile_info(const void *ctx, const char *dir)
 	if (!info)
 		return NULL;
 
-	info_c_file = maybe_temp_file(ctx, ".c", false, "_info");
+	info_c_file = temp_file(ctx, ".c", "_info");
 	fd = open(info_c_file, O_WRONLY|O_CREAT|O_EXCL, 0600);
 	if (fd < 0)
 		return NULL;
@@ -62,7 +62,7 @@ static char *compile_info(const void *ctx, const char *dir)
 	if (strrchr(ccandir, '/'))
 		*strrchr(ccandir, '/') = '\0';
 
-	compiled = maybe_temp_file(ctx, "", false, "info");
+	compiled = temp_file(ctx, "", "info");
 	if (compile_and_link(ctx, info_c_file, ccandir, "",
 			     CCAN_COMPILER, CCAN_CFLAGS " -I.", "",
 			     compiled, &output))

+ 2 - 6
tools/tools.c

@@ -213,8 +213,7 @@ int unlink_file_destructor(char *filename)
 	return 0;
 }
 
-char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
-		      const char *srcname)
+char *temp_file(const void *ctx, const char *extension, const char *srcname)
 {
 	unsigned baselen;
 	char *f, *suffix = talloc_strdup(ctx, "");
@@ -237,10 +236,7 @@ char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
 	} while (lstat(f, &st) == 0);
 
 	if (tools_verbose)
-		printf("Creating %sfile %s\n", keep ? "" : "temporary ", f);
-
-	if (!keep)
-		talloc_set_destructor(f, unlink_file_destructor);
+		printf("Creating file %s\n", f);
 
 	talloc_free(suffix);
 	return f;

+ 3 - 4
tools/tools.h

@@ -53,7 +53,7 @@ bool move_file(const char *oldname, const char *newname);
 /* If set, say what we're compiling to. */
 extern bool compile_verbose;
 /* Compile multiple object files into a single. */
-char *link_objects(const void *ctx, const char *basename, bool in_pwd,
+char *link_objects(const void *ctx, const char *basename,
 		   const char *objs, char **errmsg);
 /* Compile a single C file to an object file.  Returns false if fails. */
 bool compile_object(const void *ctx, const char *cfile, const char *ccandir,
@@ -66,9 +66,8 @@ bool compile_and_link(const void *ctx, const char *cfile, const char *ccandir,
 		      const char *compiler, const char *cflags,
 		      const char *libs, const char *outfile, char **output);
 
-/* If in_pwd is false, return a file int temp_dir, otherwise a local file. */
-char *maybe_temp_file(const void *ctx, const char *extension, bool in_pwd,
-		      const char *srcname);
+/* Returns a file in temp_dir() */
+char *temp_file(const void *ctx, const char *extension, const char *srcname);
 
 /* Default wait for run_command.  Should never time out. */
 extern const unsigned int default_timeout_ms;