Browse Source

ccanlint: clean up reduced feature handling.

Putting the reduced config.h in the current directory means that it's
actually being picked up by other tests, such as the string checks.
So move it to a sub-directory where we need an explicit -I.

We also fix the dependencies, so that "--target
tests_pass_without_features" works.
Rusty Russell 14 years ago
parent
commit
939fab341c

+ 3 - 1
tools/ccanlint/tests/depends_build_without_features.c

@@ -13,6 +13,7 @@
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
+#include "reduce_features.h"
 #include "../compulsory_tests/build.h"
 
 static const char *can_build(struct manifest *m)
@@ -30,7 +31,8 @@ static void check_depends_built_without_features(struct manifest *m,
 	struct manifest *i;
 	char *flags;
 
-	flags = talloc_asprintf(score, "%s -I.", cflags);
+	flags = talloc_asprintf(score, "%s %s", cflags,
+				REDUCE_FEATURES_FLAGS);
 
 	list_for_each(&m->deps, i, list) {
 		char *errstr = build_submodule(i, flags, COMPILE_NOFEAT);

+ 3 - 1
tools/ccanlint/tests/objects_build_without_features.c

@@ -1,5 +1,6 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <ccan/talloc/talloc.h>
+#include "reduce_features.h"
 #include "../compulsory_tests/build.h"
 
 static void check_objs_build_without_features(struct manifest *m,
@@ -7,7 +8,8 @@ static void check_objs_build_without_features(struct manifest *m,
 					      unsigned int *timeleft,
 					      struct score *score)
 {
-	const char *flags = talloc_asprintf(score, "-I. %s", cflags);
+	const char *flags = talloc_asprintf(score, "%s %s",
+					    REDUCE_FEATURES_FLAGS, cflags);
 	build_objects(m, keep, score, flags, COMPILE_NOFEAT);
 }
 

+ 6 - 3
tools/ccanlint/tests/reduce_features.c

@@ -160,11 +160,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)
+		err(1, "Creating reduced-features directory");
+
+	fd = open("reduced-features/config.h", O_EXCL|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;
 }

+ 2 - 0
tools/ccanlint/tests/reduce_features.h

@@ -1,4 +1,6 @@
 #ifndef CCANLINT_REDUCE_FEATURES_H
 #define CCANLINT_REDUCE_FEATURES_H
 extern bool features_were_reduced;
+
+#define REDUCE_FEATURES_FLAGS "-Ireduced-features"
 #endif /* CCANLINT_REDUCE_FEATURES_H */

+ 3 - 2
tools/ccanlint/tests/tests_compile.c

@@ -78,7 +78,8 @@ static bool compile(const void *ctx,
 	flags = talloc_asprintf(ctx, "%s%s%s",
 				fail ? "-DFAIL " : "",
 				cflags,
-				ctype == COMPILE_NOFEAT ? " -I." : "");
+				ctype == COMPILE_NOFEAT
+				? " "REDUCE_FEATURES_FLAGS : "");
 
 	fname = maybe_temp_file(ctx, "", keep, file->fullname);
 	if (!compile_and_link(ctx, file->fullname, ccan_dir,
@@ -192,6 +193,6 @@ struct ccanlint tests_compile_without_features = {
 	.name = "Module tests compile (without features)",
 	.check = do_compile_tests_without_features,
 	.can_run = features_reduced,
-	.needs = "tests_helpers_compile_without_features reduce_features"
+	.needs = "tests_helpers_compile_without_features objects_build_without_features"
 };
 REGISTER_TEST(tests_compile_without_features);

+ 2 - 1
tools/ccanlint/tests/tests_helpers_compile.c

@@ -102,7 +102,8 @@ static void do_compile_test_helpers_without_features(struct manifest *m,
 {
 	char *flags;
 
-	flags = talloc_asprintf(score, "%s -I.", cflags);
+	flags = talloc_asprintf(score, "%s %s", cflags,
+				REDUCE_FEATURES_FLAGS);
 
 	compile_test_helpers(m, keep, timeleft, score, flags,
 			     COMPILE_NOFEAT);