I am trying to build Makefile of a submodule in a bazel project. I see that bazel does provide genrule to execute bash command. I am facing two issues currently -
1. How to cd into a directory before executing command, something like -
genrule(
name = "hello-make",
srcs = ["hello"] + glob(["hello/**"]),
outs = ["hello/main"],
cmd = "(cd $(location :hello) && make)",
)
2. How do I update update submodule before executing genrule?
Adding cmd = "(git submodule init && git submodule update)"
gives fatal: Not a git repository (or any of the parent directories): .git
Step to reproduce:
git clone git@github.com:bazelbuild/examples.git
cd examples/ && git submodule add git@github.com:mucsi96/cpp-hello-world.git cpp-tutorial/stage1/main/hello
cd cpp-tutorial/stage1/ && bazel build //main:hello-world
After this step I want to add a rule that allows me init, update and make the hello submodule.
Is there a better way to build git@github.com:mucsi96/cpp-hello-world.git
than creating it as a submodule of git clone git@github.com:bazelbuild/examples.git
?
The actual projects are more complex and creating a BUILD file for cpp-hello-world.git is not feasible.