bazel genrule cmd that needs a filename

332 views Asked by At

I am trying to run objcopy --redefine-syms=filename command in Bazel genrule. My idea is: first create the filename using echo command in the first genrule, and use the filename in objcopy command in the second genrule. But I got this error message: in cmd attribute of genrule rule @lib_mod//:mod-symbol: label '@lib_mod//:symsfile' in $(location) expression is not a declared prerequisite of this rule. How to solve this issue?

The partial bazel file is here:

filegroup(
    name = "symsfile",
    srcs = [":sym_map"],
)
 
genrule(
    name = "sym_map",
    outs = ["syms.map"],
    cmd = """touch $@;
echo "js_string js_string_mod" >> $@;
""",
)
 
genrule(
    name = "mod-symbol",
    srcs = [LIB_PATH + "lib.a"],
    outs = [LIB_PATH + "lib_mod.a"],
    cmd = "objcopy --redefine-syms=$(location symsfile)  $< $@",
)
1

There are 1 answers

0
Benjamin Peterson On BEST ANSWER

The symbol renaming file is also an input to the last genrule; it must be added to srcs:

genrule(
    name = "mod-symbol",
    srcs = [
        LIB_PATH + "lib.a",
        ":sym_map",
    ],
    outs = [LIB_PATH + "lib_mod.a"],
    cmd = "objcopy --redefine-syms=$(location :sym_map)  $< $@",
)

(The intermediate symsfile filegroup is not necessary.)