Browse Source

tools: add testdepends handling in _info.

This allows us to separate dependencies only needed for testing.
This matters: they don't have the same impact on licensing, nor necessarily
on end-users.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell 13 years ago
parent
commit
1842f55199

+ 9 - 3
tools/ccan_depends.c

@@ -12,6 +12,7 @@ int main(int argc, char *argv[])
 	bool compile = false;
 	bool compile = false;
 	bool recurse = true;
 	bool recurse = true;
 	bool ccan = true;
 	bool ccan = true;
+	const char *style = "depends";
 
 
 	if (argv[1] && streq(argv[1], "--direct")) {
 	if (argv[1] && streq(argv[1], "--direct")) {
 		argv++;
 		argv++;
@@ -28,8 +29,13 @@ int main(int argc, char *argv[])
 		argc--;
 		argc--;
 		ccan = false;
 		ccan = false;
 	}
 	}
+	if (argv[1] && streq(argv[1], "--tests")) {
+		argv++;
+		argc--;
+		style = "testdepends";
+	}
 	if (argc != 2)
 	if (argc != 2)
-		errx(1, "Usage: ccan_depends [--direct] [--compile] [--non-ccan] <dir>\n"
+		errx(1, "Usage: ccan_depends [--direct] [--compile] [--non-ccan] [--tests] <dir>\n"
 		        "Spits out all the ccan dependencies (recursively unless --direct)");
 		        "Spits out all the ccan dependencies (recursively unless --direct)");
 
 
 	/* We find depends without compiling by looking for ccan/ */
 	/* We find depends without compiling by looking for ccan/ */
@@ -38,10 +44,10 @@ int main(int argc, char *argv[])
 
 
 	if (compile)
 	if (compile)
 		deps = get_deps(talloc_autofree_context(), argv[1],
 		deps = get_deps(talloc_autofree_context(), argv[1],
-				recurse, compile_info);
+				style, recurse, compile_info);
 	else
 	else
 		deps = get_safe_ccan_deps(talloc_autofree_context(),
 		deps = get_safe_ccan_deps(talloc_autofree_context(),
-					  argv[1], recurse);
+					  argv[1], style, recurse);
 
 
 	for (i = 0; deps[i]; i++)
 	for (i = 0; deps[i]; i++)
 		if (strstarts(deps[i], "ccan/") == ccan)
 		if (strstarts(deps[i], "ccan/") == ccan)

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

@@ -55,9 +55,10 @@ static void check_depends_exist(struct manifest *m,
 	}
 	}
 
 
 	if (safe_mode)
 	if (safe_mode)
-		deps = get_safe_ccan_deps(m, m->dir, true);
+		deps = get_safe_ccan_deps(m, m->dir, "depends", true);
 	else
 	else
-		deps = get_deps(m, m->dir, true, get_or_compile_info);
+		deps = get_deps(m, m->dir, "depends", true,
+				get_or_compile_info);
 
 
 	for (i = 0; deps[i]; i++) {
 	for (i = 0; deps[i]; i++) {
 		if (!strstarts(deps[i], "ccan/"))
 		if (!strstarts(deps[i], "ccan/"))

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

@@ -62,7 +62,8 @@ static void add_dep(struct manifest ***deps, const char *basename)
 	if (m->info_file) {
 	if (m->info_file) {
 		char **infodeps;
 		char **infodeps;
 
 
-		infodeps = get_deps(m, m->dir, false, get_or_compile_info);
+		infodeps = get_deps(m, m->dir, "depends", false,
+				    get_or_compile_info);
 
 
 		for (i = 0; infodeps[i]; i++) {
 		for (i = 0; infodeps[i]; i++) {
 			if (strstarts(infodeps[i], "ccan/"))
 			if (strstarts(infodeps[i], "ccan/"))

+ 31 - 15
tools/depends.c

@@ -71,7 +71,7 @@ char *compile_info(const void *ctx, const char *dir)
 	return NULL;
 	return NULL;
 }
 }
 
 
-static char **get_one_deps(const void *ctx, const char *dir,
+static char **get_one_deps(const void *ctx, const char *dir, const char *style,
 			   char *(*get_info)(const void *ctx, const char *dir))
 			   char *(*get_info)(const void *ctx, const char *dir))
 {
 {
 	char **deps, *cmd;
 	char **deps, *cmd;
@@ -80,10 +80,15 @@ static char **get_one_deps(const void *ctx, const char *dir,
 	if (!infofile)
 	if (!infofile)
 		return NULL;
 		return NULL;
 
 
-	cmd = talloc_asprintf(ctx, "%s depends", infofile);
+	cmd = talloc_asprintf(ctx, "%s %s", infofile, style);
 	deps = lines_from_cmd(cmd, "%s", cmd);
 	deps = lines_from_cmd(cmd, "%s", cmd);
-	if (!deps)
-		err(1, "Could not run '%s'", cmd);
+	if (!deps) {
+		/* You must understand depends, maybe not testdepends. */
+		if (streq(style, "depends"))
+			err(1, "Could not run '%s'", cmd);
+		deps = talloc(ctx, char *);
+		deps[0] = NULL;
+	}
 	return deps;
 	return deps;
 }
 }
 
 
@@ -117,10 +122,12 @@ static char *replace(const void *ctx, const char *src,
 /* This is a terrible hack.  We scan for ccan/ strings. */
 /* This is a terrible hack.  We scan for ccan/ strings. */
 static char **get_one_safe_deps(const void *ctx,
 static char **get_one_safe_deps(const void *ctx,
 				const char *dir,
 				const char *dir,
+				const char *style,
 				char *(*unused)(const void *, const char *))
 				char *(*unused)(const void *, const char *))
 {
 {
 	char **deps, **lines, *raw, *fname;
 	char **deps, **lines, *raw, *fname;
 	unsigned int i, n;
 	unsigned int i, n;
+	bool correct_style = false;
 
 
 	fname = talloc_asprintf(ctx, "%s/_info", dir);
 	fname = talloc_asprintf(ctx, "%s/_info", dir);
 	raw = grab_file(fname, fname, NULL);
 	raw = grab_file(fname, fname, NULL);
@@ -140,6 +147,14 @@ static char **get_one_safe_deps(const void *ctx,
 		if (lines[i][0] == '#')
 		if (lines[i][0] == '#')
 			continue;
 			continue;
 
 
+		if (strstr(lines[i], "\"testdepends\""))
+			correct_style = streq(style, "testdepends");
+		else if (strstr(lines[i], "\"depends\""))
+			correct_style = streq(style, "depends");
+
+		if (!correct_style)
+			continue;
+
 		/* Start of line, or after ". */
 		/* Start of line, or after ". */
 		if (strstarts(lines[i], "ccan/"))
 		if (strstarts(lines[i], "ccan/"))
 			str = lines[i];
 			str = lines[i];
@@ -176,15 +191,15 @@ static bool have_dep(char **deps, const char *dep)
 
 
 /* Gets all the dependencies, recursively. */
 /* Gets all the dependencies, recursively. */
 static char **
 static char **
-get_all_deps(const void *ctx, const char *dir,
+get_all_deps(const void *ctx, const char *dir, const char *style,
 	     char *(*get_info)(const void *ctx, const char *dir),
 	     char *(*get_info)(const void *ctx, const char *dir),
-	     char **(*get_one)(const void *, const char *,
+	     char **(*get_one)(const void *, const char *, const char *,
 			       char *(*get_info)(const void *, const char *)))
 			       char *(*get_info)(const void *, const char *)))
 {
 {
 	char **deps;
 	char **deps;
 	unsigned int i;
 	unsigned int i;
 
 
-	deps = get_one(ctx, dir, get_info);
+	deps = get_one(ctx, dir, style, get_info);
 	for (i = 0; i < talloc_array_length(deps)-1; i++) {
 	for (i = 0; i < talloc_array_length(deps)-1; i++) {
 		char **newdeps;
 		char **newdeps;
 		unsigned int j;
 		unsigned int j;
@@ -196,7 +211,7 @@ get_all_deps(const void *ctx, const char *dir,
 		subdir = talloc_asprintf(ctx, "%s/%s",
 		subdir = talloc_asprintf(ctx, "%s/%s",
 					 talloc_dirname(ctx, dir),
 					 talloc_dirname(ctx, dir),
 					 deps[i] + strlen("ccan/"));
 					 deps[i] + strlen("ccan/"));
-		newdeps = get_one(ctx, subdir, get_info);
+		newdeps = get_one(ctx, subdir, "depends", get_info);
 
 
 		/* Should be short, so brute-force out dups. */
 		/* Should be short, so brute-force out dups. */
 		for (j = 0; j < talloc_array_length(newdeps)-1; j++) {
 		for (j = 0; j < talloc_array_length(newdeps)-1; j++) {
@@ -239,7 +254,7 @@ char **get_libs(const void *ctx, const char *dir, bool recurse,
 	len = talloc_array_length(libs);
 	len = talloc_array_length(libs);
 
 
 	if (recurse) {
 	if (recurse) {
-		deps = get_deps(ctx, dir, true, get_info);
+		deps = get_deps(ctx, dir, "depends", true, get_info);
 		for (i = 0; deps[i]; i++) {
 		for (i = 0; deps[i]; i++) {
 			char **newlibs, *subdir;
 			char **newlibs, *subdir;
 			size_t newlen;
 			size_t newlen;
@@ -289,27 +304,28 @@ static char **uniquify_deps(char **deps)
 	return talloc_realloc(NULL, deps, char *, num + 1);
 	return talloc_realloc(NULL, deps, char *, num + 1);
 }
 }
 
 
-char **get_deps(const void *ctx, const char *dir, bool recurse,
+char **get_deps(const void *ctx, const char *dir, const char *style,
+		bool recurse,
 		char *(*get_info)(const void *ctx, const char *dir))
 		char *(*get_info)(const void *ctx, const char *dir))
 {
 {
 	char **ret;
 	char **ret;
 
 
 	if (!recurse) {
 	if (!recurse) {
-		ret = get_one_deps(ctx, dir, get_info);
+		ret = get_one_deps(ctx, dir, style, get_info);
 	} else
 	} else
-		ret = get_all_deps(ctx, dir, get_info, get_one_deps);
+		ret = get_all_deps(ctx, dir, style, get_info, get_one_deps);
 
 
 	return uniquify_deps(ret);
 	return uniquify_deps(ret);
 }
 }
 
 
-char **get_safe_ccan_deps(const void *ctx, const char *dir,
+char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
 			  bool recurse)
 			  bool recurse)
 {
 {
 	char **ret;
 	char **ret;
 	if (!recurse) {
 	if (!recurse) {
-		ret = get_one_safe_deps(ctx, dir, NULL);
+		ret = get_one_safe_deps(ctx, dir, style, NULL);
 	} else {
 	} else {
-		ret = get_all_deps(ctx, dir, NULL, get_one_safe_deps);
+		ret = get_all_deps(ctx, dir, style, NULL, get_one_safe_deps);
 	}
 	}
 	return uniquify_deps(ret);
 	return uniquify_deps(ret);
 }
 }

+ 5 - 2
tools/namespacize.c

@@ -458,7 +458,9 @@ static void adjust_dir(const char *dir)
 
 
 	verbose("Adjusting %s\n", dir);
 	verbose("Adjusting %s\n", dir);
 	verbose_indent();
 	verbose_indent();
-	for (deps = get_deps(parent, dir, false, compile_info); *deps; deps++) {
+	for (deps = get_deps(parent, dir, "depends", false, compile_info);
+	     *deps;
+	     deps++) {
 		char *depdir;
 		char *depdir;
 		struct adjusted *adj = NULL;
 		struct adjusted *adj = NULL;
 		struct replace *repl;
 		struct replace *repl;
@@ -496,7 +498,8 @@ static void adjust_dependents(const char *dir)
 		if (access(info, R_OK) != 0)
 		if (access(info, R_OK) != 0)
 			continue;
 			continue;
 
 
-		for (deps = get_deps(*file, *file, false, compile_info);
+		for (deps = get_deps(*file, *file, "depends", false,
+				     compile_info);
 		     *deps; deps++) {
 		     *deps; deps++) {
 			if (!strstarts(*deps, "ccan/"))
 			if (!strstarts(*deps, "ccan/"))
 				continue;
 				continue;

+ 4 - 2
tools/tools.h

@@ -23,11 +23,13 @@
 char *compile_info(const void *ctx, const char *dir);
 char *compile_info(const void *ctx, const char *dir);
 
 
 /* This actually compiles and runs the info file to get dependencies. */
 /* This actually compiles and runs the info file to get dependencies. */
-char **get_deps(const void *ctx, const char *dir, bool recurse,
+char **get_deps(const void *ctx, const char *dir, const char *style,
+		bool recurse,
 		char *(*get_info)(const void *ctx, const char *dir));
 		char *(*get_info)(const void *ctx, const char *dir));
 
 
 /* This is safer: just looks for ccan/ strings in info */
 /* This is safer: just looks for ccan/ strings in info */
-char **get_safe_ccan_deps(const void *ctx, const char *dir, bool recurse);
+char **get_safe_ccan_deps(const void *ctx, const char *dir, const char *style,
+			  bool recurse);
 
 
 /* This also needs to compile the info file. */
 /* This also needs to compile the info file. */
 char **get_libs(const void *ctx, const char *dir, bool recurse,
 char **get_libs(const void *ctx, const char *dir, bool recurse,