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

Fix makewrapper unsupported args #25185

Merged
merged 2 commits into from Aug 8, 2017

Conversation

ahmedtd
Copy link
Contributor

@ahmedtd ahmedtd commented Apr 24, 2017

Motivation for this change

Previously, makeWrapper would accept arguments it didn't recognize,
potentially allowing argument misspellings or broken callers.

Now, makeWrapper dies with a backtrace if it is called incorrectly.

Also changes wrapProgram so that it doesn't pass through the first
argument twice --- this was tripping up the argument checking.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@ahmedtd, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @abbradar and @zimbatm to be potential reviewers.

@ahmedtd ahmedtd force-pushed the fix-makewrapper-unsupported-args branch 2 times, most recently from b867050 to a6f0fc8 Compare April 24, 2017 16:44
@ahmedtd
Copy link
Contributor Author

ahmedtd commented Apr 24, 2017

#24944 depends on this, for the die utility function

@Ericson2314
Copy link
Member

Is this a mass rebuild? I'd think so.

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Apr 24, 2017

Yes. This PR was split from https://github.com/NixOS/nixpkgs/pull/24944, which might provide more context.

Currently, nox-review wip --against master chokes on it, since nixpkgs includes some problematic attribute names, which this change pulls in. See #25074 and NixOS/nix#1342 for the discussions.

I'm not sure how that will end up.

@Ericson2314
Copy link
Member

Ericson2314 commented Apr 24, 2017

@ahmedtd Ok that's cool. I guess I don't know whether the policy is to submit known mass-rebuilds to staging or master. I'd guess staging, as that is where they'd go eventually, but I'm not sure.

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Apr 24, 2017 via email

@Ericson2314
Copy link
Member

I'm not sure, but the point of staging is to queue up mass rebuilds so they cancel out a bit for master. There is something about not just merging any old untested thing to staging, but I think that means test locally. This stuff indeed ought to be documented better :).

@joachifm
Copy link
Contributor

joachifm commented Apr 24, 2017

Regarding commit policy, see https://nixos.org/nixpkgs/manual/#idm140737318460880

@FRidh FRidh changed the base branch from master to staging April 25, 2017 06:52
@FRidh
Copy link
Member

FRidh commented Apr 25, 2017

I've changed the target branch to staging.

@@ -32,26 +32,20 @@ makeWrapper() {
for ((n = 2; n < ${#params[*]}; n += 1)); do
p="${params[$n]}"

if test "$p" = "--set"; then
if [[ "$p" == "--set" ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it make sense to use a switch case here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A previous PR that did something similar (#19061) ran up against the OSX system version of bash being too old to support the case statement.

Copy link
Member

Choose a reason for hiding this comment

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

fair, the fallthrough is only useful for a single pair of arguments which could be worked around: #19061 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Ok Bash 3.2 is not that bad. Or-patterns can be used instead of fall-through (and in fact are a better solution).

# Works in bash 3.2
case n in
    p|n) echo yup;;
esac

printf "\n"

exit 1
}
Copy link
Member

Choose a reason for hiding this comment

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

How does it look like in practice when that happens? Nix's bash is quite convoluted and might have some weird stack trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It varies in usefulness, depending on how makeWrapper is being called. Sometimes there's enough information to be helpful, but often the stack trace stops at the point where stdenv/setup.sh evaluates the current phase hook.

@peti
Copy link
Member

peti commented Jul 26, 2017

@ahmedtd, this PR has mere conflicts. Would you mind force-pushing an update that is re-based relative to current versions of staging?

Calling `die "Error message"` causes the current script to exit with
an error, printing a backtrace
Previously, makeWrapper would accept arguments it didn't recognize,
potentially allowing argument misspellings or broken callers.

Now, makeWrapper dies with a backtrace if it is called incorrectly.

Also changes `wrapProgram` so that it doesn't pass through the first
argument twice --- this was tripping up the argument checking.
@ahmedtd ahmedtd force-pushed the fix-makewrapper-unsupported-args branch from a6f0fc8 to ece5387 Compare August 8, 2017 05:18
@ahmedtd
Copy link
Contributor Author

ahmedtd commented Aug 8, 2017

Rebased onto current staging.

@peti peti merged commit b196230 into NixOS:staging Aug 8, 2017
@FRidh
Copy link
Member

FRidh commented Aug 8, 2017

This breaks several packages:

installing

Builder called die: makeWrapper doesn't understand the arg /homeless-shelter
Backtrace:
88 makeWrapper /nix/store/ixm1iljz3bgl04z4c2k2nvmq9wian9qh-hook/nix-support/setup-hook
129 wrapProgram /nix/store/ixm1iljz3bgl04z4c2k2nvmq9wian9qh-hook/nix-support/setup-hook
987 genericBuild /nix/store/0ifjmsk5s6nqxz5wlkb2c78xf1213dkc-stdenv/setup
2 main /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh

builder for ‘/nix/store/67l8nyc4b7rbyld7clby9lkibraphn9q-nix-prefetch-git.drv’ failed with exit code 1

https://hydra.nixos.org/build/58313566#tabs-summary

@Ericson2314
Copy link
Member

While we're at it, if someone could use use case with --suffix-contents | --prefix-contents) alternatives, per https://github.com/NixOS/nixpkgs/pull/25185/files#r129576600?

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Aug 8, 2017 via email

@globin
Copy link
Member

globin commented Aug 8, 2017

@ahmedtd fixed already in c00a95b

@Ericson2314
Copy link
Member

staging...obsidiansystems:make-wrapper-clean Here is a draft of that cleanup, if anyone wants to finish it.

@FRidh
Copy link
Member

FRidh commented Aug 9, 2017

Just a note for a future improvement or someone else that encounters this.

The command die() is not accessible when using buildEnv. Therefore, when you wrap things from buildEnv you may get nix-support/setup-hook: line 7: die: command not found.

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Aug 9, 2017

@FRidh That will be a really frustrating experience to debug --- I will send a PR to replace die with its contents in make-wrapper.sh

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Aug 9, 2017

@FRidh Would you mind telling me in which file you observed this problem? Both die.sh and make-wrapper.sh are setup hooks, so I don't understand how one could be accessible but not the other.

@globin
Copy link
Member

globin commented Aug 9, 2017

@ahmedtd this happens when using python.withPackages prior to 4495bfe

=> buildEnv with a bad makeWrapper in postInstall should make this reproducible.

@FRidh
Copy link
Member

FRidh commented Aug 9, 2017

Indeed. An example that has scripts in /bin is python.withPackages(ps: [ps.sphinx]).

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

9 participants