ccanlint: remove argument to -k/--keep
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 2 Dec 2011 03:37:24 +0000 (14:07 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 2 Dec 2011 03:37:24 +0000 (14:07 +1030)
It's much easier to simply say "keep all", and it simplifies the code
quite a bit.

42 files changed:
tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.h
tools/ccanlint/tests/avoids_cpp_reserved.c
tools/ccanlint/tests/build.h
tools/ccanlint/tests/depends_accurate.c
tools/ccanlint/tests/depends_build.c
tools/ccanlint/tests/depends_build_without_features.c
tools/ccanlint/tests/depends_exist.c
tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/examples_exist.c
tools/ccanlint/tests/examples_relevant.c
tools/ccanlint/tests/examples_run.c
tools/ccanlint/tests/hash_if.c
tools/ccanlint/tests/headers_idempotent.c
tools/ccanlint/tests/info_documentation_exists.c
tools/ccanlint/tests/info_exists.c
tools/ccanlint/tests/info_summary_single_line.c
tools/ccanlint/tests/license_comment.c
tools/ccanlint/tests/license_depends_compat.c
tools/ccanlint/tests/license_exists.c
tools/ccanlint/tests/license_file_compat.c
tools/ccanlint/tests/main_header_compiles.c
tools/ccanlint/tests/main_header_exists.c
tools/ccanlint/tests/module_builds.c
tools/ccanlint/tests/module_links.c
tools/ccanlint/tests/no_trailing_whitespace.c
tools/ccanlint/tests/objects_build.c
tools/ccanlint/tests/objects_build_with_stringchecks.c
tools/ccanlint/tests/objects_build_without_features.c
tools/ccanlint/tests/reduce_features.c
tools/ccanlint/tests/tests_compile.c
tools/ccanlint/tests/tests_compile_coverage.c
tools/ccanlint/tests/tests_coverage.c
tools/ccanlint/tests/tests_exist.c
tools/ccanlint/tests/tests_helpers_compile.c
tools/ccanlint/tests/tests_pass.c
tools/ccanlint/tests/tests_pass_valgrind.c
tools/ccanlint/tests/tests_pass_without_features.c
tools/compile.c
tools/depends.c
tools/tools.c
tools/tools.h

index 5abcb9e8920ddfd36bc7401031db928bbbfa5fa0..d31ef94058f6d63b0030f5e85c6e971edbc60189 100644 (file)
@@ -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,
index bf01161faf10c365428ed33b5954bd043f508294..fc92cd783c7dcd26a4717af2bbcca40d37f02351 100644 (file)
@@ -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;
 
index 68d4ad603b91479db6ff6b34acf35f473a02cf57..72b3604efa45478c4f8d59110d92bc37bca9880a 100644 (file)
@@ -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;
index 04140bf9bc68d74348bd22004682f75c484d75ae..5cc181ec77df40818c985b76845a466739d7f22a 100644 (file)
@@ -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 */
index e13eb1168bcb28568ee6e0aea349d49e021885df..d3670a62d58ae281ba79d92b0d088c921932932e 100644 (file)
@@ -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;
index ea5c39269bd183f8f25c965401e0ea834f7ff01a..e6300a19502559fc3a69effa3e6b6218cae75c2b 100644 (file)
@@ -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;
index dfa96d72c0fe3d0704a86ae244aef7c57af82b91..533f4f318ce869cfb48f83882aa713bea5457dfa 100644 (file)
@@ -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)
 {
index ff67857f8cdc5a98a89c00e8d948e6e12a6dff87..27bbfc4ed0f2c28a13868fba99987c2c4b9463b7 100644 (file)
@@ -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;
index 3cbb23fd024db87249408ea5950bf3e753b85af1..6602c54683ed3b215dfa1dd9a5780267b11ba5cb 100644 (file)
@@ -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++) {
index 847010af5f43ff0df075f583bcdfaf9bd5a926ce..7e9dd97cc8afa379ba227108e3fd0354c80b9aff 100644 (file)
@@ -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;
index 66dee27e65c427cc91bd4f67a5a7e1b04fe7f292..311c4787492e7bfb2ad1d3cbacbb1f314fe38ce4 100644 (file)
@@ -15,7 +15,6 @@
 #include <ctype.h>
 
 static void examples_relevant_check(struct manifest *m,
-                                   bool keep,
                                    unsigned int *timeleft,
                                    struct score *score)
 {
index 4b881724d35a3d359d933739009d2d45fac0febd..18bb849d3d0076ace733c28669cd33911bbd6930 100644 (file)
@@ -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;
index 9e10c3049e2d4132b9a3a068400212399cfe171b..13750e9451629b83b8cf3bce766eeb37bdcc85d3 100644 (file)
@@ -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 =
index 4b98b246bfcdacc24608e5b6352ec9a77c4b2de3..bf8c9f2dad8e61e406c40b6399aeae98fa12129b 100644 (file)
@@ -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;
index bef08608fa58854de785d1dcac6e5b276c6c2cd5..6d914648ca19e3852de76632d3b2fac69523f476 100644 (file)
@@ -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;
index 5e04bd8d42b6cf91cf04f2ef928e9d940446337e..330749ba46af0e076f91916c15cd6b4860a5b0e1 100644 (file)
@@ -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)
 {
index 4be98d43bf2f4d74bd36e908326f789ed517714b..e506d4ddee283b1aefe72dc031c63362f08df629 100644 (file)
@@ -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)
 {
index f1902126472c235df1e558a94e4649caa0ce021a..7152b20f7b7070a90086dcb3a02e70aa72fd6364 100644 (file)
@@ -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;
index c4f4cb7f98506bfdd40d2f1ffe895d95e71e0f88..6517a7fc5d6973a0bdcad1e06351acc2f0d0e745 100644 (file)
@@ -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)
 {
index 09a9b7e68c7054fe010f19418511663f4021d1ef..15d566d384693335cefd0fd58ae18e0d68e17b53 100644 (file)
@@ -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];
index 39b3752e72a3a6e30708b251aa0044e1e7ef0b0d..e7e2c8a18bc2ccb946a8ab5d7858726a74312102 100644 (file)
@@ -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)
 {
index 99f3aa38855928e8611dc0967f4ff854a65e6ed9..b4a12e1349297a4330f2cae800c6d580e517232a 100644 (file)
@@ -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)
index b6150dc844c8232e3e32528e8e01f49fc672bf37..f039a1882eeaa0883f589f7614d130b523f20bd0 100644 (file)
@@ -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;
index 52059af795846fafed7c09f11ddfe5d530b03ff4..cffb84bce34038db9e62beeb933550e4ab6e5ab9 100644 (file)
@@ -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;
index 0bf9821555d70b53c98f6c767b8b36726b58bc72..66f8954f4be381d982e8068cf3917b653682e1c8 100644 (file)
@@ -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;
index 5d3b5ca19d0b10f1b76fbda3fd2cdfcaa72426b7..5c5cf35bb68769ea1276756ac7a34c99147f5b1d 100644 (file)
@@ -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)
 {
index 8fc11266be6cef94199f4ef30e4de92bf47a6805..cbb3189513c034094eec05d522c0e78fa247ec0e 100644 (file)
@@ -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 = {
index 5c57155d1aaa6a45e42af55c80681ac3d3e7ab04..9aa6fd8432fa6a6c446f83875db46acc514c2286 100644 (file)
@@ -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);
                }
        }
 
index 770dd475a3a6583ce1f60f9b804afb80cac37a58..ab3bbb0ab13438660f527be73cd4e302994740e2 100644 (file)
@@ -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 = {
index 183d798f7bd501b8b9eaed8e8ce9a58d52e43b69..6b4bd1571a857e97a09dbb7b0cbb559fb14b5d5d 100644 (file)
@@ -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;
index ee1a6b2c2e2a8da010764b081c5e14c90567e729..911f310caf5e1d9800f37996600c427483c758b8 100644 (file)
@@ -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 = {
index accb9ffdc04af8ed1a5280031032a8e27c47167e..0d3e7e1db5f87342296643563c9b4e90afeba009 100644 (file)
@@ -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);
                }
        }
 
index ba677ceacf57f90090338d6a478239ac83999ca4..69ca0350d338072f3729461e11a69ba2dd820d58 100644 (file)
@@ -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) {
index 57fd4e11769e664b77afdab30a24f3a145c9a740..2fc1664fd254adda189ffd4a181bb9eeae3363a8 100644 (file)
@@ -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;
index baa5309f08c50a6c4c4b245452f382ee33376267..c1b82b8d2aa719564ed92069c4f32da1efebe138 100644 (file)
@@ -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 = {
index 6ec17396167122eb89eee33b14c3e5bae9543e24..e1dfba6aee63534430895430cccaa183f63dcf90 100644 (file)
@@ -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)
 {
index bf914856845f2a7a42e9cec97d210c9b7c3ef06a..8ccdad963ee072e88a32400ce3b3cba9f29ff987 100644 (file)
@@ -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)
 {
index cc650c24c88fdf1761cc8f089f75c1b213ec2365..cbb23baeae0cff8d8b45127adfe13fa13eabfe7d 100644 (file)
@@ -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)
 {
index ec7e2147b239ddb568acee8a87973dc05757db85..5a381a1408a6cd87aedf82803b7664c50cbe2161 100644 (file)
@@ -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);
index f1e45c50ebc5fb37c1cf8a44becfbd8141c56f2d..c107f4b330c28a2a2473da87aea02cb267a43d6b 100644 (file)
@@ -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))
index 0a29ddf8e64cce7875a8a9d8c8fe37a0c6d90a13..c8697320a9fd5616c5dfa1e04af686efec0c1a87 100644 (file)
@@ -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;
index f3e132d97a37110c92da61ba48d3f82e7c46f3e8..4ac9818307212ed790d5008061a79f06a2084744 100644 (file)
@@ -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;