On Fri, Dec 18, 2015 at 6:23 PM, Ben Boeckel <[email protected]> wrote:
> On Fri, Dec 18, 2015 at 14:49:16 -0800, maK wrote:
> > 1. Get compile command for specific file in project - so I can pass
> this
> > to YCM (as YCM requires compilation flags per file, on demand).
> > 2. Get all compilation commands for whole project - so rtags could
> index
> > all my sources.
>
> It'd be nice if Tup would write something conforming to:
>
> http://clang.llvm.org/docs/JSONCompilationDatabase.html
>
>
Attached is a patch that might provide a good start for this - it uses a
trimmed down version of the 'tup graph' logic. However, it dumps every
command, not just compilation commands. I'm not sure if that would mess up
the compilation database. Also, I'm not sure how to generate the "file"
line - is that required? Maybe it could just pull it out of the command
string.
-Mike
--
--
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
---
You received this message because you are subscribed to the Google Groups
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/tup/tup/main.c b/src/tup/tup/main.c
index 7d66928..c6e699d 100644
--- a/src/tup/tup/main.c
+++ b/src/tup/tup/main.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <ctype.h>
#include <errno.h>
#include "tup/config.h"
#include "tup/lock.h"
@@ -54,6 +55,7 @@
static int graph_cb(void *arg, struct tup_entry *tent);
static int graph(int argc, char **argv);
+static int dump_all(void);
/* Testing commands */
static int mlink(int argc, char **argv);
static int variant(int argc, char **argv);
@@ -198,6 +200,8 @@ int main(int argc, char **argv)
print_tup_entry(stdout, tent);
} else if(strcmp(cmd, "graph") == 0) {
rc = graph(argc, argv);
+ } else if(strcmp(cmd, "dump") == 0) {
+ rc = dump_all();
} else if(strcmp(cmd, "scan") == 0) {
int pid;
if(monitor_get_pid(0, &pid) < 0)
@@ -444,6 +448,72 @@ static int graph(int argc, char **argv)
return 0;
}
+static int dump_all(void)
+{
+ struct tup_entry *tent;
+ struct graph g;
+ struct node *n;
+ tupid_t tupid;
+
+ if(tup_db_begin() < 0)
+ return -1;
+
+ if(create_graph(&g, -1, -1) < 0)
+ return -1;
+
+ if(tup_entry_add(DOT_DT, &tent) < 0)
+ return -1;
+
+ n = create_node(&g, tent);
+ if(!n)
+ return -1;
+ n->expanded = 1;
+ TAILQ_REMOVE(&g.node_list, n, list);
+ TAILQ_INSERT_HEAD(&g.plist, n, list);
+
+ while(!TAILQ_EMPTY(&g.plist)) {
+ g.cur = TAILQ_FIRST(&g.plist);
+ if(tup_db_select_node_by_link(graph_cb, &g, g.cur->tnode.tupid) < 0)
+ return -1;
+ TAILQ_REMOVE(&g.plist, g.cur, list);
+ TAILQ_INSERT_HEAD(&g.node_list, g.cur, list);
+
+ if(strcmp(g.cur->tent->name.s, TUP_CONFIG) != 0) {
+ tupid = g.cur->tnode.tupid;
+ g.cur = NULL;
+ if(tup_db_select_node_dir(graph_cb, &g, tupid) < 0)
+ return -1;
+ }
+ }
+
+ TAILQ_FOREACH(n, &g.node_list, list) {
+ if(n->tent->type == TUP_NODE_CMD) {
+ const char *cmd;
+
+ printf("{\"directory\": \"");
+ print_tup_entry(stdout, n->tent->parent);
+ printf("\",\n");
+
+ cmd = n->tent->name.s;
+ if(cmd[0] == '^') {
+ cmd = strchr(cmd+1, '^');
+ if(!cmd) {
+ fprintf(stderr, "tup error: Missing second '^' in command: %s\n", n->tent->name.s);
+ return -1;
+ }
+ cmd++;
+ while(isspace(*cmd)) cmd++;
+ }
+ printf("\"command\": \"%s\"},\n", cmd);
+ }
+ }
+
+ destroy_graph(&g);
+ if(tup_db_commit() < 0)
+ return -1;
+ return 0;
+}
+
static int mlink(int argc, char **argv)
{
/* This only works for files in the top-level directory. It's only