Jeff King <p...@peff.net> writes:

> Perhaps instead of just dumping it into a macro, we could actually parse
> it at compile time into C code, and store the result as a header file.
> Then that header file becomes the proper dependency, and this run-time
> error:
>
>> +    while (*pager_env) {
>> +            struct strbuf buf = STRBUF_INIT;
>> +            const char *cp = strchrnul(pager_env, '=');
>> +
>> +            if (!*cp)
>> +                    die("malformed build-time PAGER_ENV");
>
> would become a compile-time error. We could do the same for the shell
> code, too.
>
> I'm thinking something like:

Heh, great minds think alike.  I did start writing a toy-patch with
a new file called "pager-env.h", before discarding it and sending a
simpler alternative which you are responding to.

I do not mind the approach at all; the primary reason I stopped
doing that was because the amount of code to get quotes right turned
out to be sufficiently big to obscure the real point of the "how
about doing it this way" illustration patch.

> diff --git a/Makefile b/Makefile
> index b4af1e2..3a8d15e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2182,6 +2182,16 @@ GIT-LDFLAGS: FORCE
>               echo "$$FLAGS" >GIT-LDFLAGS; \
>              fi
>  
> +GIT-PAGER-ENV:
> +     @PAGER_ENV='$(PAGER_ENV)'; \
> +     if test x"$$PAGER_ENV" != x"`cat GIT-PAGER-ENV 2>/dev/null`"; then \
> +             echo "$$PAGER_ENV" >GIT-PAGER-ENV; \
> +     fi
> +
> +pager-env.h: GIT-PAGER-ENV mkcarray
> +     $(SHELL_PATH) mkcarray pager_env <$< >$@+
> +     mv $@+ $@
> +
>  # We need to apply sq twice, once to protect from the shell
>  # that runs GIT-BUILD-OPTIONS, and then again to protect it
>  # and the first level quoting from the shell that runs "echo".
> diff --git a/mkcarray b/mkcarray
> index e69de29..5962440 100644
> --- a/mkcarray
> +++ b/mkcarray
> @@ -0,0 +1,21 @@
> +name=$1; shift
> +guard=$(echo "$name" | tr a-z A-Z)
> +
> +cat <<-EOF
> +#ifndef ${guard}_H
> +#define ${guard}_H
> +
> +static const char *${name} = {
> +EOF
> +
> +for i in $(cat); do
> +     # XXX c-quote the values?
> +     printf '\t"%s",\n' "$i"
> +done
> +
> +cat <<EOF
> +     NULL
> +};
> +
> +#endif /* ${guard}_H */
> +EOF
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to