Changeset 393

Show
Ignore:
Timestamp:
02/23/07 19:16:00 (2 years ago)
Author:
Gregor
Message:

rebuild/*: Added support for using response files.

RELEASE: Rebuild 0.12 (try 2)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rebuild/compile.c

    r277 r393  
    1818#include "mars.h" 
    1919#include "module.h" 
     20#include "response.h" 
    2021 
    21 string compileCommand(const string &i
     22string compileCommand(const string &i, string &response, bool &useresponse
    2223{ 
    2324    int varLoc; 
     
    2930        global.errors++; 
    3031        return ""; 
     32    } 
     33     
     34    // check if we need to use a response file 
     35    useresponse = false; 
     36    if (masterConfig["compile"].find("response") != masterConfig["compile"].end()) { 
     37        useresponse = true; 
     38        response = masterConfig["compile"]["response"]; 
    3139    } 
    3240     
     
    4957void runCompile(const std::string &files) 
    5058{ 
    51     string cline = compileCommand(files); 
     59    string response; 
     60    bool useresponse; 
     61    string cline = compileCommand(files, response, useresponse); 
    5262     
    5363    if (global.params.verbose) 
     
    5565     
    5666    // run it 
    57     if (cline == "" || 
    58         system(cline.c_str())) 
     67    int res = 0; 
     68    if (cline == "") { 
     69        res = 1; 
     70    } else { 
     71        if (useresponse) 
     72            res = systemResponse(cline.c_str(), response.c_str(), "rsp"); 
     73        else 
     74            res = system(cline.c_str()); 
     75    } 
     76    if (res) { 
    5977        global.errors++; 
     78    } 
    6079} 
  • trunk/rebuild/compile.h

    r277 r393  
    1212#include <string> 
    1313 
    14 std::string compileCommand(const std::string &i); 
     14std::string compileCommand(const std::string &i, std::string &response, bool &useresponse); 
    1515 
    1616void runCompile(const std::string &files); 
  • trunk/rebuild/config.c

    r332 r393  
    114114     
    115115    // get the compile line 
    116     string cline = compileCommand("rebuild_tmp.d"); 
     116    string response; 
     117    bool useresponse; 
     118    string cline = compileCommand("rebuild_tmp.d", response, useresponse); 
    117119     
    118120    // test it 
  • trunk/rebuild/link.c

    r366 r393  
    4040#include    "mars.h" 
    4141#include    "mem.h" 
     42#include        "response.h" 
    4243#include    "root.h" 
    4344 
     
    5152 */ 
    5253 
    53 string linkCommand(const string &i, const string &o, char post = 0
     54string linkCommand(const string &i, const string &o, string &response, bool &useresponse, char post
    5455{ 
    5556    int varLoc; 
     
    7778    } 
    7879     
     80    // check if we need to use a response file 
     81    useresponse = false; 
     82    if (masterConfig.find(linkset) != masterConfig.end() && 
     83        masterConfig[linkset].find("response") != masterConfig[linkset].end()) { 
     84        useresponse = true; 
     85        response = masterConfig[linkset]["response"]; 
     86    } 
     87     
    7988    // config: compile=[g]dmd -c $i -o $o 
    8089    string cline = masterConfig[linkset]["cmd"]; 
    81  
     90     
    8291    // there are some flags that should be added only on non-darwin 
    8392    if (!findCondition(global.params.versionids, new Identifier("darwin", 0))) { 
     
    123132{ 
    124133    // get the list of input files, as well as the age if they're necessary 
    125     string inp, out; 
     134    string inp, out, response; 
     135    bool useresponse; 
    126136    time_t mtime = 0; 
    127137    struct stat sbuf, osbuf; 
     
    177187        osbuf.st_mtime <= mtime) { 
    178188        string cline = linkCommand( 
    179             inp, out); 
     189            inp, out, response, useresponse, 0); 
    180190         
    181191        if (global.params.verbose) 
     
    183193         
    184194        // run it 
    185         if (cline == "" || 
    186             system(cline.c_str())) { 
     195        int res = 0; 
     196        if (cline == "") { 
     197            res = 1; 
     198        } else { 
     199            if (useresponse) 
     200                res = systemResponse(cline.c_str(), response.c_str(), "rsp"); 
     201            else 
     202                res = system(cline.c_str()); 
     203        } 
     204        if (res) { 
    187205            global.errors++; 
    188206            return -1; 
     
    191209        if (global.params.lib) { 
    192210            // do postlib link 
    193             cline = linkCommand(out, "", 1); 
     211            cline = linkCommand(out, "", response, useresponse, 1); 
    194212            if (global.params.verbose) 
    195213                printf("postlink  %s\n", cline.c_str()); 
    196             if (cline == "" || 
    197                 system(cline.c_str())) { 
     214             
     215            res = 0; 
     216            if (cline == "") { 
     217                res = 1; 
     218            } else { 
     219                if (useresponse) 
     220                    res = systemResponse(cline.c_str(), response.c_str(), "rsp"); 
     221                else 
     222                    res = system(cline.c_str()); 
     223            } 
     224            if (res) { 
    198225                global.errors++; 
    199226                return -1; 
  • trunk/rebuild/rebuild.conf/dmd-win

    r391 r393  
    3030[compile] 
    3131cmd=dmd -c $i 
     32response=@ 
    3233 
    3334flag=$i 
     
    4950safe=yes 
    5051cmd=lib -c -p256 $o $i 
     52response=@ 
    5153 
    5254libdir= 
  • trunk/rebuild/rebuild.conf/dmd-win-tango

    r391 r393  
    3131[compile] 
    3232cmd=dmd -version=Tango -c $i 
     33response=@ 
    3334 
    3435flag=$i 
     
    4142[link] 
    4243cmd=dmd $i -of$o 
     44response=@ 
    4345 
    4446libdir=-L+$i\ 
     
    5052safe=yes 
    5153cmd=lib -c -p256 $o $i 
     54response=@ 
    5255 
    5356libdir= 
  • trunk/rebuild/response.c

    r332 r393  
    8787    *argv = nargv; 
    8888} 
     89 
     90int systemResponse(const char *cmd, const char *rflag, const char *rfile) 
     91{ 
     92    char *newcmd = mem.strdup(cmd); 
     93    int res; 
     94     
     95    // open the output file 
     96    FILE *of = fopen(rfile, "w"); 
     97    if (!of) { 
     98        perror(rfile); 
     99        exit(1); 
     100    } 
     101     
     102    // break up the command 
     103    int i, slen; 
     104    slen = strlen(newcmd); 
     105    char *cur = newcmd; 
     106    for (i = 0; i <= slen; i++) { 
     107        if (newcmd[i] == ' ' || 
     108            newcmd[i] == '\0' || 
     109            newcmd[i] == '\n' || 
     110            newcmd[i] == '\r') { 
     111            newcmd[i] = '\0'; 
     112             
     113            // add the previous one 
     114            if (cur != newcmd && 
     115                *cur != '\0') { 
     116                fprintf(of, "%s\n", cur); 
     117            } 
     118            cur = newcmd + i + 1; 
     119        } 
     120    } 
     121    fclose(of); 
     122     
     123    // form the response file line 
     124    char *newcmdr = (char *) mem.malloc(strlen(newcmd) + strlen(rflag) + strlen(rfile) + 2); 
     125    sprintf(newcmdr, "%s %s%s", newcmd, rflag, rfile); 
     126    res = system(newcmdr); 
     127    remove(rfile); 
     128     
     129    mem.free(newcmdr); 
     130    mem.free(newcmd); 
     131     
     132    return res; 
     133} 
  • trunk/rebuild/response.h

    r332 r393  
    11 
    2 // Component to parse response files 
     2// Component to parse and generate response files 
    33// Copyright (c) 2007  Gregor Richards 
    44// License for redistribution is by either the Artistic License 
     
    1414void parseResponseFile(int *argc, char ***argv, char *rf, int argnum); 
    1515 
     16int systemResponse(const char *cmd, const char *rflag, const char *rfile); 
     17 
    1618#endif