From: "Ludovic Courtès" <ludo@gnu.org>
To: Zack Weinberg <zack@owlfolio.org>
Cc: 64359@debbugs.gnu.org
Subject: [bug#64359] [PATCH] [RFC] --search-paths: emit code compatible with set -u
Date: Wed, 11 Oct 2023 19:06:32 +0200 [thread overview]
Message-ID: <87bkd5t7fr.fsf@gnu.org> (raw)
In-Reply-To: <877crlyidb.wl-zack@owlfolio.org> (Zack Weinberg's message of "Thu, 29 Jun 2023 19:10:56 -0400")
Hi Zack,
Zack Weinberg <zack@owlfolio.org> skribis:
> The shell script fragment emitted by the --search-paths option to
> ‘guix shell’, etc., uses this construct to prepend a directory to
> a search-path environment variable:
>
> export VAR="/gnu/store/...${VAR:+:}$VAR"
>
> If this is evaluated by a shell in set -u mode, and VAR was previously
> unset, it will error out:
>
> $ bash -c '
> set -u
> unset PKG_CONFIG_PATH
> export PKG_CONFIG_PATH="/example/lib/pkgconfig${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH"
> echo $PKG_CONFIG_PATH
> '
> bash: line 4: PKG_CONFIG_PATH: unbound variable
>
> This happens in real life, for instance, if direnv[1] is being used in its
> “strict_env” mode[2], which the documentation says will become the default
> in a future release.
>
> This patch makes the code emitted by --search-paths compatible with set -u,
> by changing each use of bare `$VARIABLE` to `${VARIABLE:-}`, e.g.
>
> $ bash -c '
> set -u
> unset PKG_CONFIG_PATH
> export PKG_CONFIG_PATH="/example/lib/pkgconfig${PKG_CONFIG_PATH:+:}${PKG_CONFIG_PATH:-}"
> echo $PKG_CONFIG_PATH'
> /example/lib/pkgconfig
This change makes a lot of sense to me.
[...]
> +++ b/guix/build/utils.scm
> @@ -1384,19 +1384,19 @@ (define (export-variable lst)
> (format #f "export ~a=\"~a\""
> var (string-join rest sep)))
> ((var sep 'prefix rest)
> - (format #f "export ~a=\"~a${~a:+~a}$~a\""
> + (format #f "export ~a=\"~a${~a:+~a}${~a:-}\""
> var (string-join rest sep) var sep var))
This part is a full-rebuild change, so it’d have to wait. However, it’s
within ‘wrap-program’; the script generated by ‘wrap-program’ does *not*
use ‘set -u’, so I think this change is unnecessary. Am I right?
> +++ b/guix/search-paths.scm
> @@ -225,10 +225,10 @@ (define* (environment-variable-definition variable value
> ('exact
> (format #f "export ~a=\"~a\"" variable value))
> ('prefix
> - (format #f "export ~a=\"~a${~a:+~a}$~a\""
> + (format #f "export ~a=\"~a${~a:+~a}${~a:-}\""
> variable value variable separator variable))
> ('suffix
> - (format #f "export ~a=\"$~a${~a:+~a}~a\""
> + (format #f "export ~a=\"${~a:-}${~a:+~a}~a\""
> variable variable variable separator value))))
LGTM.
> --- a/tests/guix-environment.sh
> +++ b/tests/guix-environment.sh
You can remove this change and keep only the ‘tests/guix-shell.sh’ part.
Could you send an updated patch?
Thanks, and apologies for the long delay!
Ludo’.
next prev parent reply other threads:[~2023-10-11 17:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 23:10 [bug#64359] [PATCH] [RFC] --search-paths: emit code compatible with set -u Zack Weinberg
2023-10-11 17:06 ` Ludovic Courtès [this message]
2023-10-11 18:56 ` Zack Weinberg
2023-10-14 17:04 ` Ludovic Courtès
2023-10-18 18:21 ` Zack Weinberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkd5t7fr.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=64359@debbugs.gnu.org \
--cc=zack@owlfolio.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).