0

I know that bazel runs all commands in isolated sandboxes, however, I want to break them deliberately. Suppose I've got a project with the following layout:

.
├── BUILD
├── cpp
│   ├── BUILD
│   ├── foo.cpp
│   └── test_foo.cpp
├── python
│   ├── BUILD
│   ├── foo.py
│   └── test_foo.py
└── WORKSPACE

The file python/BUILD contains a py_test rule that runs some python tests that leave some artifacts (let's say some binary files). The file cpp/BUILD contains a cc_test rule that runs some cpp tests that require the artifacts left by the python tests.

The question is how I can do this? It would be better if the possible solution would provide all advantages of the incremental build system e.g. not running the python tests if they are older than artifacts and so on.

falsekeel
  • 157
  • 5

1 Answers1

1

The standard way for generating code for testing is a genrule, see example for the python script. After you have your genrule target (let say //path/to:foo_gen) all you have to do is to add the label to the cc_test data attribute:

cc_test(
  data = ['/path/to:foo_gen'],
...
)

File specified in the outs attibute of the genrule (see example above) will be available at path ./path/to/file_specified_in_outs

slsy
  • 1,257
  • 8
  • 21
  • I'm afraid that `genrule` is not suitable here because it works with sh commands, nor with bazel rules and it requires specifying the output files that is a bit inconvenient in my case. On the other hand `data` field of the `cc_test` would be useful on the second step, after artifacts have already been generated – falsekeel Sep 17 '21 at 18:13
  • 1
    With bash you can run any bazel target. In my previous project I was using a python target (`py_binary`) to generate a XML file for `cc_test`, and it was working. Just use magical `$(location //src:foo_tool)`. About specifying files: it is how bazel works: inputs and outputs must be know to perform dependency tracking. To avoid it just create one `sh_test` target, which will generate files and then run your second test inside that shell script – slsy Sep 17 '21 at 19:05