Handle .do files that start with "#!/" to specify an explicit interpreter.

Now you can have your .do files interpreted by whatever interpreter you
want.
This commit is contained in:
Avery Pennarun 2011-01-01 22:00:14 -08:00
commit f641e52e3b
7 changed files with 38 additions and 11 deletions

View file

@ -437,15 +437,28 @@ changed, you can run `redo-ifchange target` instead.
# Can my .do files be written in a language other than sh?
FIXME: Not presently. In theory, we could support starting your .do files
with the magic "#!/" sequence (eg. #!/usr/bin/python) and then using that
shell to run your .do script. But that opens new problems, like figuring
out what is the equivalent of the `redo-ifchange` command in python. Do you
just run it in a subprocess? That might be unnecessarily slow. And so on.
Yes. If the first line of your .do file starts with the
magic "#!/" sequence (eg. `#!/usr/bin/python`), then redo
will execute your script using that particular interpreter.
Right now, `redo` explicitly runs `sh filename.do`. The main reasons for
this are to make the #!/ line optional, and so you don't have to remember to
`chmod +x` your .do files.
Note that this is slightly different from normal Unix
execution semantics: redo never execs your script directly;
it only looks for the "#!/" line. The main reason for this
is so that your .do scripts don't have to be marked
executable (chmod +x). Executable .do scripts would
suggest to users that they should run them directly, and
they shouldn't; .do scripts should always be executed
inside an instance of redo, so that dependencies can be
tracked correctly.
WARNING: If your .do script *is* written in Unix sh, we
recommend *not* including the `#!/bin/sh` line. That's
because there are many variations of /bin/sh, and not all
of them are POSIX compliant. redo tries pretty hard to
find a good default shell that will be "as POSIXy as
possible," and if you override it using #!/bin/sh, you lose
this benefit and you'll have to worry more about
portability.
# Can a single .do script generate multiple outputs?