我有一个(基础的)C++项目:
├── bin
│ ├── BUILD
│ ├── example.cpp
├── data
│ └── someData.txt
└── WORKSPACE
可执行文件 example.cpp 使用了来自 data/
目录的一些数据文件:
#include <fstream>
#include <iostream>
int main()
{
std::ifstream in("data/someData.txt");
if (!in)
{
std::cerr << "Can not open file!";
return EXIT_FAILURE;
}
std::string message;
if (!(in >> message))
{
std::cerr << "Can not read file content!";
return EXIT_FAILURE;
}
std::cout << message << std::endl;
return EXIT_SUCCESS;
}
我的Bazel设置是最小的:
- WORKSPACE:空文件
- bin/BUILD:
cc_binary(name = "example",srcs = ["example.cpp"])
- data/someData.txt:包含
Hello_world!
行
问题在于,Bazel将所有这些文件移动到特殊位置:
.
├── bazel-Bazel_with_Data -> ...
├── bazel-bin -> ...
├── bazel-genfiles -> ...
├── bazel-out -> ...
├── bazel-testlogs -> ...
特别是,示例可执行文件找不到data/someData.txt文件:
bazel run bin:example
将打印:
INFO: Analysed target //bin:example (0 packages loaded).
INFO: Found 1 target...
Target //bin:example up-to-date:
bazel-bin/bin/example
INFO: Elapsed time: 0.101s, Critical Path: 0.00s
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/bin/example
Can not open file!ERROR: Non-zero return code '1' from command: Process exited with status 1
问题是如何进行管理?
我希望示例可执行文件能够找到Data/someData.txt文件。
exports_files(glob(['**']))
- 如何引用整个组?留下路径解析,因为这对程序来说只是黑魔法 =( - shybovycha