Commit e2a53df3 authored by Rusty Russell's avatar Rusty Russell

tools: more intelligent caching for compile _info.

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
parent 4c5f970e
...@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) ...@@ -38,7 +38,7 @@ 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, NULL); 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], recurse);
......
...@@ -164,6 +164,9 @@ void compile_and_link_async(const void *ctx, unsigned int time_ms, ...@@ -164,6 +164,9 @@ void compile_and_link_async(const void *ctx, unsigned int time_ms,
/* Get results of a command, returning ctx (and free it). */ /* Get results of a command, returning ctx (and free it). */
void *collect_command(bool *ok, char **output); 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. */ /* Normal tests. */
extern struct ccanlint trailing_whitespace; extern struct ccanlint trailing_whitespace;
......
...@@ -394,3 +394,13 @@ void score_file_error(struct score *score, struct ccan_file *f, unsigned line, ...@@ -394,3 +394,13 @@ void score_file_error(struct score *score, struct ccan_file *f, unsigned line,
score->error = talloc_append_string(score->error, score->error = talloc_append_string(score->error,
"... more (use -vv to see them all)\n"); "... 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];
}
...@@ -57,8 +57,7 @@ static void check_depends_exist(struct manifest *m, ...@@ -57,8 +57,7 @@ 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, true);
else else
deps = get_deps(m, m->dir, true, deps = get_deps(m, m->dir, true, get_or_compile_info);
&m->info_file->compiled[COMPILE_NORMAL]);
for (i = 0; deps[i]; i++) { for (i = 0; deps[i]; i++) {
if (!strstarts(deps[i], "ccan/")) if (!strstarts(deps[i], "ccan/"))
......
...@@ -62,8 +62,7 @@ static void add_dep(struct manifest ***deps, const char *basename) ...@@ -62,8 +62,7 @@ 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, infodeps = get_deps(m, m->dir, false, get_or_compile_info);
&m->info_file->compiled[COMPILE_NORMAL]);
for (i = 0; infodeps[i]; i++) { for (i = 0; infodeps[i]; i++) {
if (strstarts(infodeps[i], "ccan/")) if (strstarts(infodeps[i], "ccan/"))
......
...@@ -38,7 +38,7 @@ lines_from_cmd(const void *ctx, const char *format, ...) ...@@ -38,7 +38,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
/* Be careful about trying to compile over running programs (parallel make). /* Be careful about trying to compile over running programs (parallel make).
* temp_file helps here. */ * 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; char *info_c_file, *info, *ccandir, *compiled, *output;
size_t len; size_t len;
...@@ -71,17 +71,16 @@ static char *compile_info(const void *ctx, const char *dir) ...@@ -71,17 +71,16 @@ static char *compile_info(const void *ctx, const char *dir)
return NULL; return NULL;
} }
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 **deps, *cmd; char **deps, *cmd;
char *infofile = get_info(ctx, dir);
if (!*infofile) { if (!infofile)
*infofile = compile_info(ctx, dir); return NULL;
if (!*infofile)
errx(1, "Could not compile _info for '%s'", dir);
}
cmd = talloc_asprintf(ctx, "%s depends", *infofile); cmd = talloc_asprintf(ctx, "%s depends", infofile);
deps = lines_from_cmd(cmd, "%s", cmd); deps = lines_from_cmd(cmd, "%s", cmd);
if (!deps) if (!deps)
err(1, "Could not run '%s'", cmd); err(1, "Could not run '%s'", cmd);
...@@ -118,7 +117,7 @@ static char *replace(const void *ctx, const char *src, ...@@ -118,7 +117,7 @@ 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,
char **infofile) char *(*unused)(const void *, const char *))
{ {
char **deps, **lines, *raw, *fname; char **deps, **lines, *raw, *fname;
unsigned int i, n; unsigned int i, n;
...@@ -178,17 +177,17 @@ static bool have_dep(char **deps, const char *dep) ...@@ -178,17 +177,17 @@ 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,
char **infofile, char *(*get_info)(const void *ctx, const char *dir),
char **(*get_one)(const void *, const char *, char **)) char **(*get_one)(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, infofile); deps = get_one(ctx, dir, 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;
char *subinfo = NULL;
char *subdir; char *subdir;
if (!strstarts(deps[i], "ccan/")) if (!strstarts(deps[i], "ccan/"))
...@@ -197,7 +196,7 @@ get_all_deps(const void *ctx, const char *dir, ...@@ -197,7 +196,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, &subinfo); newdeps = get_one(ctx, subdir, 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++) {
...@@ -240,6 +239,9 @@ static char **uniquify_deps(char **deps) ...@@ -240,6 +239,9 @@ static char **uniquify_deps(char **deps)
{ {
unsigned int i, j, num; unsigned int i, j, num;
if (!deps)
return NULL;
num = talloc_array_length(deps) - 1; num = talloc_array_length(deps) - 1;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
for (j = i + 1; j < num; j++) { for (j = i + 1; j < num; j++) {
...@@ -255,22 +257,16 @@ static char **uniquify_deps(char **deps) ...@@ -255,22 +257,16 @@ 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, char **get_deps(const void *ctx, const char *dir, bool recurse,
bool recurse, char **infofile) char *(*get_info)(const void *ctx, const char *dir))
{ {
char *temp = NULL, **ret; char **ret;
if (!infofile)
infofile = &temp;
if (!recurse) { if (!recurse) {
ret = get_one_deps(ctx, dir, infofile); ret = get_one_deps(ctx, dir, get_info);
} else } else
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);
} }
......
...@@ -458,7 +458,7 @@ static void adjust_dir(const char *dir) ...@@ -458,7 +458,7 @@ 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, NULL); *deps; deps++) { for (deps = get_deps(parent, dir, 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 +496,7 @@ static void adjust_dependents(const char *dir) ...@@ -496,7 +496,7 @@ 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, NULL); for (deps = get_deps(*file, *file, false, compile_info);
*deps; deps++) { *deps; deps++) {
if (!strstarts(*deps, "ccan/")) if (!strstarts(*deps, "ccan/"))
continue; continue;
......
...@@ -19,9 +19,12 @@ ...@@ -19,9 +19,12 @@
#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. */ /* 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, bool recurse,
char **infofile); 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, bool recurse);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment