Changeset 957

Show
Ignore:
Timestamp:
03/05/09 01:29:14 (3 years ago)
Author:
andrei
Message:

Changed eval() to cache generated binaries for 24 hours

Files:

Legend:

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

    r956 r957  
    2424 */ 
    2525 
    26 import std.getopt, std.string, std.process, std.stdio, std.contracts, std.file, 
     26import std.date, std.getopt, std.string, std.process, std.stdio, 
     27    std.contracts, std.file, 
    2728    std.algorithm, std.iterator, std.md5, std.path, std.regexp, std.getopt, 
    28     std.c.stdlib, std.date, std.process; 
     29    std.c.stdlib, std.process; 
    2930 
    3031private bool chatty, buildOnly, dryRun, force; 
     
    359360    ubyte digest[16]; 
    360361    context.finish(digest); 
    361     auto progname = std.path.join(tmpDir, 
    362             "rdmd_eval" ~ digestToString(digest) ~ ".d"); 
    363  
    364     std.file.write(progname, todo); 
    365     scope(exit) std.file.remove(progname); 
    366     run("dmd -run " ~ progname); 
     362    auto pathname = std.path.join(tmpDir, ".rdmd"); 
     363    if (!exists(pathname)) mkdirRecurse(pathname); 
     364    auto progname = std.path.join(pathname, 
     365            "eval." ~ digestToString(digest)); 
     366 
     367    if (exists(progname) || 
     368            // Compile it 
     369            (std.file.write(progname~".d", todo), 
     370                    run("dmd " ~ progname ~ ".d -of" ~ progname) == 0)) 
     371    { 
     372        // It's there, just run it 
     373        run(progname); 
     374    } 
     375 
     376    // Clean pathname 
     377    enum lifetimeInHours = 24; 
     378    auto cutoff = getUTCtime - 60 * 60 * lifetimeInHours * TicksPerSecond; 
     379    foreach (DirEntry d; dirEntries(pathname, SpanMode.shallow)) 
     380    { 
     381        if (d.lastWriteTime < cutoff) 
     382        { 
     383            std.file.remove(d.name); 
     384            //break; // only one per call so we don't waste time 
     385        } 
     386    } 
     387     
    367388    return 0; 
    368389}