コード例 #1
0
ファイル: pkg.c プロジェクト: bjarneh/organice
static void pkg_make_args(struct pkg * slf, char ** xtra){

    if(slf->c_file){
        // replace .h with .o to create output
        char * tmp  = strdup(slf->c_file);
        size_t len  = strlen(tmp);
        tmp[len-1]  = 'o';
        slf->o_file = tmp;

        struct strvec * v = new_strvec();

        v->add(v, global_get_str("-backend"));
        v->add(v, "-I");
        v->add(v, global_get_str("-src"));
        v->add(v, "-c");
        v->add(v, slf->c_file);
        //TODO extra arguments go here...
        if(xtra){
            int i;
            for(i = 0; xtra[i]; i++){
                v->add(v, "-I");
                v->add(v, xtra[i]);
            }
        }
        v->add(v, "-o");
        v->add(v, slf->o_file);

        slf->args = v->join(v, " ");

        v->free(v);
    }
};
コード例 #2
0
ファイル: print.c プロジェクト: Claruarius/stblinux-2.6.37
void
print_flist(
	flist_t	*flist)
{
	char	**pfx;

	pfx = new_strvec(0);
	print_flist_1(flist, pfx, 0);
	free_strvec(pfx);
}
コード例 #3
0
ファイル: dag.c プロジェクト: bjarneh/organice
static char * dag_add_test(struct dag * slf, char ** xtra){

    int i;
    struct pkg * pk;
    char ** tests;
    char tmpdir[11];
    char * test_regex = NULL;
    struct strvec * hv = new_strvec();
    struct strvec * tv = new_strvec();

    if(slf->sorted){
        
        for(i = 0; slf->sorted[i]; i++){

            pk = slf->sorted[i];

            if(pk->is_test(pk)){
                tests = pk->get_tests(pk);
                if(tests){
                    tv->add_array(tv, tests);
                    hv->add(hv, add_str(pk->name, ".h"));
                    free(tests);
                }
            };
        }       
        
    }else{
        panic("dag_add_test: pkg's not found!", __FILE__, __LINE__);
    }
    
    if(tv->len(tv) > 0){
        
        struct buffer * b  = new_buffer();

        b->add(b, "\n// Auto generated code..\n");
        b->add(b, "// http://oc.googlecode.com for documentation\n");
        b->add(b, "\n// imports\n#include <stdio.h>\n\n");
    
        for(i = 0; i < hv->len(hv); i++){
            b->add(b, "#include \"");
            b->add(b, hv->at(hv, i));
            b->add(b, "\"\n");
        }
        
        b->add(b, "\n\n#define TOTAL_NUM_TESTS ");
        char cbuf[20]; // should be enough space 
        sprintf(cbuf, "%d\n", tv->len(tv));
        b->add(b, cbuf);
        
        b->add(b, "\n\nstruct unit_test{\n");
        b->add(b, "  char * name;\n");
        b->add(b, "  int  (*fn)(int);\n");
        b->add(b, "} tests[TOTAL_NUM_TESTS] = {\n");

        tests = tv->to_array(tv);

        for(i = 0; tests[i]; i++){
            b->add(b, "  {\"");
            b->add(b, tests[i]);
            b->add(b, "\", (int (*)(int))");
            b->add(b, tests[i]);
            b->add(b, "},\n");
        };
            
        free_strings(tests); // tv->to_array creates copies
        
        b->add(b, "};\n\n");

        b->add(b, "int main(int argc, char ** argv){\n\n");
        b->add(b, "  int i, ok, failed = 0;\n");
        b->add(b, "  int verbose = ");
        b->add(b, global_get_bool("-verbose")? "1;" : "0;");
        b->add(b, "\n\n");
        b->add(b, "  for( i = 0; i < TOTAL_NUM_TESTS; i++ ){\n\n");
        b->add(b, "    ok = tests[i].fn(verbose);\n\n");
        b->add(b, "    if(! ok){\n");
        b->add(b, "      fprintf(stderr,\"NO       : %s\\n\", tests[i].name);\n");
        b->add(b, "      failed = 1;\n");
        b->add(b, "    }else{\n");
        b->add(b, "      if(verbose){\n");
        b->add(b, "        printf(\"OK       : %s\\n\", tests[i].name);\n");
        b->add(b, "      }\n");
        b->add(b, "    }\n");
        b->add(b, "  }\n");
        b->add(b, "  return failed;\n");
        b->add(b, "}\n\n");
        
        // create content of package in filetree
        const char * test_path[3];
        sprintf(tmpdir, "%ld", time(NULL));
        test_path[0] = global_get_str("-src");
        test_path[1] = tmpdir;
        test_path[2] = "octestmain";

        // we can use timestamp as regex to match test pkg
        test_regex = strdup(tmpdir);

        char * test_dir = path_join_len(test_path, 2);

        mkdir_or_die(test_dir);

        char * pkg_name         = path_join_len(&test_path[1], 2);
        test_path[2] = "octestmain.c";
        char * test_path_joined = path_join_len(test_path, 3);
        
        // spit content to file
        char * test_content = b->str(b);
        spit_str(test_path_joined, test_content);

        // add newly created package to hash
        pk = new_pkg(pkg_name);
        pk->add_file(pk, test_path_joined);
        pk->make_args(pk, xtra);
        slf->pkgs->put( slf->pkgs, pkg_name, pk);
        // add newly create package to sorted (it's got room for it)
        for( i = 0; slf->sorted[i]; i++){;} // figure out stop
        slf->sorted[i] = pk;
        
        free(test_dir);
        free(test_path_joined);
        free(test_content);
        b->free(b);
    }
    
    tv->free_all(tv);
    hv->free_all(hv);

    return test_regex;
};
コード例 #4
0
ファイル: dag.c プロジェクト: bjarneh/organice
static void 
dag_link(struct dag * slf,char *output, char *match, char ** look, char ** lnk)
{
    
    int i, rv, main_count;
    char * args;
    struct pkg ** pks;
    
    if(slf->sorted){
        
        main_count = num_main_pkgs(slf);

        if( main_count > 1 ){
            pks = filter_relevant_main(slf, match);
        }else{
            pks = slf->sorted;
        }
        
        if( ! global_get_bool("-dryrun") ){
            if( dag_binary_up2date( pks , output ) ){
                if(! global_get_bool("-quiet")){
                    printf("up 2 date: %s\n", output );
                }
                return;
            }
        }

        struct strvec * v = new_strvec();
        
        v->add(v, global_get_str("-backend"));
        v->add(v, "-o");
        v->add(v, output );

        for(i = 0; pks[i]; i++){
            if(pks[i]->o_file){
                v->add(v, pks[i]->o_file);
            }
        }
        
        if(v->len(v) > 3){
            
            if(!global_get_bool("-quiet") && !global_get_bool("-dryrun") ) {
                printf("linking  : %s\n", output );
            }
            
            if( global_get_bool("-static") ){
                v->add(v, "-static");
            }
            
            if(look){
                for(i = 0; look[i]; i++){
                    v->add(v, "-L");
                    v->add(v, look[i]);
                }
            }

            if(lnk){
                for(i = 0; lnk[i]; i++){
                    v->add(v, "-l");
                    v->add(v, lnk[i]);
                }
            }

            args = v->join(v, " ");

            if(global_get_bool("-dryrun")) {
                printf("%s\n", args);
            }else{
                rv = run(args);
                if(rv == -1){ panic("failed to fork()",__FILE__,__LINE__); }
                if(rv){ exit(EXIT_FAILURE); }
            }
            
            free(args);
        }
        v->free(v);

        // we have allocated a new array if we filtered
        if( main_count > 1 ){
            free(pks);
        }
    }
};