question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--test_env=LD_LIBRARY_PATH not passed to tests on MacOS

See original GitHub issue

I need to manipulate the LD_LIBRARY_PATH used by my test binaries. I tried using --test_env=LD_LIBRARY_PATH and --test_env=LD_LIBRARY_PATH=foo and neither were set in the environment when running the tests. Nor are DYLD_LIBRARY_PATH and most other DYLD_* values. Arbitrary other environment variables are correctly passed (–test_env=FOO=1, etc).

I can’t seem to find any code in bazel that is explicitly stripping these, but perhaps I’m missing something. Why is this happening? The docs state that --test_env can be used for this kind of stuff (explicitly listing --test_env=PATH as an example) - why would LD_LIBRARY_PATH be special?

I was able to confirm this with the following:

sh_binary(name = "runner", srcs = ["runner.sh"])
sh_test(name = "dummy", srcs=["runner.sh"])
#!/bin/bash
export
echo $LD_LIBRARY_PATH
$ blaze test :dummy --test_env=LD_LIBRARY_PATH=/foo --test_env=FOO=1 --run_under=:runner

Output:

...
declare -x FOO="1"
...

LD_LIBRARY_PATH is nowhere in that list and the value is empty.

$ bazel version
Build label: 0.6.1-homebrew
Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Oct 6 02:36:58 2017 (1507257418)
Build timestamp: 1507257418
Build timestamp as int: 1507257418

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
susinmotioncommented, May 12, 2020

The problem does persist with --incompatible_strict_action_env and passing the variables via --action_env.

I poked around a little, and it seems that El Capitan and later strip LD_LIBRARY_PATH/DYLD_LIBRARY_PATH for executables in certain directories, including /bin. see: https://forums.developer.apple.com/thread/9233

I’m going to close this as a not-Bazel-related issue, but please comment if there’s something we should look into further.

0reactions
thundergolfercommented, Sep 12, 2019

Related to https://github.com/bazelbuild/bazel/issues/6648?

From memory I didn’t have that on and remember seeing the issue I linked at the time, and also do remember passing by --action_env as a test which was unsuccessful. Memory’s fallible though, so I’d have to check again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found