shebang launcher for D programs

Anders F Björklund afb at algonet.se
Sat Mar 24 02:02:04 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:

>> The #! thing would be cool, but since I run Windows, I don't tend to use
>> it.  That, and the fact that I tend to use lots of switches :3
> 
> Do your switches vary from one build to the next, or only from one file 
> to the next? If the latter, you could use:
> 
> #!/path/to/rundmd -clean -debug -etc
> 
> as the first line of the program containing main(), and that works under 
> cygwin. You don't have to build your program - ever. It builds itself 
> when necessary.

When doing more complex such "scripts", this seems to work OK:

#!/usr/bin/env rdmd --compiler=rebuild

i.e. just using rebuild as a drop-in replacement for gdmd/dmd


This caches the resulting program in /tmp (or $TEMP on Windows)
and passes any additional arguments over to the compiled program:

$ more run.d
#!/usr/bin/env rdmd --compiler=rebuild

import std.stdio;

void main(char[][] args)
{
   foreach (char[] arg; args)
     writefln("%s", arg);
}

$ ./run.d foo bar
/tmp/run-501-234881028-13386453-4D8B5B0DF758A62AAB383FC432A9EED4
foo
bar

The program name is a little "interesting", but otherwise it's good.
(for shell scripts or perl programs, then $0 would be the script...)

Tested briefly under Mac OS X and Linux, without larger incidents ?
(rdmd --force would rebuild the program if external things changed)


Should also work OK with Tango.
--anders


PS.
http://www.algonet.se/~afb/d/rdmd.d (GDC version of DMD bin)
http://svn.dsource.org/projects/dsss/downloads/rebuild/0.14/



More information about the Digitalmars-d mailing list