shebang launcher for D programs
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Sat Mar 24 09:02:25 PDT 2007
Anders F Björklund wrote:
> 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.
This won't work if your script includes one of your own modules.
Andrei
More information about the Digitalmars-d
mailing list