]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/reduce_features.c
ccanlint: don't remove HAVE_STRUCT_TIMESPEC when testing without features.
[ccan] / tools / ccanlint / tests / reduce_features.c
index 2a389ce555e39bb0f1145f61e77826fa3b075c92..d7f5c24209f845ae792233e53dd3c9b20d7729af 100644 (file)
@@ -40,7 +40,20 @@ static bool option_cmp(const char *name1, const char *name2)
        return streq(name1, name2);
 }
 
-HTABLE_DEFINE_TYPE(char, option_name, option_hash, option_cmp, option);
+HTABLE_DEFINE_TYPE(char, option_name, option_hash, option_cmp, htable_option);
+
+static struct htable_option *htable_option_new(void)
+{
+       struct htable_option *opts = malloc(sizeof(*opts));
+       htable_option_init(opts);
+       return opts;
+}
+
+static void htable_option_free(struct htable_option *opts)
+{
+       htable_option_clear(opts);
+       free(opts);
+}
 
 static unsigned int add_options(struct htable_option *opts,
                                struct pp_conditions *cond)
@@ -108,6 +121,9 @@ static struct htable_option *get_config_options(struct manifest *m)
                /* Don't override endian... */
                if (strends(sym, "_ENDIAN"))
                        continue;
+               /* Don't override HAVE_STRUCT_TIMESPEC. */
+               if (streq(sym, "HAVE_STRUCT_TIMESPEC"))
+                       continue;
                if (!get_token(&lines[i], "1"))
                        continue;
                htable_option_add(opts, sym);
@@ -116,7 +132,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;
@@ -160,11 +175,14 @@ static void do_reduce_features(struct manifest *m,
                hdr = talloc_asprintf_append
                        (hdr, "#undef %s\n#define %s 0\n", sym, sym);
        }
-       fd = open("config.h", O_EXCL|O_CREAT|O_RDWR, 0600);
+       if (mkdir("reduced-features", 0700) != 0 && errno != EEXIST)
+               err(1, "Creating reduced-features directory");
+
+       fd = open("reduced-features/config.h", O_TRUNC|O_CREAT|O_RDWR, 0600);
        if (fd < 0)
-               err(1, "Creating config.h");
+               err(1, "Creating reduced-features/config.h");
        if (!write_all(fd, hdr, strlen(hdr)))
-               err(1, "Writing config.h");
+               err(1, "Writing reduced-features/config.h");
        close(fd);
        features_were_reduced = true;
 }
@@ -174,6 +192,8 @@ struct ccanlint reduce_features = {
        .name = "Produce config.h with reduced features",
        .can_run = can_run,
        .check = do_reduce_features,
+       /* We only want to compile up versions with reduced featuress once
+        * objects for normal tests are built. */
        .needs = "tests_compile"
 };
 REGISTER_TEST(reduce_features);