kythe.io@v0.0.68-0.20240422202219-7225dbc01741/tools/build_rules/cc_resources.bzl (about) 1 def cc_resources(name, data, strip = None): 2 if strip: 3 basename_expr = "$${j##*%s}" % (strip,) 4 else: 5 basename_expr = "$$(basename \"$${j}\")" 6 out_inc = name + ".inc" 7 cmd = ('echo "static const struct FileToc kPackedFiles[] = {" > $(@); \n' + 8 "for j in $(SRCS); do\n" + ( 9 ' echo "{\\"%s\\"," >> $(@);\n' % (basename_expr,) 10 ) + 11 ' echo "R\\"filecontent($$(< $${j}))filecontent\\"" >> $(@);\n' + 12 ' echo "}," >> $(@);\n' + 13 "done &&\n" + 14 'echo "{nullptr, nullptr}};" >> $(@)') 15 if len(data) == 0: 16 fail("Empty `data` attribute in `%s`" % name) 17 native.genrule( 18 name = name + "_inc", 19 outs = [out_inc], 20 srcs = data, 21 cmd = cmd, 22 ) 23 native.cc_library( 24 name = name, 25 hdrs = [name + "_inc"], 26 )