tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: handle #! /usr/bin/env
On Mon, Mar 4, 2013 at 12:50 PM, Alan Barrett <apb%cequrux.com@localhost> wrote:
> On Sun, 03 Mar 2013, matthew sporleder wrote:
>>
>> Okay, sorry to develop this on the mailing list but I got a new update.
>> I'm mainly interested in comments about the idea. I think it saves a
>> lot of hassle.
>>
>> 1{ /env -i/!s|^#![[:space:]]*/usr/bin/env|#!|;}
>
>
> You could do it all in a single command. The idea is:
>
> If this is line 1:
> If line has "#!", optional space, optional {"/use/bin/env"
> followed by one or more spaces}, and finally the
> interpreter you were looking for, then replace it all
> with "#!" followed by the new interpreter.
>
> I don't see the need for a special case for "/usr/bin/env -i". Firstly, many
> systems (including NetBSD) prohibit multiple arguments on the "#!" line, so
> stuff like "#!/usr/bin/env -i foo" will fail often enough that people learn
> not to write such code. Secondly, scripts in which you don't want the
> substitution to occur should not be passed to the REPLACE infrastructure.
> If, despite this, you want to avoid accidentally matching "/usr/bin/env -i
> foo", then you can change the REPLACE.sys-foo.old regexps to use
> "[^[:space:]]*" instead of ".*".
>
> Here's patch (untested).
>
> --apb (Alan Barrett)
>
> Index: mk/configure/replace-interpreter.mk
> ===================================================================
> --- mk/configure/replace-interpreter.mk 6 Feb 2012 06:18:36 -0000 1.11
> +++ mk/configure/replace-interpreter.mk 4 Mar 2013 16:19:09 -0000
> @@ -90,6 +90,9 @@ REPLACE.sys-sh.new= ${SH}
> REPLACE_FILES.sys-sh= ${REPLACE_SH}
> .endif
> +# sed regexp to match optional "/usr/bin/env" followed by one or more
> spaces
> +REPLACE.optional-env-space= (/usr/bin/env[[:space:]][[:space:]]*)?
> +
> .PHONY: replace-interpreter
> replace-interpreter:
> .for _lang_ in ${REPLACE_INTERPRETER}
> @@ -99,7 +102,7 @@ replace-interpreter:
>
> cd ${WRKSRC}; \
> for f in ${REPLACE_FILES.${_lang_}}; do \
> if [ -f "$${f}" ]; then \
> - ${SED} -e
> '1s|^#![[:space:]]*${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \
> + ${SED} -e
> '1s|^#![[:space:]]*${REPLACE.optional-env-space}${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|'
> \
>
> < "$${f}" > "$${f}.new"; \
> if [ -x "$${f}" ]; then \
> ${CHMOD} a+x "$${f}.new"; \
Looks good to me. Who can give a final vote on if this is a good idea or not?
Home |
Main Index |
Thread Index |
Old Index