We let the get_deps() caller hand us the compiled _info filename, but what
about recursive dependencies? These we re-generate every time.
So fix this: hand a generator callback to get_deps(), expose the one
which simply compiles it, and add a ccanlint one which looks up the
manifest to see if we have one already.
Before:
$ ccanlint -vvvv ccan/failtest | grep -c 'Creating.*_info'
31
After:
$ ccanlint -vvvv ccan/failtest | grep -c 'Creating.*_info'
17
if (compile)
deps = get_deps(talloc_autofree_context(), argv[1],
if (compile)
deps = get_deps(talloc_autofree_context(), argv[1],
+ recurse, compile_info);
else
deps = get_safe_ccan_deps(talloc_autofree_context(),
argv[1], recurse);
else
deps = get_safe_ccan_deps(talloc_autofree_context(),
argv[1], recurse);
/* Get results of a command, returning ctx (and free it). */
void *collect_command(bool *ok, char **output);
/* Get results of a command, returning ctx (and free it). */
void *collect_command(bool *ok, char **output);
+/* Find manifest for this dir and return compiled _info filename. */
+char *get_or_compile_info(const void *ctx, const char *dir);
+
/* Normal tests. */
extern struct ccanlint trailing_whitespace;
/* Normal tests. */
extern struct ccanlint trailing_whitespace;
score->error = talloc_append_string(score->error,
"... more (use -vv to see them all)\n");
}
score->error = talloc_append_string(score->error,
"... more (use -vv to see them all)\n");
}
+
+char *get_or_compile_info(const void *ctx, const char *dir)
+{
+ struct manifest *m = get_manifest(NULL, dir);
+
+ if (!m->info_file->compiled[COMPILE_NORMAL])
+ m->info_file->compiled[COMPILE_NORMAL] = compile_info(m, dir);
+
+ return m->info_file->compiled[COMPILE_NORMAL];
+}
if (safe_mode)
deps = get_safe_ccan_deps(m, m->dir, true);
else
if (safe_mode)
deps = get_safe_ccan_deps(m, m->dir, true);
else
- deps = get_deps(m, m->dir, true,
- &m->info_file->compiled[COMPILE_NORMAL]);
+ deps = get_deps(m, m->dir, true, get_or_compile_info);
for (i = 0; deps[i]; i++) {
if (!strstarts(deps[i], "ccan/"))
for (i = 0; deps[i]; i++) {
if (!strstarts(deps[i], "ccan/"))
if (m->info_file) {
char **infodeps;
if (m->info_file) {
char **infodeps;
- infodeps = get_deps(m, m->dir, false,
- &m->info_file->compiled[COMPILE_NORMAL]);
+ infodeps = get_deps(m, m->dir, false, get_or_compile_info);
for (i = 0; infodeps[i]; i++) {
if (strstarts(infodeps[i], "ccan/"))
for (i = 0; infodeps[i]; i++) {
if (strstarts(infodeps[i], "ccan/"))
/* Be careful about trying to compile over running programs (parallel make).
* temp_file helps here. */
/* Be careful about trying to compile over running programs (parallel make).
* temp_file helps here. */
-static char *compile_info(const void *ctx, const char *dir)
+char *compile_info(const void *ctx, const char *dir)
{
char *info_c_file, *info, *ccandir, *compiled, *output;
size_t len;
{
char *info_c_file, *info, *ccandir, *compiled, *output;
size_t len;
-static char **get_one_deps(const void *ctx, const char *dir, char **infofile)
+static char **get_one_deps(const void *ctx, const char *dir,
+ char *(*get_info)(const void *ctx, const char *dir))
+ char *infofile = get_info(ctx, dir);
- if (!*infofile) {
- *infofile = compile_info(ctx, dir);
- if (!*infofile)
- errx(1, "Could not compile _info for '%s'", dir);
- }
+ if (!infofile)
+ return NULL;
- cmd = talloc_asprintf(ctx, "%s depends", *infofile);
+ cmd = talloc_asprintf(ctx, "%s depends", infofile);
deps = lines_from_cmd(cmd, "%s", cmd);
if (!deps)
err(1, "Could not run '%s'", cmd);
deps = lines_from_cmd(cmd, "%s", cmd);
if (!deps)
err(1, "Could not run '%s'", cmd);
/* This is a terrible hack. We scan for ccan/ strings. */
static char **get_one_safe_deps(const void *ctx,
const char *dir,
/* This is a terrible hack. We scan for ccan/ strings. */
static char **get_one_safe_deps(const void *ctx,
const char *dir,
+ char *(*unused)(const void *, const char *))
{
char **deps, **lines, *raw, *fname;
unsigned int i, n;
{
char **deps, **lines, *raw, *fname;
unsigned int i, n;
/* Gets all the dependencies, recursively. */
static char **
get_all_deps(const void *ctx, const char *dir,
/* Gets all the dependencies, recursively. */
static char **
get_all_deps(const void *ctx, const char *dir,
- char **infofile,
- char **(*get_one)(const void *, const char *, char **))
+ char *(*get_info)(const void *ctx, const char *dir),
+ char **(*get_one)(const void *, const char *,
+ char *(*get_info)(const void *, const char *)))
{
char **deps;
unsigned int i;
{
char **deps;
unsigned int i;
- deps = get_one(ctx, dir, infofile);
+ deps = get_one(ctx, dir, get_info);
for (i = 0; i < talloc_array_length(deps)-1; i++) {
char **newdeps;
unsigned int j;
for (i = 0; i < talloc_array_length(deps)-1; i++) {
char **newdeps;
unsigned int j;
char *subdir;
if (!strstarts(deps[i], "ccan/"))
char *subdir;
if (!strstarts(deps[i], "ccan/"))
subdir = talloc_asprintf(ctx, "%s/%s",
talloc_dirname(ctx, dir),
deps[i] + strlen("ccan/"));
subdir = talloc_asprintf(ctx, "%s/%s",
talloc_dirname(ctx, dir),
deps[i] + strlen("ccan/"));
- newdeps = get_one(ctx, subdir, &subinfo);
+ newdeps = get_one(ctx, subdir, get_info);
/* Should be short, so brute-force out dups. */
for (j = 0; j < talloc_array_length(newdeps)-1; j++) {
/* Should be short, so brute-force out dups. */
for (j = 0; j < talloc_array_length(newdeps)-1; j++) {
{
unsigned int i, j, num;
{
unsigned int i, j, num;
+ if (!deps)
+ return NULL;
+
num = talloc_array_length(deps) - 1;
for (i = 0; i < num; i++) {
for (j = i + 1; j < num; j++) {
num = talloc_array_length(deps) - 1;
for (i = 0; i < num; i++) {
for (j = i + 1; j < num; j++) {
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 **infofile)
+char **get_deps(const void *ctx, const char *dir, bool recurse,
+ char *(*get_info)(const void *ctx, const char *dir))
- char *temp = NULL, **ret;
- if (!infofile)
- infofile = &temp;
- ret = get_one_deps(ctx, dir, infofile);
+ ret = get_one_deps(ctx, dir, get_info);
- ret = get_all_deps(ctx, dir, infofile, get_one_deps);
+ ret = get_all_deps(ctx, dir, get_info, get_one_deps);
- if (infofile == &temp && temp) {
- unlink(temp);
- talloc_free(temp);
- }
return uniquify_deps(ret);
}
return uniquify_deps(ret);
}
verbose("Adjusting %s\n", dir);
verbose_indent();
verbose("Adjusting %s\n", dir);
verbose_indent();
- for (deps = get_deps(parent, dir, false, NULL); *deps; deps++) {
+ for (deps = get_deps(parent, dir, false, compile_info); *deps; deps++) {
char *depdir;
struct adjusted *adj = NULL;
struct replace *repl;
char *depdir;
struct adjusted *adj = NULL;
struct replace *repl;
if (access(info, R_OK) != 0)
continue;
if (access(info, R_OK) != 0)
continue;
- for (deps = get_deps(*file, *file, false, NULL);
+ for (deps = get_deps(*file, *file, false, compile_info);
*deps; deps++) {
if (!strstarts(*deps, "ccan/"))
continue;
*deps; deps++) {
if (!strstarts(*deps, "ccan/"))
continue;
#define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
#define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
+/* This compiles up the _info file into a temporary. */
+char *compile_info(const void *ctx, const char *dir);
+
/* This actually compiles and runs the info file to get dependencies. */
char **get_deps(const void *ctx, const char *dir, bool recurse,
/* This actually compiles and runs the info file to get dependencies. */
char **get_deps(const void *ctx, const char *dir, bool recurse,
+ char *(*get_info)(const void *ctx, const char *dir));
/* This is safer: just looks for ccan/ strings in info */
char **get_safe_ccan_deps(const void *ctx, const char *dir, bool recurse);
/* This is safer: just looks for ccan/ strings in info */
char **get_safe_ccan_deps(const void *ctx, const char *dir, bool recurse);