Bazel: set runtime environment variable and configuration file location for cc_binary/cc_test

旧巷老猫 提交于 2020-01-15 06:01:13

问题


I am trying to use odbc++ in a C++ application on linux. The following build file is used to include the library as an external dependency

licenses(["notice"])
cc_library(
    name = "lib",
    srcs=["lib/libodbc.so","lib64/libodbc++-mt.so"],
    hdrs=glob(["include/**/*.h","include/*.h"]),
    includes = ["include"],
    visibility = ["//visibility:public"],
    linkstatic = 1,
    data = [ "odbc.ini", "odbcinst.ini" ]
)

My bash profile has ODBCINI and OBCDINST set so running the binary directly from command line is fine. However, the environment variable ODBCINI and ODBCINST are not set when running bazel test.

Is there anyway to include the configuration files and set the run time environment variables to them?

Thanks


回答1:


You can set environment variables for test execution in bazel with the --test_env flag. The documentation is here: https://docs.bazel.build/versions/master/command-line-reference.html

For example, bazel build --test_env ODBCINI=foo //my:test



来源:https://stackoverflow.com/questions/43944933/bazel-set-runtime-environment-variable-and-configuration-file-location-for-cc-b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!