Changeset 965

Show
Ignore:
Timestamp:
03/08/09 16:32:14 (3 years ago)
Author:
andrei
Message:

Multiple --eval allowed; exe always kept in tmpdir

Files:

Legend:

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

    r964 r965  
    11// Written in the D programming language. 
    2  
    3 /* 
    4  *  Copyright (C) 2008 by Andrei Alexandrescu 
    5  *  Written by Andrei Alexandrescu, www.erdani.org 
    6  *  Based on an idea by Georg Wrede 
    7  * 
    8  *  This software is provided 'as-is', without any express or implied 
    9  *  warranty. In no event will the authors be held liable for any damages 
    10  *  arising from the use of this software. 
    11  * 
    12  *  Permission is granted to anyone to use this software for any purpose, 
    13  *  including commercial applications, and to alter it and redistribute it 
    14  *  freely, subject to the following restrictions: 
    15  * 
    16  *  o  The origin of this software must not be misrepresented; you must not 
    17  *     claim that you wrote the original software. If you use this software 
    18  *     in a product, an acknowledgment in the product documentation would be 
    19  *     appreciated but is not required. 
    20  *  o  Altered source versions must be plainly marked as such, and must not 
    21  *     be misrepresented as being the original software. 
    22  *  o  This notice may not be removed or altered from any source 
    23  *     distribution. 
    24  */ 
    252 
    263import std.date, std.getopt, std.string, std.process, std.stdio, 
     
    318private bool chatty, buildOnly, dryRun, force; 
    329private string exe, compiler = "dmd"; 
    33  
    34 // For --eval 
    35 immutable string importWorld = " 
    36 module temporary; 
    37 import std.stdio, std.algorithm, std.array, std.atomics, std.base64,  
    38     std.bigint, /*std.bind, std.bitarray,*/ std.bitmanip, std.boxer,  
    39     std.compiler, std.complex, std.contracts, std.conv, std.cpuid, std.cstream, 
    40     std.ctype, std.date, std.dateparse, std.demangle, std.encoding, std.file,  
    41     std.format, std.functional, std.getopt, std.intrinsic, std.iterator,  
    42     /*std.loader,*/ std.math, std.md5, std.metastrings, std.mmfile,  
    43     std.numeric, std.openrj, std.outbuffer, std.path, std.perf, std.process,  
    44     std.random, std.range, std.regex, std.regexp, std.signals, std.socket,  
    45     std.socketstream, std.stdint, std.stdio, std.stdiobase, std.stream,  
    46     std.string, std.syserror, std.system, std.traits, std.typecons,  
    47     std.typetuple, std.uni, std.uri, std.utf, std.variant, std.xml, std.zip, 
    48     std.zlib; 
    49 "; 
    5010 
    5111int main(string[] args) 
     
    9757    } 
    9858 
    99     // set by functions called in getopt if program should exit 
    100     bool bailout, loop, addStubMain; 
    101     string eval; 
     59    bool bailout;    // bailout set by functions called in getopt if 
     60                     // program should exit 
     61    bool loop;       // set by --loop 
     62    bool addStubMain;// set by --main 
     63    string[] eval;     // set by --eval 
    10264    getopt(args, 
    10365            std.getopt.config.caseSensitive, 
     
    12385        if (loop) 
    12486        { 
    125             return .eval(importWorld ~ "void main(string[] args) { " 
    126                 ~ "foreach (line; stdin.byLine()) {\n" ~ eval ~ ";\n} }"); 
     87            return .eval(importWorld ~ "void main(char[][] args) { " 
     88                ~ "foreach (line; stdin.byLine()) {\n" ~ join(eval, "\n") 
     89                    ~ ";\n} }"); 
    12790        } 
    12891        else 
    12992        { 
    130             return .eval(importWorld ~ "void main(string[] args) {\n" 
    131                     ~ eval ~ ";\n}"); 
     93            return .eval(importWorld ~ "void main(char[][] args) {\n" 
     94                    ~ join(eval, "\n") ~ ";\n}"); 
    13295        } 
    13396    } 
     
    176139    else 
    177140    { 
    178         exe = exeBasename ~ '.' ~ hash(root, compilerFlags); 
     141        //exe = exeBasename ~ '.' ~ hash(root, compilerFlags); 
     142        version (Posix) 
     143            exe = join(myOwnTmpDir, rel2abs(root)[1 .. $]) 
     144                ~ '.' ~ hash(root, compilerFlags); 
     145        else version (Windows) 
     146            exe = join(myOwnTmpDir, root) 
     147                ~ '.' ~ hash(root, compilerFlags); 
     148        else 
     149            assert(0); 
    179150    } 
    180151 
     
    358329  --dry-run         do not compile, just show what commands would be run 
    359330                      (implies --chatty) 
    360   --eval=code       evaluate code \u00E0 la perl -e 
     331  --eval=code       evaluate code \u00E0 la perl -e (multiple --eval allowed) 
    361332  --force           force a rebuild even if apparently not necessary 
    362333  --help            this message 
     
    367338"; 
    368339} 
     340 
     341// For --eval 
     342immutable string importWorld = " 
     343module temporary; 
     344import std.stdio, std.algorithm, std.array, std.atomics, std.base64,  
     345    std.bigint, /*std.bind, std.bitarray,*/ std.bitmanip, std.boxer,  
     346    std.compiler, std.complex, std.contracts, std.conv, std.cpuid, std.cstream, 
     347    std.ctype, std.date, std.dateparse, std.demangle, std.encoding, std.file,  
     348    std.format, std.functional, std.getopt, std.intrinsic, std.iterator,  
     349    /*std.loader,*/ std.math, std.md5, std.metastrings, std.mmfile,  
     350    std.numeric, std.openrj, std.outbuffer, std.path, std.perf, std.process,  
     351    std.random, std.range, std.regex, std.regexp, std.signals, std.socket,  
     352    std.socketstream, std.stdint, std.stdio, std.stdiobase, std.stream,  
     353    std.string, std.syserror, std.system, std.traits, std.typecons,  
     354    std.typetuple, std.uni, std.uri, std.utf, std.variant, std.xml, std.zip, 
     355    std.zlib; 
     356"; 
    369357 
    370358int eval(string todo) 
     
    426414    return year[0]~year[1 .. $]~monthNum~day; 
    427415} 
     416 
     417/* 
     418 *  Copyright (C) 2008 by Andrei Alexandrescu 
     419 *  Written by Andrei Alexandrescu, www.erdani.org 
     420 *  Based on an idea by Georg Wrede 
     421 *  Featuring improvements suggested by Christopher Wright 
     422 * 
     423 *  This software is provided 'as-is', without any express or implied 
     424 *  warranty. In no event will the authors be held liable for any damages 
     425 *  arising from the use of this software. 
     426 * 
     427 *  Permission is granted to anyone to use this software for any purpose, 
     428 *  including commercial applications, and to alter it and redistribute it 
     429 *  freely, subject to the following restrictions: 
     430 * 
     431 *  o  The origin of this software must not be misrepresented; you must not 
     432 *     claim that you wrote the original software. If you use this software 
     433 *     in a product, an acknowledgment in the product documentation would be 
     434 *     appreciated but is not required. 
     435 *  o  Altered source versions must be plainly marked as such, and must not 
     436 *     be misrepresented as being the original software. 
     437 *  o  This notice may not be removed or altered from any source 
     438 *     distribution. 
     439 */