Changeset 1219

Show
Ignore:
Timestamp:
07/05/09 10:57:37 (3 years ago)
Author:
andrei
Message:

Adjusted all imports to match the directory of the main program, such that rdmd can compile and run a program from a different path than the current one.

Files:

Legend:

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

    r1126 r1219  
    3434            // add a trailing path separator to clarify it's a dir 
    3535            exe = std.path.join(value[1 .. $], ""); 
    36             assert(std.string.endsWith(exe, std.path.sep)); 
     36            assert(std.algorithm.endsWith(exe, std.path.sep[])); 
    3737        } 
    3838        else if (value[0] == '-') 
     
    9090                    ~ ";\n} }"); 
    9191        } 
    92         else 
    93         { 
    94             return .eval(importWorld ~ "void main(char[][] args) {\n" 
    95                     ~ join(eval, "\n") ~ ";\n}"); 
    96         } 
     92        return .eval(importWorld ~ "void main(char[][] args) {\n" 
     93                ~ join(eval, "\n") ~ ";\n}"); 
    9794    } 
    9895     
     
    111108        root = /*rel2abs*/(chomp(args[programPos], ".d") ~ ".d"), 
    112109        exeBasename = basename(root, ".d"), 
     110        exeDirname = dirname(root), 
    113111        programArgs = args[programPos + 1 .. $]; 
    114112    args = args[0 .. programPos]; 
    115113    const compilerFlags = args[1 .. programPos]; 
     114 
     115    // Change to the main module's directory; all searches will be 
     116    // relative to that directory 
     117    // auto initialDir = getcwd; 
     118    // chdir(exeDirname); 
     119    // scope(exit) chdir(initialDir); 
    116120 
    117121    // Compute the object directory and ensure it exists 
     
    132136    { 
    133137        // user-specified exe name 
    134         if (std.string.endsWith(exe, std.path.sep)) 
     138        if (std.algorithm.endsWith(exe, std.path.sep[])) 
    135139        { 
    136140            // user specified a directory, complete it to a file 
     
    277281        return std.path.join(objDir, chomp(basename(dfile), ".d")~".o"); 
    278282    } 
     283 
     284    immutable depsFilename = rootModule~".deps"; 
     285    immutable rootDir = dirname(rootModule); 
    279286     
    280287    // myModules maps module source paths to corresponding .o names 
    281288    string[string] myModules;// = [ rootModule : d2obj(rootModule) ]; 
    282289    // Must collect dependencies 
    283     invariant depsGetter = compiler~" "~join(compilerFlags, " ") 
    284         ~" -v -o- "~shellQuote(rootModule); 
     290    invariant depsGetter = "chdir "~shellQuote(rootDir)~" && " 
     291        ~compiler~" "~join(compilerFlags, " ") 
     292        ~" -v -o- "~shellQuote(rootModule) 
     293        ~" >"~depsFilename; 
    285294    if (chatty) writeln(depsGetter); 
    286     File depsReader; 
    287     depsReader.popen(depsGetter); 
     295    immutable depsExitCode = system(depsGetter); 
     296    if (depsExitCode) exit(depsExitCode); 
     297    auto depsReader = File(depsFilename); 
    288298    scope(exit) collectException(depsReader.close); // we don't care for errors 
    289299 
     
    296306        if (inALibrary(moduleName, moduleSrc)) continue; 
    297307        invariant moduleObj = d2obj(moduleSrc); 
    298         myModules[/*rel2abs*/(moduleSrc)] = moduleObj; 
     308        myModules[/*rel2abs*/join(rootDir, moduleSrc)] = moduleObj; 
    299309    } 
    300310