~mcf/samurai

0727b7c7d08e857a836b8cc7c630fe7a66385c92 — Paolo Bonzini a month ago 58ca03b master
Implement "query" tool

The query tool allows to print the incoming and outgoing edges for
a given node.
2 files changed, 46 insertions(+), 0 deletions(-)

M samu.1
M tool.c
M samu.1 => samu.1 +9 -0
@@ 29,6 29,11 @@
.Nm
.Op Fl C Ar dir
.Op Fl f Ar buildfile
.Fl t Cm query
.Op Ar target...
.Nm
.Op Fl C Ar dir
.Op Fl f Ar buildfile
.Fl t Cm targets
.Op Cm depth Op Ar maxdepth
.Nm


@@ 80,6 85,10 @@ tool is used, a compilation database
is printed instead.
.Pp
If the
.Cm query
tool is used, the inputs and outputs of the targets are printed instead.
.Pp
If the
.Cm targets
tool is used, a list of targets will be displayed, either by rule or by depth.
The first argument determines how the targets will be displayed:

M tool.c => tool.c +37 -0
@@ 298,12 298,49 @@ targets(int argc, char *argv[])
	return 0;
}

static int
query(int argc, char *argv[])
{
	struct node *n;
	struct edge *e;
	char *path;
	int i;
	size_t j, k;

	if (argc == 1) {
		fprintf(stderr, "usage: %s ... -t query target...\n", argv0);
		exit(2);
	}
	for (i = 1; i < argc; ++i) {
		path = argv[i];
		n = nodeget(path, 0);
		if (!n)
			fatal("unknown target '%s'", path);
		printf("%s:\n", argv[i]);
		e = n->gen;
		if (e) {
			printf("  input: %s\n", e->rule->name);
			for (j = 0; j < e->nin; ++j)
				printf("    %s\n", e->in[j]->path->s);
		}
		puts("  outputs:");
		for (j = 0; j < n->nuse; ++j) {
			e = n->use[j];
			for (k = 0; k < e->nout; ++k)
				printf("    %s\n", e->out[k]->path->s);
		}
	}

	return 0;
}

static int list(int argc, char *argv[]);

static const struct tool tools[] = {
	{"clean", "remove build outputs", clean},
	{"compdb", "dump compilation database", compdb},
	{"list", NULL, list},
	{"query", "show incoming/outgoing edges for a path", query},
	{"targets", "list targets", targets},
};