pants icon indicating copy to clipboard operation
pants copied to clipboard

extra_env_vars for system_binary

Open ubmarco opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. I want to use drawio as a system_binary. It crashes with SIGSEGV and other errors if the following environment variables are not given: DISPLAY, HOME, DBUS_SESSION_BUS_ADDRESS. When pants runs the fingerprinting step, it invokes the binary with a cleared environment. There is currently no way to specify which env vars to keep for the fingerprinting step.

Describe the solution you'd like Add the parameter extra_env_vars to system_binary, just like it exists for adhoc_tool or shell_command.

Describe alternatives you've considered Workaround the issue by creating a wrapper shell script that replies to only the fingerprinting using a special args value and forwards all other options and parameters to the target system binary.

Additional context The fingerprinting error:

ValueError: Could not find a binary with name `drawio`.
The following paths were searched: /bin, /opt/drawio, /opt/homebrew/bin, /usr/bin, /usr/local/bin, /usr/sbin.

Btw, the error message is quite misleading as the binary can be found, just the fingerprinting fails. This was already reported in https://github.com/pantsbuild/pants/issues/19013.

The generated __run.sh currently looks like this:

#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /tmp/pants-sandbox-lpxUQZ
env -i  /opt/drawio/drawio --version

Executing __run.sh manually reveals the error:

$ env -i  /opt/drawio/drawio --version
[152836:0106/210646.416373:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[152836:0106/210646.416407:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.
[1]    152836 segmentation fault (core dumped)  env -i /opt/drawio/drawio --version

ubmarco avatar Jan 06 '24 20:01 ubmarco