]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: Add cflags support to _info
authorAndrew Jeffery <andrew@aj.id.au>
Sat, 5 Sep 2015 13:00:43 +0000 (22:30 +0930)
committerAndrew Jeffery <andrew@aj.id.au>
Wed, 9 Sep 2015 14:32:35 +0000 (00:02 +0930)
tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/module_links.c
tools/ccanlint/tests/objects_build.c
tools/ccanlint/tests/tests_compile.c
tools/ccanlint/tests/tests_compile_coverage.c
tools/depends.c
tools/tools.h

index b10940ae8a3bb4c112ed4cd1fcbc726c2e88410e..745860668beddc8e158d3d5226dc3a4d0b4b849b 100644 (file)
@@ -126,6 +126,17 @@ static char *example_lib_list(const void *ctx, struct manifest **deps)
        return list;
 }
 
        return list;
 }
 
+static char *cflags_list(const struct manifest *m)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, cflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
 /* FIXME: Test with reduced features! */
 static bool compile(const void *ctx,
                    struct manifest *m,
 /* FIXME: Test with reduced features! */
 static bool compile(const void *ctx,
                    struct manifest *m,
@@ -133,11 +144,12 @@ static bool compile(const void *ctx,
                    char **output)
 {
        struct manifest **deps = get_example_deps(m, file);
                    char **output)
 {
        struct manifest **deps = get_example_deps(m, file);
+       const char *flags = cflags_list(m);
 
        file->compiled[COMPILE_NORMAL] = temp_file(ctx, "", file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
                              example_obj_list(file, deps),
 
        file->compiled[COMPILE_NORMAL] = temp_file(ctx, "", file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
                              example_obj_list(file, deps),
-                             compiler, cflags,
+                             compiler, flags,
                              example_lib_list(file, deps),
                              file->compiled[COMPILE_NORMAL],
                              output)) {
                              example_lib_list(file, deps),
                              file->compiled[COMPILE_NORMAL],
                              output)) {
index c3c638d7be1c3ba9cc9d3e1fddeedb0cf8185180..403fff1a56120d31926359ca64af51afd3480732 100644 (file)
@@ -41,6 +41,17 @@ static char *obj_list(const struct manifest *m)
        return list;
 }
 
        return list;
 }
 
+static char *cflags_list(const struct manifest *m)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, cflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
 static char *lib_list(const struct manifest *m)
 {
        unsigned int i;
 static char *lib_list(const struct manifest *m)
 {
        unsigned int i;
@@ -59,6 +70,7 @@ static void check_use_build(struct manifest *m,
        char *contents;
        char *tmpfile, *cmdout;
        int fd;
        char *contents;
        char *tmpfile, *cmdout;
        int fd;
+       char *flags;
 
        tmpfile = temp_file(m, ".c", "example.c");
 
 
        tmpfile = temp_file(m, ".c", "example.c");
 
@@ -77,8 +89,10 @@ static void check_use_build(struct manifest *m,
                err(1, "Failure writing to temporary file %s", tmpfile);
        close(fd);
 
                err(1, "Failure writing to temporary file %s", tmpfile);
        close(fd);
 
+       flags = cflags_list(m);
+
        if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
        if (compile_and_link(score, tmpfile, ccan_dir, obj_list(m),
-                            compiler, cflags, lib_list(m),
+                            compiler, flags, lib_list(m),
                             temp_file(m, "", tmpfile),
                             &cmdout)) {
                score->pass = true;
                             temp_file(m, "", tmpfile),
                             &cmdout)) {
                score->pass = true;
index d44b7e7464fd2410071697570fa9267a7de541bb..5e6daf7827a1c5104d5e9dd81c49f671e834ea5f 100644 (file)
@@ -22,6 +22,17 @@ static const char *can_build(struct manifest *m)
        return NULL;
 }
 
        return NULL;
 }
 
+static char *cflags_list(const struct manifest *m)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, cflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
 void build_objects(struct manifest *m,
                   struct score *score, const char *flags,
                   enum compile_type ctype)
 void build_objects(struct manifest *m,
                   struct score *score, const char *flags,
                   enum compile_type ctype)
@@ -65,7 +76,10 @@ void build_objects(struct manifest *m,
 static void check_objs_build(struct manifest *m,
                             unsigned int *timeleft, struct score *score)
 {
 static void check_objs_build(struct manifest *m,
                             unsigned int *timeleft, struct score *score)
 {
-       build_objects(m, score, cflags, COMPILE_NORMAL);
+       const char *flags;
+
+       flags = cflags_list(m);
+       build_objects(m, score, flags, COMPILE_NORMAL);
 }
 
 struct ccanlint objects_build = {
 }
 
 struct ccanlint objects_build = {
index c939055857021e93c105c2da2352840902b45698..f6995085c4f08d42ebe9a5c2feb9037a676f08c4 100644 (file)
@@ -66,6 +66,17 @@ char *test_lib_list(const struct manifest *m, enum compile_type ctype)
        return ret;
 }
 
        return ret;
 }
 
+static char *cflags_list(const struct manifest *m, const char *iflags)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, iflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
 static bool compile(const void *ctx,
                    struct manifest *m,
                    struct ccan_file *file,
 static bool compile(const void *ctx,
                    struct manifest *m,
                    struct ccan_file *file,
@@ -81,6 +92,7 @@ static bool compile(const void *ctx,
                        cflags,
                        ctype == COMPILE_NOFEAT
                        ? " "REDUCE_FEATURES_FLAGS : "");
                        cflags,
                        ctype == COMPILE_NOFEAT
                        ? " "REDUCE_FEATURES_FLAGS : "");
+       flags = cflags_list(m, flags);
 
        fname = temp_file(ctx, "", file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
 
        fname = temp_file(ctx, "", file->fullname);
        if (!compile_and_link(ctx, file->fullname, ccan_dir,
@@ -110,6 +122,7 @@ static void compile_async(const void *ctx,
                        cflags,
                        ctype == COMPILE_NOFEAT
                        ? " "REDUCE_FEATURES_FLAGS : "");
                        cflags,
                        ctype == COMPILE_NOFEAT
                        ? " "REDUCE_FEATURES_FLAGS : "");
+       flags = cflags_list(m, flags);
 
        compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
                               test_obj_list(m, link_with_module, ctype, ctype),
 
        compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
                               test_obj_list(m, link_with_module, ctype, ctype),
index ed9f4ce659ce28326c010e626fbed9bec9cae072..89308fe80ae9ae4a26ba97979bb11f7bf2725785 100644 (file)
@@ -31,6 +31,27 @@ static const char *can_run_coverage(struct manifest *m)
 #endif
 }
 
 #endif
 }
 
+static char *cflags_list(const struct manifest *m)
+{
+       unsigned int i;
+       char *ret = tal_strdup(m, cflags);
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&ret, " %s", flags[i]);
+       return ret;
+}
+
+static char *cflags_list_append(const struct manifest *m, char *iflags)
+{
+       unsigned int i;
+
+       char **flags = get_cflags(m, m->dir, get_or_compile_info);
+       for (i = 0; flags[i]; i++)
+               tal_append_fmt(&iflags, " %s", flags[i]);
+       return iflags;
+}
+
 static void cov_compile(const void *ctx,
                        unsigned int time_ms,
                        struct manifest *m,
 static void cov_compile(const void *ctx,
                        unsigned int time_ms,
                        struct manifest *m,
@@ -38,6 +59,7 @@ static void cov_compile(const void *ctx,
                        bool link_with_module)
 {
        char *flags = tal_fmt(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
                        bool link_with_module)
 {
        char *flags = tal_fmt(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
+       flags = cflags_list_append(m, flags);
 
        file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
        compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
 
        file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
        compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
@@ -58,7 +80,8 @@ static void do_compile_coverage_tests(struct manifest *m,
        struct ccan_file *i;
        struct list_head *h;
        bool ok;
        struct ccan_file *i;
        struct list_head *h;
        bool ok;
-       char *f = tal_fmt(score, "%s %s", cflags, COVERAGE_CFLAGS);
+       char *f = cflags_list(m);
+       tal_append_fmt(&f, " %s", COVERAGE_CFLAGS);
 
        /* For API tests, we need coverage version of module. */
        if (!list_empty(&m->api_tests)) {
 
        /* For API tests, we need coverage version of module. */
        if (!list_empty(&m->api_tests)) {
index dde2b3ae3673eef0094ae85c3fd8187a2d0dc78a..871a3e8712368a649dc3d2d478e696087496bd57 100644 (file)
@@ -228,12 +228,12 @@ get_all_deps(const void *ctx, const char *dir, const char *style,
 }
 
 /* Can return NULL: _info may not support 'libs'. */
 }
 
 /* Can return NULL: _info may not support 'libs'. */
-static char **get_one_libs(const void *ctx, const char *dir,
+static char **get_one_prop(const void *ctx, const char *dir, const char *prop,
                           char *(*get_info)(const void *ctx, const char *dir))
 {
        char *cmd, **lines;
 
                           char *(*get_info)(const void *ctx, const char *dir))
 {
        char *cmd, **lines;
 
-       cmd = tal_fmt(ctx, "%s libs", get_info(ctx, dir));
+       cmd = tal_fmt(ctx, "%s %s", get_info(ctx, dir), prop);
        lines = lines_from_cmd(cmd, "%s", cmd);
        /* Strip final NULL. */
        if (lines)
        lines = lines_from_cmd(cmd, "%s", cmd);
        /* Strip final NULL. */
        if (lines)
@@ -241,6 +241,18 @@ static char **get_one_libs(const void *ctx, const char *dir,
        return lines;
 }
 
        return lines;
 }
 
+static char **get_one_libs(const void *ctx, const char *dir,
+                          char *(*get_info)(const void *ctx, const char *dir))
+{
+       return get_one_prop(ctx, dir, "libs", get_info);
+}
+
+static char **get_one_cflags(const void *ctx, const char *dir,
+                          char *(*get_info)(const void *ctx, const char *dir))
+{
+       return get_one_prop(ctx, dir, "cflags", get_info);
+}
+
 /* O(n^2) but n is small. */
 static char **add_deps(char **deps1, char **deps2)
 {
 /* O(n^2) but n is small. */
 static char **add_deps(char **deps1, char **deps2)
 {
@@ -258,6 +270,18 @@ static char **add_deps(char **deps1, char **deps2)
        return deps1;
 }
 
        return deps1;
 }
 
+char **get_cflags(const void *ctx, const char *dir,
+        char *(*get_info)(const void *ctx, const char *dir))
+{
+       char **flags;
+       unsigned int len;
+       flags = get_one_cflags(ctx, dir, get_info);
+       len = tal_count(flags);
+       tal_resize(&flags, len + 1);
+       flags[len] = NULL;
+       return flags;
+}
+
 char **get_libs(const void *ctx, const char *dir, const char *style,
                char *(*get_info)(const void *ctx, const char *dir))
 {
 char **get_libs(const void *ctx, const char *dir, const char *style,
                char *(*get_info)(const void *ctx, const char *dir))
 {
index b4751bec51734230c5b49de868e31764dc8188d5..cfbe871f9bfb0228016f1e2ab80f0085480592ae 100644 (file)
@@ -43,6 +43,9 @@ char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
 char **get_libs(const void *ctx, const char *dir, const char *style,
                char *(*get_info)(const void *ctx, const char *dir));
 
 char **get_libs(const void *ctx, const char *dir, const char *style,
                char *(*get_info)(const void *ctx, const char *dir));
 
+char **get_cflags(const void *ctx, const char *dir,
+               char *(*get_info)(const void *ctx, const char *dir));
+
 /* From tools.c */
 /* If set, print all commands run, all output they give and exit status. */
 extern bool tools_verbose;
 /* From tools.c */
 /* If set, print all commands run, all output they give and exit status. */
 extern bool tools_verbose;