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

patchShebangs: Allow multiple args #60559

Merged

Conversation

JohnAZoidberg
Copy link
Member

@JohnAZoidberg JohnAZoidberg commented May 1, 2019

Motivation for this change

It's tempting to think patchShebangs supports multiple arguments.
Without this patch it just silently ignores all but the first. Now it
patches the shebangs in all of its arguments.

Fixes: #57695

Obviously I haven't tested it on nixpkgs because it rebuilds everything. Please check whether there might be some edge cases that I forgot which could break with these changes.
I tried the function on its own (copied tothe patchPhase of a derivation) and it seems to work as intended.

Seems like there's no docbook documentation for this function. I think I'll do that next.

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 nix-review --run "nix-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.

@JohnAZoidberg JohnAZoidberg changed the title Patchshebangs multiple args pathShebangs: Allow multiple args May 1, 2019
@JohnAZoidberg JohnAZoidberg changed the title pathShebangs: Allow multiple args patchShebangs: Allow multiple args May 1, 2019
rm "$timestamp"
fi
fi
done < <(find "$dir" -type f -perm -0100 -print0)
Copy link
Member

Choose a reason for hiding this comment

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

Could you just put find "$@" here? I think that could be more efficient

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that would remove the need for my loop, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah would just have to remove the [ -e "$dir" ] || return 0 part as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I tried the function out on its own and it seems to be doing the right things.

@FRidh
Copy link
Member

FRidh commented May 4, 2019

Waiting for reviews before merging.

@@ -95,7 +94,7 @@ patchShebangs() {
rm "$timestamp"
fi
fi
done < <(find "$dir" -type f -perm -0100 -print0)
done < <(find "$@" -type f -perm -0100 -print0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change, combined with the removal of line 43, means the function will fail clumsily if no arguments are passed to it. But considering that the old version silently and surprisingly ignores nonexistent files, this could be considered an improvement. ;) However, since it's a change in behavior, might it cause build failures? Should we let them happen? (Serious question.)

Copy link
Member Author

Choose a reason for hiding this comment

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

What about we check if there are no arguments supplied in line 43?

  if [ $# -eq 0 ]; then
      echo "No arguments supplied to patchShebangs" >&2
      return 3141592  # Not sure which return code is best, maybe just 1
  fi

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 made it exit with 0 like it was before so that existing scripts don't break.

It's tempting to think patchShebangs supports multiple arguments.
Without this patch it just silently ignores all but the first. Now it
patches the shebangs in all of its arguments.

Fixes: NixOS#57695
@JohnAZoidberg
Copy link
Member Author

@matthewbauer Do you still approve?
Does anyone else have any thoughts?
@chreekat Does this address your concerns?

@chreekat
Copy link
Contributor

Lgtm, yep

[ -e "$dir" ] || return 0
if [ $# -eq 0 ]; then
echo "No arguments supplied to patchShebangs" >&2
exit 0
Copy link
Member

Choose a reason for hiding this comment

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

This should be >0 so bash recognizes it as an error

Copy link
Member

Choose a reason for hiding this comment

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

Should be return actually

Copy link
Member

Choose a reason for hiding this comment

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

Why >0? That just pipes the string to a file with name "0"?

Copy link
Member

Choose a reason for hiding this comment

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

Oops meant "greater than 0". That is non-zero code.

Copy link
Member Author

Choose a reason for hiding this comment

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

ohhhh

local dir="$1"

header "patching script interpreter paths in $dir"
echo "patching script interpreter paths in $@"
Copy link
Member

Choose a reason for hiding this comment

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

I think header should be kept too

Copy link
Member Author

Choose a reason for hiding this comment

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

But it just calls echo and is marked as obsolete. https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L115

Commit "patchShebangs: Allow for multiple arguments" 4a1e51f
removed the check. We don't want to break existing usages so this
introduces it again with a successful exit code.
@matthewbauer matthewbauer merged commit 87a69ed into NixOS:staging Jun 6, 2019
@infinisil
Copy link
Member

#60559 (comment) ?

@jtojnar jtojnar mentioned this pull request Jun 16, 2019
10 tasks
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.

5 participants