1

When I use a cc_test like:

cc_test(
    name = "xxx_test",
    srcs = glob([
        'xxx.cpp',
    ]),
    linkopts = [
        "-L/usr/local/lib",
        "-lcppunit",
        "-ldl",
        "-lz",
        "-ltbb",
        "-llz4",
        "-lzstd"
    ],
    deps = [
        ":feature_generator"
    ],
)

I need to run this cmd:

./bazel test @xxx//xxx:xxx_test --test_output=errors --test_env=LD_LIBRARY_PATH=/usr/local/lib

How can I omit it "--test_env=LD_LIBRARY_PATH=/usr/local/lib".

Does cc_test has env_path option?

I want to do like this

cc_test( 
*** 
*** 
test_env = ['/usr/local/lib'] 
) 

and I can test in this cmd:./bazel test @xxx//xxx:xxx_test --test_output=errors I dont want to write "--test_env=LD_LIBRARY_PATH=/usr/local/lib" when I want to test

now if I run this cmd:./bazel test @xxx//xxx:xxx_test --test_output=errors will get this error:

/home/alex.sh/.cache/bazel/_bazel_alex.sh/c973fcd5ba7eef8db46b22b84af3a149/bazel-sandbox/3561058496653596424/execroot/__main__/bazel-out/local-fastbuild/bin/external/feature_generator/featur\
e_generator/gbdt_test.runfiles/__main__/external/feature_generator/feature_generator/gbdt_test: error while loading shared libraries: libzstd.so.1: cannot open shared object file: No such fi\
le or directory
Alex
  • 65
  • 5
  • Sorry can you add more details on what is the problem exactly? E.g. what you would like to do and what happen when you try to do it? – Damien Martin-Guillerez Sep 21 '17 at 09:27
  • I want to do like this cc_test( *** *** test_env = ['/usr/local/lib'] ) and I can test in this cmd:./bazel test @xxx//xxx:xxx_test --test_output=errors I dont want to write "--test_env=LD_LIBRARY_PATH=/usr/local/lib" when I want to test – Alex Sep 21 '17 at 09:47
  • Why do you need to add the test env? Do you have a bazelrc that pass more option to Bazel? – Damien Martin-Guillerez Sep 21 '17 at 09:58
  • I update my question~ I thihk maybe libzstd.so is in the /usr/loca/lib, when bazel run test,can't find it. – Alex Sep 21 '17 at 10:01
  • Sry, I dont use bazelrc, bazelrc file can solve this question?0.0 – Alex Sep 22 '17 at 02:04
  • Ok yes you can put the flag in a bazelrc to not have to specify it on the command line, see https://docs.bazel.build/versions/master/bazel-user-manual.html#bazelrc But I was more asking because it seems like a bug that you have to specify that option for test but not for build actions. – Damien Martin-Guillerez Sep 22 '17 at 09:55
  • Yes,I think maybe linkopt has bug.I write "-L/usr/local/lib" in it,but when I run the test,run option not found "-L/usr/local/lib" – Alex Sep 25 '17 at 02:49

1 Answers1

1

So you can add the flag to your ~/.bazelrc file, e.g.:

test --test_env=LD_LIBRARY_PATH=/usr/local/lib

However, the fact that test action cannot find LD_LIBRARY_PATH while build action can sounds like a bug to me, you should file an issue on https://github.com/bazelbuild/bazel/issues/new