]> git.ozlabs.org Git - ccan/commitdiff
tools/ccanlint: detect more unmentioned dependencies.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 26 May 2014 03:27:44 +0000 (12:57 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 27 May 2014 11:08:29 +0000 (20:38 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/ccanlint/tests/depends_accurate.c
tools/ccanlint/tests/headers_idempotent.c
tools/manifest.c
tools/manifest.h

index d7082fac296c68730383542dce0a82085aee03a3..a0fe6f32a36976886ae80ef90f48bf80dfb9a887 100644 (file)
@@ -53,10 +53,9 @@ static bool check_dep_includes(struct manifest *m,
                if (has_dep(m, deps, used, mod))
                        continue;
 
-               /* FIXME: we can't be sure about
-                * conditional includes, so don't
-                * complain. */
-               if (!li[i].cond) {
+               /* FIXME: we can't be sure about conditional includes,
+                * so don't complain (handle common case of idempotent wrap) */
+               if (!li[i].cond || li[i].cond == f->idempotent_cond) {
                        score_file_error(score, f, i+1,
                                         "%s not listed in _info", mod);
                        ok = false;
@@ -138,7 +137,7 @@ struct ccanlint depends_accurate = {
        .key = "depends_accurate",
        .name = "Module's CCAN dependencies are the only CCAN files #included",
        .check = check_depends_accurate,
-       .needs = "depends_exist test_depends_exist"
+       .needs = "depends_exist test_depends_exist headers_idempotent"
 };
 
 REGISTER_TEST(depends_accurate);
index 55fa9974b6d37c08edd6fc004e7068fdf25be974..1b2916bda3cb1ec1293ba59f7cda7f4b5ea6f8c8 100644 (file)
@@ -125,9 +125,10 @@ static void check_idem(struct ccan_file *f, struct score *score)
        if (!f->lines[i])
                return;
 
-       /* We expect a condition on this line. */
+       /* We expect a condition around this line. */
        if (!line_info[i].cond) {
-               score_file_error(score, f, i+1, "Expected #ifndef");
+               score_file_error(score, f, first_preproc_line+1,
+                                "Expected #ifndef");
                return;
        }
 
@@ -136,7 +137,8 @@ static void check_idem(struct ccan_file *f, struct score *score)
        /* We expect the condition to be ! IFDEF <symbol>. */
        if (line_info[i].cond->type != PP_COND_IFDEF
            || !line_info[i].cond->inverse) {
-               score_file_error(score, f, i+1, "Expected #ifndef");
+               score_file_error(score, f, first_preproc_line+1,
+                                "Expected #ifndef");
                return;
        }
 
@@ -157,6 +159,9 @@ static void check_idem(struct ccan_file *f, struct score *score)
                return;
        }
 
+       /* Record this for use in depends_accurate */
+       f->idempotent_cond = line_info[i].cond;
+
        /* Rest of code should all be covered by that conditional. */
        for (i++; f->lines[i]; i++) {
                unsigned int val = 0;
index 762550ea4122549c00d7363b413ea657d91ae53e..fe3e4680b2d49117338def1e27bfc3b2ff58607e 100644 (file)
@@ -78,6 +78,8 @@ struct ccan_file *new_ccan_file(const void *ctx, const char *dir,
        f->fullname = path_join(f, dir, f->name);
        f->contents = NULL;
        f->simplified = NULL;
+       f->idempotent_cond = NULL;
+
        return f;
 }
 
index d2de6437ed81d6ebb5197a0a2a56bbee528759d8..d11dbec8865d66a77f97d6374316126bd4d5bf7c 100644 (file)
@@ -80,6 +80,9 @@ struct ccan_file {
 
        /* Simplified stream (lowercase letters and single spaces) */
        char *simplified;
+
+       /* Condition for idempotent wrapper (filled by headers_idempotent) */
+       struct pp_conditions *idempotent_cond;
 };
 
 /* A new ccan_file, with the given dir and name (either can be take()). */