]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: Move ccanlint test options from _info comments to code
authorDavid Gibson <david@gibson.dropbear.id.au>
Sat, 24 Dec 2016 12:58:19 +0000 (23:58 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Sat, 24 Dec 2016 12:58:19 +0000 (23:58 +1100)
Currently, _info files can specify options, or note expected failures, for
ccanlint checks in the _info file with specially structured comments. That
differs from most other things ccanlint gets from _info, where it instead
executes the info file with certain parameters.

This changes ccanlint and existing _info files to use the normal method for
the ccanlint test options as well.  This also has the advantage that an
info file can alter its test options based on things from config.h - in
some cases whether a test can work or not might depend on various things.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
14 files changed:
ccan/block_pool/_info
ccan/ccan_tokenizer/_info
ccan/coroutine/_info
ccan/crcsync/_info
ccan/deque/_info
ccan/generator/_info
ccan/minmax/_info
ccan/rszshm/_info
ccan/stringmap/_info
tools/ccanlint/ccanlint.c
tools/ccanlint/ccanlint.h
tools/ccanlint/tests/info_exists.c
tools/depends.c
tools/tools.h

index a42cdba4b5c6148ddf347ea3087cd2cc63cef3c8..e2169765a94e3e8ee05158e401599e139ea10ebe 100644 (file)
@@ -38,9 +38,6 @@
  * Author: Joey Adams <joeyadams3.14159@gmail.com>
  * License: MIT
  * Version: 0.1
- * Ccanlint:
- *     // We actually depend on the LGPL talloc
- *     license_depends_compat FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -53,5 +50,11 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We actually depend on the LGPL talloc */
+               printf("license_depends_compat FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index ee1477a9c31d6dc16359b0dabd54a13b9a4700d4..f5116b4fc80103957d6e74feb7ee1ac8b7def9c3 100644 (file)
  * }
  *
  * License: BSD (3 clause)
- *
- * Ccanlint:
- *     // We actually depend on the LGPL dependencies
- *     license_depends_compat FAIL
- *     // We don't put the license line in all files.
- *     license_comment FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -101,5 +95,13 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We actually depend on the LGPL dependencies */
+               printf("license_depends_compat FAIL\n");
+               /* We don't put the license line in all files. */
+               printf("license_comment FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index a99629c91172476d9134c746a7666f98bf7ee0cb..07e4b967e72777752a393eacafe32d7988afd12c 100644 (file)
  *
  * Author: David Gibson <david@gibson.dropbear.id.au>
  * License: LGPL (v2.1 or any later version)
- *
- * Ccanlint:
- *     // Context switching really confuses valgrind
- *     tests_pass_valgrind FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -40,5 +36,11 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* Context switching really confuses valgrind */
+               printf("tests_pass_valgrind FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index 9ebb8bd8a01e7e844ccc62e90bc0454d11904781..7516f447480603c7722b61020953b9716980af50 100644 (file)
@@ -71,9 +71,6 @@
  *
  * License: LGPL (v2.1 or any later version)
  * Author: Rusty Russell <rusty@rustcorp.com.au>
- * Ccanlint:
- *     // We actually depend on the GPL crc routines, so not really LGPL :(
- *     license_depends_compat FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -88,6 +85,11 @@ int main(int argc, char *argv[])
                printf("ccan/array_size\n");
                return 0;
        }
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We actually depend on the GPL crc routines, so not really LGPL :( */
+               printf("license_depends_compat FAIL\n");
+               return 0;
+       }
 
        return 1;
 }
index 63687b7421e96ef8e68336ea42e93318b7c788f2..1c5460f932b2b11976f143ac14980d431f4939db 100644 (file)
  *
  * License: APACHE-2
  * Author: Dan Good <dan@dancancode.com>
- *
- * Ccanlint:
- *     // uses statement expressions
- *     // supported by gcc, clang, icc, and some others, but not msvc
- *     // (see https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html)
- *     objects_build_without_features FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -142,5 +136,13 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* uses statement expressions
+                * supported by gcc, clang, icc, and some others, but not msvc
+                * (see https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) */
+               printf("objects_build_without_features FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index e40d7bbb28c602c5e8b984a41ab203e5e82943de..aa6048e9c3f27aa5701cc16c94881d37ec9eb39f 100644 (file)
  *
  * Author: David Gibson <david@gibson.dropbear.id.au>
  * License: LGPL (v2.1 or any later version)
- *
- * Ccanlint:
- *      // We need several gcc extensions
- *     objects_build_without_features FAIL
- *      tests_compile_without_features FAIL
- *     tests_helpers_compile_without_features FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -78,5 +72,13 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We need several gcc extensions */
+               printf("objects_build_without_features FAIL\n");
+               printf("tests_compile_without_features FAIL\n");
+               printf("tests_helpers_compile_without_features FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index 4d95336a92f73254e1660e329d76360d7a21a968..2f6437e610f2dba988d9062c7540faa2ae87a8b5 100644 (file)
  *
  * Author: David Gibson <david@gibson.dropbear.id.au>
  * License:  CC0 (Public domain)
- *
- * Ccanlint:
- *      // We need several gcc extensions
- *      tests_compile_without_features FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -42,5 +38,11 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We need several gcc extensions */
+               printf("tests_compile_without_features FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index cc95400ce64f53bc0496b74bb2be4d2351197b33..e9122e0b78b76dd0489286c7cbe28f912d154b24 100644 (file)
  *     // $ tail -c +29 /dev/shm/rszshm_LAsEvt/0 | sed 's/./&\n/g' | sort | uniq -c | tr '\n' '\t'; echo
  *     //  515532 A   527251 B    512930 C    513062 D    544326 E    545876 F    512936 G    522363 H
  *
- * Ccanlint: tests_pass_valgrind FAIL
  * License: APACHE-2
  * Author: Dan Good <dan@dancancode.com>
- *
- * Ccanlint:
- *     // tests use optional macros containing statement expressions
- *     tests_compile_without_features FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -93,5 +88,12 @@ int main(int argc, char *argv[])
        if (strcmp(argv[1], "depends") == 0)
                return 0;
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               printf("tests_pass_valgrind FAIL\n");
+               /* tests use optional macros containing statement expressions */
+               printf("tests_compile_without_features FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index 1f6465b6c8c46cf93421369c15e63cc2f42c386c..c01c576c27fecfec243761af30295b8bdb6cc7cf 100644 (file)
@@ -52,9 +52,6 @@
  * Authors: Joey Adams, Anders Magnusson
  * License: BSD (3 clause)
  * Version: 0.2
- * Ccanlint:
- *     // We actually depend (indirectly) on the LGPL talloc
- *     license_depends_compat FAIL
  */
 int main(int argc, char *argv[])
 {
@@ -67,5 +64,11 @@ int main(int argc, char *argv[])
                return 0;
        }
 
+       if (strcmp(argv[1], "ccanlint") == 0) {
+               /* We actually depend (indirectly) on the LGPL talloc */
+               printf("license_depends_compat FAIL\n");
+               return 0;
+       }
+
        return 1;
 }
index 0ed969cb868ef8fc5f7f38f61465653244bfc1ed..f06f200b8daf0017ebe68fc655ac393747e7cbf6 100644 (file)
@@ -456,50 +456,43 @@ static void add_options(struct ccanlint *test, char **options,
        memcpy(&test->options[num], options, (num_options + 1)*sizeof(char *));
 }
 
-void add_info_options(struct ccan_file *info)
+void add_info_options(struct manifest *m)
 {
-       struct doc_section *d;
        unsigned int i;
-       struct ccanlint *test;
+       char **info_options = get_ccanlint(m, m->dir, get_or_compile_info);
 
-       list_for_each(get_ccan_file_docs(info), d, list) {
-               if (!streq(d->type, "ccanlint"))
+       for (i = 0; info_options[i]; i++) {
+               char **words = tal_strsplit(m, info_options[i], " \t",
+                                           STR_NO_EMPTY);
+               struct ccanlint *test;
+
+               if (!words[0])
+                       continue;
+
+               test = find_test(words[0]);
+               if (!test) {
+                       warnx("%s: unknown ccanlint test '%s'",
+                             m->info_file->fullname, words[0]);
                        continue;
+               }
+
+               if (!words[1]) {
+                       warnx("%s: no argument to test '%s'",
+                             m->info_file->fullname, words[0]);
+                       continue;
+               }
 
-               for (i = 0; i < d->num_lines; i++) {
-                       char **words = tal_strsplit(d, d->lines[i], " \t",
-                                                   STR_NO_EMPTY);
-                       if (!words[0])
-                               continue;
-
-                       if (strncmp(words[0], "//", 2) == 0)
-                               continue;
-
-                       test = find_test(words[0]);
-                       if (!test) {
-                               warnx("%s: unknown ccanlint test '%s'",
-                                     info->fullname, words[0]);
-                               continue;
-                       }
-
-                       if (!words[1]) {
-                               warnx("%s: no argument to test '%s'",
-                                     info->fullname, words[0]);
-                               continue;
-                       }
-
-                       /* Known failure? */
-                       if (strcasecmp(words[1], "FAIL") == 0) {
-                               if (!targeting)
-                                       skip_test_and_deps(test,
-                                                          "excluded in _info"
-                                                          " file");
-                       } else {
-                               if (!test->takes_options)
-                                       warnx("%s: %s doesn't take options",
-                                             info->fullname, words[0]);
-                               add_options(test, words+1, tal_count(words)-1);
-                       }
+               /* Known failure? */
+               if (strcasecmp(words[1], "FAIL") == 0) {
+                       if (!targeting)
+                               skip_test_and_deps(test,
+                                                  "excluded in _info"
+                                                  " file");
+               } else {
+                       if (!test->takes_options)
+                               warnx("%s: %s doesn't take options",
+                                     m->info_file->fullname, words[0]);
+                       add_options(test, words+1, tal_count(words)-1);
                }
        }
 }
index 9cb858f7d6a02e715eda56ac38d92d133e846066..7df951084f3aec4dd1ddbec10072c0d879c735a4 100644 (file)
@@ -186,7 +186,7 @@ struct dependent {
 bool is_excluded(const char *name);
 
 /* Called to add options from _info, once it's located. */
-void add_info_options(struct ccan_file *info);
+void add_info_options(struct manifest *m);
 
 /* Are we happy to compile stuff, or just non-intrusive tests? */
 extern bool safe_mode;
index 5e4459bcbe02d362213bcf35e99a33c37c14f175..8f01946f7ff018dfaa01d0acdf6e17d8f2e86cdb 100644 (file)
@@ -20,7 +20,7 @@ static void check_has_info(struct manifest *m,
        if (m->info_file) {
                score->pass = true;
                score->score = score->total;
-               add_info_options(m->info_file);
+               add_info_options(m);
        } else {
                score->error = tal_strdup(score,
        "You have no _info file.\n\n"
index f1ff30904c897d92fef28ba54cd7c41608af76c5..95bda1b50a7b33088f41345a7369fa5e982ffa21 100644 (file)
@@ -253,6 +253,12 @@ static char **get_one_cflags(const void *ctx, const char *dir,
        return get_one_prop(ctx, dir, "cflags", get_info);
 }
 
+static char **get_one_ccanlint(const void *ctx, const char *dir,
+                              char *(*get_info)(const void *ctx, const char *dir))
+{
+       return get_one_prop(ctx, dir, "ccanlint", get_info);
+}
+
 /* O(n^2) but n is small. */
 static char **add_deps(char **deps1, char **deps2)
 {
@@ -282,6 +288,18 @@ char **get_cflags(const void *ctx, const char *dir,
        return flags;
 }
 
+char **get_ccanlint(const void *ctx, const char *dir,
+                   char *(*get_info)(const void *ctx, const char *dir))
+{
+       char **ccanlint;
+       unsigned int len;
+       ccanlint = get_one_ccanlint(ctx, dir, get_info);
+       len = tal_count(ccanlint);
+       tal_resize(&ccanlint, len + 1);
+       ccanlint[len] = NULL;
+       return ccanlint;
+}
+
 static char *get_one_ported(const void *ctx, const char *dir,
                            char *(*get_info)(const void *ctx, const char *dir))
 {
index 668c91ad1bca8a2042104eee49458e677cd2e17f..d29a25fbdfaf6697c5fb9827f2aa7a38a01bac03 100644 (file)
@@ -48,6 +48,9 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
 char **get_cflags(const void *ctx, const char *dir,
                char *(*get_info)(const void *ctx, const char *dir));
 
+char **get_ccanlint(const void *ctx, const char *dir,
+                   char *(*get_info)(const void *ctx, const char *dir));
+
 char *get_ported(const void *ctx, const char *dir, bool recurse,
                 char *(*get_info)(const void *ctx, const char *dir));