Changeset 962
- Timestamp:
- 03/06/09 16:01:51 (3 years ago)
- Files:
-
- trunk/tools/rdmd.d (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tools/rdmd.d
r958 r962 98 98 99 99 // set by functions called in getopt if program should exit 100 bool bailout, loop ;100 bool bailout, loop, addStubMain; 101 101 string eval; 102 102 getopt(args, … … 109 109 "force", &force, 110 110 "help", (string) { writeln(helpString); bailout = true; }, 111 "main", &addStubMain, 111 112 "man", (string) { man; bailout = true; }, 112 113 "eval", &eval, … … 182 183 find!((string a) {return isNewer(a, exe);})(myModules.keys).length) 183 184 { 184 invariant result = rebuild(root, exe, objDir, myModules, compilerFlags); 185 invariant result = rebuild(root, exe, objDir, myModules, compilerFlags, 186 addStubMain); 185 187 if (result) return result; 186 188 } … … 202 204 } 203 205 204 private string tmpDir()206 private string myOwnTmpDir() 205 207 { 206 208 version (linux) 207 209 { 208 enum tmpRoot = "/tmp ";210 enum tmpRoot = "/tmp/.rdmd"; 209 211 } 210 212 else version (Windows) … … 214 216 { 215 217 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); 219 223 return tmpRoot; 220 224 } … … 239 243 private string getObjPath(in string root, in string[] compilerFlags) 240 244 { 241 const tmpRoot = tmpDir;245 const tmpRoot = myOwnTmpDir; 242 246 return std.path.join(tmpRoot, 243 247 "rdmd-" ~ basename(root) ~ '-' ~ hash(root, compilerFlags)); … … 250 254 private int rebuild(string root, string fullExe, 251 255 string objDir, in string[string] myModules, 252 in string[] compilerFlags )256 in string[] compilerFlags, bool addStubMain) 253 257 { 254 258 auto todo = compiler~" "~join(compilerFlags, " ") … … 259 263 todo ~= k ~ " "; 260 264 } 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 261 274 invariant result = run(todo); 262 275 if (result) … … 344 357 --dry-run do not compile, just show what commands would be run 345 358 (implies --chatty) 359 --eval=code evaluate code a la perl -e 346 360 --force force a rebuild even if apparently not necessary 347 -- eval=code evaluate code a la perl -e361 --help this message 348 362 --loop assume \"foreach (line; stdin.byLine()) { ... }\" for eval 349 -- help this message363 --main add a stub main program to the mix (e.g. for unittesting) 350 364 --man open web browser on manual page 351 365 --shebang rdmd is in a shebang line (put as first argument) … … 360 374 ubyte digest[16]; 361 375 context.finish(digest); 362 auto pathname = std.path.join(tmpDir, ".rdmd"); 363 if (!exists(pathname)) mkdirRecurse(pathname); 376 auto pathname = myOwnTmpDir; 364 377 auto progname = std.path.join(pathname, 365 378 "eval." ~ digestToString(digest));
