-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
bazel: remove dependence on buildFHSUserEnv #23074
Conversation
@izuk, thanks for your PR! By analyzing the history of the files in this pull request, we identified @IreneKnapp, @benley and @teh to be potential reviewers. |
|
I switched to using patchShebangs, except for a few cases. |
in bazelBinary | ||
sourceRoot = "."; | ||
|
||
patches = [ ./bin_to_env.patch ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the Bazel team would accept most of these changes upstream. Using /usr/bin/env bash
seems like a pretty universally sane thing to do in place of /bin/bash
, unless you actively distrust PATH in the environment, and bazel manages PATH itself when it sets up build sandboxes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can ask the devs if they'd be OK with that. Maybe next week :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the patch is smaller now that I use patchShebangs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benley I asked on the conda
(a mostly Python package manager) issue tracker once if they could change to /usr/bin/env bash
and got back
I've never come across a Unix system, which does not have /bin/bash installed.
...
The easiest fix would be to create a link in /bin/bash to the location where bash is located on that system, I would say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FRidh then those people have never used something else but linux and MacOS X. On FreeBSD bash
is installed in /usr/local/bin
or in Solaris it is even in /opt
.
I'm not the maintainer nor do I have any formal connection to NixOS, but please verify manually that the built bazel can build C++ and Java binaries which, themselves, work properly. Ideally someday there would be an automated test for this. |
I've added a checkPhase that uses the built bazel to build and run two tests, for CPP and for Java. I've also verified that this behaves as expected: $ nix-env -f . -iA bazel |
Awesome! Thank you for making this work. |
Anything else I need to do for this to get approved? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise generally looks good, although I don't like having large patches like this and should generally also be tried to fix it upstream.
|
||
try { | ||
- new Command(new String[] {"/bin/true", null}).execute(); | ||
+ new Command(new String[] {"/usr/bin/env", "true", null}).execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
is a shell built-in normally and won't work through /usr/bin/env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true is also an executable provided by coreutils. That's essentially what the test (which now passes, BTW) uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still want me to do something about this? If you object to this part of the patch I can just remove it. It doesn't affect the build, just the unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo this ought to stay, since it looks like it won't work without the patch. In theory you could patch in the /nix/store path to bin/true but if it's findable in $PATH then this is probably good enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, do I need to do something about this? I'd like to move on, and this pull request is holding me back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge it. It sounds like the change works and it's an improvement over the FHSUserEnv machinery.
The test phase is failing when in sandboxed mode due to no
|
Weird. Seems like an easy fix at least: add coreutils to buildInputs. I'm testing that out now. |
It might be nicer to change the patch to replace /bin/bash with @bash@/bin/bash and then run one of the substitute* scripts in postPatch. I think that would also require propagatedBuildInputs. Not sure. I can look at that later this week if anyone thinks that's a good idea. |
It seems like patching the shebang lines may be necessary after all; even with coreutils in propagatedBuildInputs there seems to be nothing at /usr/bin/env during checkPhase. |
Motivation for this change
Reduce the complexity of default.nix for bazel.
The main issues I found were:
For the former I manually patched a bunch of the shell scripts and the main Java command helper. The patch could probably be pruned down to a handful of places if we don't care about the tests.
For the latter I set TMPDIR=/tmp before compiling. This is ugly and I welcome a better solution.
I'm also not clear on how necessary propagatedBuildInputs is, or whether this works on Darwin. I would appreciate some help/advice there.
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)