I am starting to use Bazel as my C ++ project build system.
However, I am stuck in the following problem:
I am in a scenario where I automatically create a .hpp file.cpp (competent programming) file.
To reproduce my problem, you can simply use this minimal generator:
-- file.sh -- #!/bin/sh echo "int foo();" >> file.hpp echo "#include \"myLib/file.hpp\"\n\nint foo() { return 2017; }" >> file.cpp
My repo project: (WORKSPACE - empty file)
βββ myLib β βββ BUILD β βββ file.sh βββ WORKSPACE
BUILD File
genrule( name = "tangle_file", srcs = ["file.sh"], outs = ["file.cpp","file.hpp"], cmd = "./$(location file.sh);cp file.cpp $(@D);cp file.hpp $(@D);" ) cc_library( name = "file", srcs = ["file.cpp"], hdrs = ["file.hpp"],
I have two problems:
Question (A) regarding the part of genrule ():
The fact that I have to use
cmd = "./$(location file.sh);cp file.cpp $(@D);cp file.hpp $(@D);"
rather mysterious.
My first attempt:
cmd = "./$(location file.sh)"
However, in this case, I get the following error:
The declared output 'myLib / file.cpp' was not created by genrule. This is probably due to the fact that genrule did not actually generate this output, or because the output was a directory, and genrule was started remotely (note that only the contents of the declared output files are copied from the genrules started remotely)
Question (B) on the cc_library () part
I donβt know how to make Bazel aware that the target : the file depends on the target : tangle_file .
If I uncomment:
deps = [":tangle_file"],
I get the following error:
in the deps attribute of the cc_library // myLib rule: file: genrule rule '// myLib: tangle_file' is inappropriate here (expected cc_inc_library, cc_library, objc_library, experimental_objc_library or cc_proto_library).