Can i create a directory and copy the files in to that direcotry using genrule in bazel

4,033 views
Skip to first unread message

Sravanthi Nainala

unread,
Feb 1, 2019, 8:29:49 AM2/1/19
to bazel-discuss
I tried to create directories and copy the files from one directory to the created ones :

genrule(
    name = "copyoffiles",
    srcs = ["files/conf/version1-conf.xml", "files/src/version1.sh"],
    cmd = """
           mkdir share
           mkdir share/conf
           mkdir bin
           cp $(SRCS) $(@D)
          """,
    outs = ["share/conf", "bin"],
)


Where the requirement is to get the file(which ends with .xml) under share/conf and file(ends with .sh) under bin folder

But when i am trying to run with bazel , i am facing below issue


LD:85:1: declared output 'share/conf' was not created by genrule. This is probably because the genrule actually didn't create this output, or because the output was a directory and the genrule was run remotely (note that only the contents of declared file outputs are copied from genrules run remotely).



And also i tried with different ways where i am getting the files under bazel-genfiles without any folder structure if i keep OUTS = ["version1-conf.xml", "version1.sh"]

output structure : bazel-genfiles/version1-conf.xml , bazel-genfiles/version1.sh
Required output structure : bazel-genfiles/share/conf/version1-conf.xml , bazel-genfiles/bin/version1.sh


Gregg Reynolds

unread,
Feb 1, 2019, 9:54:53 AM2/1/19
to Sravanthi Nainala, bazel-discuss
I believe your outs must explicitly list each file in each dir, e.g. outs=["share/conf/foo.xml", "bin/bar.xml"].  And since you're outputting to two different directories you'll have to write each one. You might need two genrules, dunnno.

Here's some code that works for me. This patches an external lib (mbedtls):

exports_files("ocf.patch"])
mbedtls_hdrs = ["include/mbedtls/aes.h", ... etc....]

genrule(
    name = "patch",
    srcs = glob(["**/*.c"])
    + mbedtls_hdrs
         + glob(["**/*.data"])
         + glob(["**/*.function"])
         + glob(["**/*.sh"])
         + ["@//src/sec/mbedtls:ocf.patch"],
    outs = ["patched/" + x for x in glob(["**/library/*.c"])]
         + ["patched/" + x for x in mbedtls_hdrs],
     cmd  = "\n".join([
        "cp -LR external/mbedtls/ patched",
        "patch -dpatched -p1 -l -f < $(location @//src/sec/mbedtls:ocf.patch)",
        "cp -R patched $(@D)",
        ])
)

HTH,

Gregg

Reply all
Reply to author
Forward
0 new messages