]> git.ozlabs.org Git - ccan/commitdiff
Committing create_dep_tar after changing for dependents handlings
authordinesh <dinesh@dinesh-laptop>
Wed, 13 Aug 2008 09:39:58 +0000 (15:09 +0530)
committerdinesh <dinesh@dinesh-laptop>
Wed, 13 Aug 2008 09:39:58 +0000 (15:09 +0530)
tools/Makefile
tools/create_dep_tar
tools/create_dep_tar.c

index 141eb3267b2772dd98444804dedd387fb9fb8ff4..a03cc9a4c113e9abaaa40e72c3f96998e877ab01 100644 (file)
@@ -6,7 +6,8 @@ tools/doc_extract: tools/doc_extract.o ccan/string/string.o ccan/noerr/noerr.o c
 
 tools/namespacize: tools/namespacize.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o
 
-tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o
+tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o tools/_infotojson/sqlite3_database.o tools/_infotojson/utils.o
+       $(CC) $(LDFLAGS) -o $@ $^ -lsqlite3
 
 tools/run_tests.o tools/namespacize.o tools/depends.o: tools/tools.h
 
index d34281290cdc57dfc7a9b1ef3177e6f55012d27c..7920b0b094cb1221023859ec5438b01ecb7473d7 100755 (executable)
Binary files a/tools/create_dep_tar and b/tools/create_dep_tar differ
index 8247e57ef11d8642706985b7582344a9dd694998..09c331c6f7a09be8f3100bb9a177eb1aec5d3035 100644 (file)
@@ -3,23 +3,60 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sqlite3.h>
 #include "ccan/string/string.h"
 #include "ccan/talloc/talloc.h"
+#include "tools/_infotojson/database.h"
 
 #define TAR_CMD "tar cvvf "
 
-static void create_tar(char **deps, const char *dir)
+/* get dependents of the module from db */
+static char**
+get_dependents(const char *dir, const char *db)
 {
-       FILE *p;
-       char *cmd_args, *cmd, *module, *buffer;
+       char            *query, *module, **dependents;
+       sqlite3         *handle;
+       int             i;
+       struct db_query *q;
+
+       module = strrchr(dir, '/');
+       module++;
+
+       /* getting dependents from db */
+       handle = db_open(db);
+       query = talloc_asprintf(NULL, "select module from search where depends LIKE \"%%%s%%\";", module);
+       q = db_query(handle, query);
+       db_close(handle);
+
+       if (q->num_rows == 0)
+               return 0;
+       else {  
+               /* getting query results and returning */
+               dependents = talloc_array(NULL, char *, q->num_rows + 1);
+               for (i = 0; i < q->num_rows; i++)
+                       dependents[i] = talloc_asprintf(dependents, "ccan/%s", q->rows[i][0]);
+               dependents[q->num_rows] = NULL;
+               return dependents;
+       }
+}
+
+/* create tar ball of dependencies */
+static void
+create_tar(char **deps, const char *dir, const char *targetdir)
+{
+       FILE    *p;
+       char    *cmd_args, *cmd, *module, *buffer;
 
        /* getting module name*/
        module = strrchr(dir, '/');
        module++;
        
-       cmd_args = strjoin(NULL, deps, " ");    
-       cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dep.tar %s", dir, module, cmd_args);
-               
+       if (deps != NULL) {
+               cmd_args = strjoin(NULL, deps, " ");    
+               cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dependencies.tar %s %s", targetdir, module, cmd_args, dir);
+       } else 
+               cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s.tar %s", targetdir, module, dir);
+                       
        p = popen(cmd, "r");
        if (!p)
                err(1, "Executing '%s'", cmd);
@@ -32,14 +69,34 @@ static void create_tar(char **deps, const char *dir)
 
 int main(int argc, char *argv[])
 {
-       char **deps;
+       char    **deps, **dependents;
+       int     i;
 
-       if (argc != 2)
-               errx(1, "Usage: create_dep_tar <dir>\n"
+       if (argc != 4)
+               errx(1, "Usage: create_dep_tar <dir> <targetdir> <db>\n"
                        "Create tar of all the ccan dependencies");
 
+       /* creating tar of the module */
+       create_tar(NULL, argv[1], argv[2]);
+       printf("creating tar ball of \"%s\"\n", argv[1]);       
+
+       /* creating tar of the module dependencies */
        deps = get_deps(NULL, argv[1]);
-       if(deps != NULL)
-               create_tar(deps, argv[1]);
+       if (deps != NULL)
+               create_tar(deps, argv[1], argv[2]);
+       talloc_free(deps);
+
+       /* creating/updating tar of the module dependents */
+       dependents = get_dependents(argv[1], argv[3]);
+       if (dependents != NULL)
+               for (i = 0; dependents[i]; i++) {       
+                       printf("creating tar ball of \"%s\"\n", dependents[i]); 
+                       deps = get_deps(NULL, dependents[i]);
+                       if (deps != NULL)
+                               create_tar(deps, dependents[i], argv[2]);                       
+                       talloc_free(deps);
+               }
+
+       talloc_free(dependents);
        return 0;
 }