Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python.pkgs.wrapPython: fix makeWrapperArgs #76283

Merged
merged 1 commit into from Dec 27, 2019

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Dec 23, 2019

Motivation for this change

When makeWrapperArgs is a Bash array, we only passed the first item to wrapProgram. We need to use "${makeWrapperArgs[@]}" to extract all the items. But that breaks the common string case so we need to handle that case separately.

Closes: #76158

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

cc @worldofpeace


When `makeWrapperArgs` is a Bash array, we only passed the first
item to `wrapProgram`. We need to use `"${makeWrapperArgs[@]}"`
to extract all the items. But that breaks the common string case so
we need to handle that case separately.
@jtojnar jtojnar requested a review from FRidh as a code owner December 23, 2019 17:06
@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 23, 2019

$ declare -a foo=(bar baz)
$ echo $foo
bar
$ declare -a bar=${foo[@]}
$ echo $bar
bar baz
$ declare -a bar=(${foo[@]})
$ echo $bar
bar
$ declare -a bar=("${foo[@]}")
$ echo $bar
bar
$ declare -a bar='("${foo[@]}")'
$ echo $bar
bar
$ qux='bar baz'
$ declare -a bar='("${qux[@]}")'
$ echo $bar
bar baz
$ declare -a bar='($qux)'
$ echo $bar
bar

@worldofpeace
Copy link
Contributor

worldofpeace commented Dec 24, 2019

@jtojnar I believe this works. But ${gappsWrapperArgs[@]} at preFixup only has GIO_EXTRA_MODULES in it. I believe that's because wrapGAppsHook is only in fixupOutputHooks and we can't control the order? I think, because of how wrapQtAppsHook is, it will work correctly there.

So all the gappsWrapperArgs+= should be in preFixupPhases?

Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

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

This change LGTM, but the larger issues needs a fix in wrapGAppsHook
(and honestly a slight rewrite 😄 )

@worldofpeace worldofpeace merged commit 4a2621d into NixOS:staging Dec 27, 2019
@worldofpeace worldofpeace deleted the python-mwa branch December 27, 2019 00:21
@veprbl
Copy link
Member

veprbl commented Dec 28, 2019

This broke pythonPackages.setuptools:

# nix-build -Q https://github.com/NixOS/nixpkgs/archive/4a2621da53705b602bcdd8460157517f23d14cff.tar.gz -A python3.pkgs.setuptools
these derivations will be built:
  /nix/store/dzl8i9gwvjw91n5wgbvfgyshqf2rq45s-python3.7-setuptools-42.0.2.drv
building '/nix/store/dzl8i9gwvjw91n5wgbvfgyshqf2rq45s-python3.7-setuptools-42.0.2.drv'...
builder for '/nix/store/dzl8i9gwvjw91n5wgbvfgyshqf2rq45s-python3.7-setuptools-42.0.2.drv' failed with exit code 1; last 10 log lines:
  145 wrapProgram /nix/store/xi3kdsxzn7nz6wdhghfzpfl9w90k5mbb-hook/nix-support/setup-hook
  118 wrapPythonProgramsIn /nix/store/b2i442f7v0mr17cz2a0nqywymr9axpxc-hook/nix-support/setup-hook
  4 wrapPythonPrograms /nix/store/b2i442f7v0mr17cz2a0nqywymr9axpxc-hook/nix-support/setup-hook
  81 _callImplicitHook /nix/store/cis5rcj9qvm94wq7ch500jnszshc3wx8-stdenv-linux/setup
  98 _eval /nix/store/cis5rcj9qvm94wq7ch500jnszshc3wx8-stdenv-linux/setup
  41 runHook /nix/store/cis5rcj9qvm94wq7ch500jnszshc3wx8-stdenv-linux/setup
  1189 fixupPhase /nix/store/cis5rcj9qvm94wq7ch500jnszshc3wx8-stdenv-linux/setup
  1299 genericBuild /nix/store/cis5rcj9qvm94wq7ch500jnszshc3wx8-stdenv-linux/setup
  2 main /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh
error: build of '/nix/store/dzl8i9gwvjw91n5wgbvfgyshqf2rq45s-python3.7-setuptools-42.0.2.drv' failed
# nix-build -Q https://github.com/NixOS/nixpkgs/archive/42b5c7e994c827b90e1a5432314e9c7513c99926.tar.gz -A python3.pkgs.setuptools
/nix/store/77qmmhipzpjpz2c6zd927rqqrkyzylmk-python3.7-setuptools-42.0.2

@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 28, 2019

Aargh, turns out there is a difference between

local -a user_args="()"

and

local -a user_args
user_args="()"

@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 28, 2019

set -eux

a() {
    local -a user_args="()"
    declare -p user_args
}

b() {
    local -a user_args
    user_args="()"
    declare -p user_args
}

a
b

I long ran out of expletives for bash:

+ a
+ local -a 'user_args=()'
+ declare -p user_args
declare -a user_args=()
+ b
+ local -a user_args
+ user_args='()'
+ declare -p user_args
declare -a user_args=([0]="()")

@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 28, 2019

Since local is function scoped, we can just do

set -eux

c() {
    if [[ "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then
        local -a user_args=("${makeWrapperArgs[@]}")
    else
        local -a user_args="($makeWrapperArgs)"
    fi

    local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}")

    declare -p wrapProgramArgs
}

makeWrapperArgs=
c
makeWrapperArgs=()
c

set -eux

c() {
    if [[ "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then
        local -a user_args=("${makeWrapperArgs[@]}")
    else
        local -a user_args="($makeWrapperArgs)"
    fi

    local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}")

    declare -p wrapProgramArgs
}

makeWrapperArgs=
c
makeWrapperArgs=()
c

@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 28, 2019

Fixed in a6bb2ed, thanks for letting me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants