Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the behaviour of makeWrapper

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserves wildcards. I amended the makeWrapper tests to cover this but didn't include that change because I wasn't changing makeWrapper; should I?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's already being tested

(mkWrapperBinary { name = "test-prefix-noglob"; args = [ "--prefix" "VAR" ":" "./*" ]; })

Let's do the same reenableGlob thing in here too

local reenableGlob=0
if [[ ! -o noglob ]]; then
reenableGlob=1
fi
set -o noglob

Do you think noglob is only necessary in addFlags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done a meticulous review of that entire file for quote hygiene. --add-flags and --append-flags are the only makeWrapper flags documented to accept multiple arguments in one space-separated string, so I would expect the other handlers to quote their values and not need this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance that there's something relying on the current behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly hope not, especially since makeWrapper doesn't do the same thing. If you want wildcard expansion when either implementation of makeWrapper is called, you can leave the wildcards unquoted/unescaped and bash will expand them first.

Here's the result of a quick ripgrep:

$ rg -e '--a(ppen|d)d-flags.*\*'
pkgs/development/tools/schemacrawler/default.nix
26:      --add-flags "-cp $out/lib/*:$out/config" \

pkgs/development/tools/flyway/default.nix
19:      --add-flags "-classpath '$out/share/flyway/lib/*:$out/share/flyway/drivers/*'" \

pkgs/development/libraries/rabbitmq-java-client/default.nix
23:      --add-flags "-Djava.awt.headless=true -cp $out/share/java/\* com.rabbitmq.examples.PerfTest"

pkgs/tools/security/cryptomator/default.nix
43:      --add-flags "--class-path '$out/share/cryptomator/libs/*'" \

pkgs/applications/networking/instant-messengers/signal-cli/default.nix
23:      --add-flags "-classpath '$out/lib/*:${libmatthew_java}/lib/jni'" \

pkgs/applications/office/jameica/default.nix
64:      --add-flags "-cp $out/share/java/jameica.jar:$out/share/jameica-${version}/* ${

All of these files use makeWrapper or makeShellWrapper, not makeBinaryWrapper.

Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,23 @@ makeCWrapper() {

addFlags() {
local n flag before after var

# Disable file globbing, since bash will otherwise try to find
# filenames matching the the value to be prefixed/suffixed if
# it contains characters considered wildcards, such as `?` and
# `*`. We want the value as is, except we also want to split
# it on on the separator; hence we can't quote it.
local reenableGlob=0
if [[ ! -o noglob ]]; then
reenableGlob=1
fi
set -o noglob
# shellcheck disable=SC2086
before=($1) after=($2)
if (( reenableGlob )); then
set +o noglob
fi

var="argv_tmp"
printf '%s\n' "char **$var = calloc(${#before[@]} + argc + ${#after[@]} + 1, sizeof(*$var));"
printf '%s\n' "assert($var != NULL);"
Expand Down
12 changes: 7 additions & 5 deletions pkgs/test/make-binary-wrapper/add-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
#include <assert.h>

int main(int argc, char **argv) {
char **argv_tmp = calloc(4 + argc + 2 + 1, sizeof(*argv_tmp));
char **argv_tmp = calloc(6 + argc + 2 + 1, sizeof(*argv_tmp));
assert(argv_tmp != NULL);
argv_tmp[0] = argv[0];
argv_tmp[1] = "-x";
argv_tmp[2] = "-y";
argv_tmp[3] = "-z";
argv_tmp[4] = "-abc";
argv_tmp[5] = "-g";
argv_tmp[6] = "*.txt";
for (int i = 1; i < argc; ++i) {
argv_tmp[4 + i] = argv[i];
argv_tmp[6 + i] = argv[i];
}
argv_tmp[4 + argc + 0] = "-foo";
argv_tmp[4 + argc + 1] = "-bar";
argv_tmp[4 + argc + 2] = NULL;
argv_tmp[6 + argc + 0] = "-foo";
argv_tmp[6 + argc + 1] = "-bar";
argv_tmp[6 + argc + 2] = NULL;
argv = argv_tmp;

argv[0] = "/send/me/flags";
Expand Down
3 changes: 2 additions & 1 deletion pkgs/test/make-binary-wrapper/add-flags.cmdline
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--append-flags "-foo -bar" \
--add-flags "-x -y -z" \
--add-flags -abc
--add-flags -abc \
--add-flags "-g *.txt"
2 changes: 2 additions & 0 deletions pkgs/test/make-binary-wrapper/add-flags.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ SUBST_ARGV0
-y
-z
-abc
-g
*.txt
-foo
-bar