Changeset 962

Show
Ignore:
Timestamp:
03/06/09 16:01:51 (3 years ago)
Author:
andrei
Message:

Added --main option

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/rdmd.d

    r958 r962  
    9898 
    9999    // set by functions called in getopt if program should exit 
    100     bool bailout, loop
     100    bool bailout, loop, addStubMain
    101101    string eval; 
    102102    getopt(args, 
     
    109109            "force", &force, 
    110110            "help", (string) { writeln(helpString); bailout = true; }, 
     111            "main", &addStubMain, 
    111112            "man", (string) { man; bailout = true; }, 
    112113            "eval", &eval, 
     
    182183            find!((string a) {return isNewer(a, exe);})(myModules.keys).length) 
    183184    { 
    184         invariant result = rebuild(root, exe, objDir, myModules, compilerFlags); 
     185        invariant result = rebuild(root, exe, objDir, myModules, compilerFlags, 
     186                                   addStubMain); 
    185187        if (result) return result; 
    186188    } 
     
    202204} 
    203205 
    204 private string tmpDir() 
     206private string myOwnTmpDir() 
    205207{ 
    206208    version (linux) 
    207209    { 
    208         enum tmpRoot = "/tmp"; 
     210        enum tmpRoot = "/tmp/.rdmd"; 
    209211    } 
    210212    else version (Windows) 
     
    214216        { 
    215217            tmpRoot = std.process.getenv("TMP"); 
    216             if (!tmpRoot) tmpRoot = "."; 
    217         } 
    218     } 
     218        } 
     219        if (!tmpRoot) tmpRoot = "./.rdmd"; 
     220        else tmpRoot ~= "/.rdmd"; 
     221    } 
     222    exists(tmpRoot) && isdir(tmpRoot) || mkdirRecurse(tmpRoot); 
    219223    return tmpRoot; 
    220224} 
     
    239243private string getObjPath(in string root, in string[] compilerFlags) 
    240244{ 
    241     const tmpRoot = tmpDir; 
     245    const tmpRoot = myOwnTmpDir; 
    242246    return std.path.join(tmpRoot, 
    243247            "rdmd-" ~ basename(root) ~ '-' ~ hash(root, compilerFlags)); 
     
    250254private int rebuild(string root, string fullExe, 
    251255        string objDir, in string[string] myModules, 
    252         in string[] compilerFlags
     256        in string[] compilerFlags, bool addStubMain
    253257{ 
    254258    auto todo = compiler~" "~join(compilerFlags, " ") 
     
    259263        todo ~= k ~ " "; 
    260264    } 
     265 
     266    // Need to add the pesky void main(){}? 
     267    if (addStubMain) 
     268    { 
     269        auto stubMain = std.path.join(myOwnTmpDir, "stubmain.d"); 
     270        std.file.write(stubMain, "void main(){}"); 
     271        todo ~= stubMain; 
     272    } 
     273     
    261274    invariant result = run(todo); 
    262275    if (result)  
     
    344357  --dry-run         do not compile, just show what commands would be run 
    345358                      (implies --chatty) 
     359  --eval=code       evaluate code a la perl -e 
    346360  --force           force a rebuild even if apparently not necessary 
    347   --eval=code       evaluate code a la perl -
     361  --help            this messag
    348362  --loop            assume \"foreach (line; stdin.byLine()) { ... }\" for eval 
    349   --help            this message 
     363  --main            add a stub main program to the mix (e.g. for unittesting) 
    350364  --man             open web browser on manual page 
    351365  --shebang         rdmd is in a shebang line (put as first argument) 
     
    360374    ubyte digest[16]; 
    361375    context.finish(digest); 
    362     auto pathname = std.path.join(tmpDir, ".rdmd"); 
    363     if (!exists(pathname)) mkdirRecurse(pathname); 
     376    auto pathname = myOwnTmpDir; 
    364377    auto progname = std.path.join(pathname, 
    365378            "eval." ~ digestToString(digest));