I am new to Bazel. I have a project which is built with Bazel. But some of the source files are pre-codegened and then compile them with Bazel. Now I can run the bash script standalone and run the bazel command:
.
|-- project
| |-- BUILD (will depend on temp_output:codegen)
| |-- scripts
| | |-- codegen.sh (read config.yaml and generate codegen.cpp/hpp and a BUILD.bazel)
| |-- config
| | |-- config.yaml
| |-- temp_output
| | |-- codegen.cpp (not existed before running codegen.sh)
| | |-- codegen.hpp (not existed before running codegen.sh)
| | |-- BAZEL.build (not existed before running codegen.sh)
|-- WORKSPACE
$ ./scripts/codegen.sh
$ bazel build :project
What are done in the codegen.sh:
- Read the config.yaml where the contains some other WORKSPACE path and name.
- Query the targets in that WORKSPACE.
- Create cpp/hpp files to include some headers files.
- Create a new BUILD file, adding the depends on those targets.
My goal is to embed the bash script in the bazel system. I tried with rule + action.run. But the failures are for:
- sandbox directory is not readable nor writable.
- input files cannot be found in sandbox.
Is there a fancy way to do this? Or any examples I can refer to?