]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: chdir to temporary dir so gcov files land there.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 27 Aug 2010 04:27:23 +0000 (13:57 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 27 Aug 2010 04:27:23 +0000 (13:57 +0930)
This means parallel "make check" works again.

tools/ccanlint/ccanlint.c
tools/ccanlint/tests/build-coverage.c
tools/ccanlint/tests/build-coverage.h [deleted file]
tools/ccanlint/tests/run-coverage.c
tools/tools.c
tools/tools.h

index 3555ad2a09d1ea083c1fba68aafbaed98f24cbc1..d65a4a43a7412632f6cbcfa0d0301f8c818d0cfe 100644 (file)
@@ -333,7 +333,7 @@ int main(int argc, char *argv[])
        unsigned int score = 0, total_score = 0;
        struct manifest *m;
        struct ccanlint *i;
        unsigned int score = 0, total_score = 0;
        struct manifest *m;
        struct ccanlint *i;
-       const char *prefix = "", *dir = ".";
+       const char *prefix = "", *dir = talloc_getcwd(NULL);
        
        init_tests();
 
        
        init_tests();
 
@@ -344,7 +344,11 @@ int main(int argc, char *argv[])
        while ((c = getopt(argc, argv, "sd:vnlx:t:k:")) != -1) {
                switch (c) {
                case 'd':
        while ((c = getopt(argc, argv, "sd:vnlx:t:k:")) != -1) {
                switch (c) {
                case 'd':
-                       dir = optarg;
+                       if (optarg[0] != '/')
+                               dir = talloc_asprintf_append(NULL, "%s/%s",
+                                                            dir, optarg);
+                       else
+                               dir = optarg;
                        prefix = talloc_append_string(talloc_basename(NULL,
                                                                      optarg),
                                                      ": ");
                        prefix = talloc_append_string(talloc_basename(NULL,
                                                                      optarg),
                                                      ": ");
@@ -383,6 +387,10 @@ int main(int argc, char *argv[])
        if (optind < argc)
                usage(argv[0]);
 
        if (optind < argc)
                usage(argv[0]);
 
+       /* 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));
+
        m = get_manifest(talloc_autofree_context(), dir);
 
        /* If you don't pass the compulsory tests, you don't even get a score */
        m = get_manifest(talloc_autofree_context(), dir);
 
        /* If you don't pass the compulsory tests, you don't even get a score */
index f1010204d0447221244c4b6466b3568a728f2187..7f75064219f495d514266559b5b25c9d79e94b91 100644 (file)
@@ -13,7 +13,6 @@
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
-#include "build-coverage.h"
 
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_coverage(struct manifest *m)
 
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_coverage(struct manifest *m)
@@ -87,23 +86,6 @@ static char *lib_list(const struct manifest *m)
        return ret;
 }
 
        return ret;
 }
 
-/* Grrr... gcov drops a turd in the current directory. */
-void move_gcov_turd(const char *dir,
-                   struct ccan_file *file, const char *extension)
-{
-       char *base, *gcovfile, *gcovdest;
-
-       base = talloc_basename(file, file->name);
-       gcovfile = talloc_asprintf(file, "%s/%.*s%s",
-                                  dir, strlen(base)-2, base, extension);
-       gcovdest = talloc_asprintf(file, "%s/%.*s%s",
-                                  talloc_dirname(base, file->cov_compiled),
-                                  strlen(base)-2, base, extension);
-       if (!move_file(gcovfile, gcovdest))
-               err(1, "Could not move %s to %s", gcovfile, gcovdest);
-       talloc_free(base);
-}
-
 static char *cov_compile(const void *ctx,
                         struct manifest *m,
                         struct ccan_file *file,
 static char *cov_compile(const void *ctx,
                         struct manifest *m,
                         struct ccan_file *file,
@@ -111,7 +93,6 @@ static char *cov_compile(const void *ctx,
                         bool keep)
 {
        char *errmsg;
                         bool keep)
 {
        char *errmsg;
-       char path[PATH_MAX];
 
        file->cov_compiled = maybe_temp_file(ctx, "", keep, file->fullname);
        errmsg = compile_and_link(ctx, file->fullname, ccan_dir,
 
        file->cov_compiled = maybe_temp_file(ctx, "", keep, file->fullname);
        errmsg = compile_and_link(ctx, file->fullname, ccan_dir,
@@ -123,7 +104,6 @@ static char *cov_compile(const void *ctx,
                return errmsg;
        }
 
                return errmsg;
        }
 
-       move_gcov_turd(getcwd(path, sizeof(path)), file, ".gcno");
        return NULL;
 }
 
        return NULL;
 }
 
diff --git a/tools/ccanlint/tests/build-coverage.h b/tools/ccanlint/tests/build-coverage.h
deleted file mode 100644 (file)
index 0bbac2b..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef CCANLINT_BUILD_COVERAGE_H
-#define CCANLINT_BUILD_COVERAGE_H
-
-/* FIXME: gcov dumps a file into a random dir. */
-void move_gcov_turd(const char *dir,
-                   struct ccan_file *file, const char *extension);
-
-#endif /* CCANLINT_BUILD_COVERAGE_H */
index 74247e32ac83f4c685551222adf6bd1688935d99..9e9769907b90b3ed3649d6d680d23ae86c3d3814 100644 (file)
@@ -14,7 +14,6 @@
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
-#include "build-coverage.h"
 
 struct coverage_result {
        float uncovered;
 
 struct coverage_result {
        float uncovered;
@@ -118,7 +117,6 @@ static void *do_run_coverage_tests(struct manifest *m,
                        return res;
                }
                covcmd = talloc_asprintf_append(covcmd, " %s", i->name);
                        return res;
                }
                covcmd = talloc_asprintf_append(covcmd, " %s", i->name);
-               move_gcov_turd(olddir, i, ".gcda");
        }
 
        list_for_each(&m->api_tests, i, list) {
        }
 
        list_for_each(&m->api_tests, i, list) {
@@ -129,7 +127,6 @@ static void *do_run_coverage_tests(struct manifest *m,
                        return res;
                }
                covcmd = talloc_asprintf_append(covcmd, " %s", i->name);
                        return res;
                }
                covcmd = talloc_asprintf_append(covcmd, " %s", i->name);
-               move_gcov_turd(olddir, i, ".gcda");
        }
 
        /* Now run gcov: we want output even if it succeeds. */
        }
 
        /* Now run gcov: we want output even if it succeeds. */
index 7de02e3b9dfdcc2ae1604d6db5c6d46a1466ecc7..eacfbf9c8d353ac89bb7e782b19d379e0aefd1a1 100644 (file)
@@ -172,7 +172,7 @@ static int unlink_all(char *dir)
        return 0;
 }
 
        return 0;
 }
 
-char *temp_file(const void *ctx, const char *extension)
+char *temp_dir(const void *ctx)
 {
        /* For first call, create dir. */
        while (!tmpdir) {
 {
        /* For first call, create dir. */
        while (!tmpdir) {
@@ -192,8 +192,13 @@ char *temp_file(const void *ctx, const char *extension)
                }
                talloc_set_destructor(tmpdir, unlink_all);
        }
                }
                talloc_set_destructor(tmpdir, unlink_all);
        }
+       return tmpdir;
+}
 
 
-       return talloc_asprintf(ctx, "%s/%u%s", tmpdir, count++, extension);
+char *temp_file(const void *ctx, const char *extension)
+{
+       return talloc_asprintf(ctx, "%s/%u%s",
+                              temp_dir(ctx), count++, extension);
 }
 
 char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
 }
 
 char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
index 35f6bd8c80dcf3ac31f1b4d2f7d7d765cca31bd6..fe3a3aedd3d03c1243c56e7d37809c12f376747b 100644 (file)
@@ -32,6 +32,7 @@ char *talloc_getcwd(const void *ctx);
 char *run_command(const void *ctx, unsigned int *time_ms, const char *fmt, ...);
 char *run_with_timeout(const void *ctx, const char *cmd,
                       bool *ok, unsigned *timeout_ms);
 char *run_command(const void *ctx, unsigned int *time_ms, const char *fmt, ...);
 char *run_with_timeout(const void *ctx, const char *cmd,
                       bool *ok, unsigned *timeout_ms);
+char *temp_dir(const void *ctx);
 char *temp_file(const void *ctx, const char *extension);
 bool move_file(const char *oldname, const char *newname);
 
 char *temp_file(const void *ctx, const char *extension);
 bool move_file(const char *oldname, const char *newname);