4

I have a test:

cc_test(
    name = "common_test",
    linkstatic = 1,
    srcs = glob([
        "common/test/*.cpp",
    ]),
    linkopts = [
        "-L/usr/local/lib",
        "-L/usr/lib64",
        "-g",
        "-lcppunit",
        "-ldl",
        "-lz",
        "-ltbb",
        "-llz4",
    ],
    data= [
        "@:testdata"
    ]
)

my testdata is define in:

filegroup(
    name = "testdata",
    srcs = glob([
        "testdata/biz_test/*.json",
    ]),
    visibility = ["//visibility:public"]
)

the TEST_PATH get by here :

TESTBASE_BASE() {
    char cwdBuf[10240];
    if (getcwd(cwdBuf, 10240) == NULL) {
        std::cerr << "get cwd failed, error:" << strerror(errno) << std::endl;
        assert(false);
    }
    _testRootPath = cwdBuf;
}
std::string GET_TEST_DATA_PATH(std::string bazelTestPath = "") const {
    return _testRootPath + bazelTestPath + std::string("/testdata/");
}

in my testcode:

GET_TEST_DATA_PATH() +"/biz_info_test/" can't find the testdata
GET_TEST_DATA_PATH('/external/my_project') +"/biz_info_test/" is ok

Because I have a lot of projects to be changed to bazel compilation, I need a more general way to solve the testdata path problem.I dont want to write code like this:

GET_TEST_DATA_PATH('/external/my_project1') +"/biz_info_test/"
GET_TEST_DATA_PATH('/external/my_project2') +"/biz_info_test/"
GET_TEST_DATA_PATH('/external/my_project3') +"/biz_info_test/"

I hope bazel can do like this: It can find where is my WORKSPACE dir.

my_pj/
├── my_pj
│   └── BUILD
├── testdata
└── WORKSPACE
so my testdata dir is: _testRootPath + std::string("/testdata/")
Alex
  • 65
  • 5
  • Hello, This is a known issue in Bazel, we are redesigning the layout of external repositories but that takes time. Can you tell here what you would like to see? Because certainly you have to provide the id my_project1 at least? – Damien Martin-Guillerez Sep 22 '17 at 10:12
  • I hope bazel can do like this: It can find where is my WORKSPACE dir. my_pj/ ├── my_pj │ └── BUILD ├── testdata └── WORKSPACE so my testdata dir is: _testRootPath + std::string("/testdata/") – Alex Sep 27 '17 at 12:10
  • And I update my question – Alex Sep 27 '17 at 12:15

1 Answers1

0

This is a known issue and we are working on changing it to match your expectation. It is unfortunately a hard change because it impacts all the projects building with Bazel (including everything at Google).