def _generate_interface_impl(ctx): out_hdrs = [ ctx.actions.declare_file(ctx.attr.interface + ".h"), ctx.actions.declare_file(ctx.attr.interface + "_mock.hpp"), ] out_srcs = [ ctx.actions.declare_file(ctx.attr.interface + "_mock.cpp"), ] args = ["-l", ctx.file.license.path, "-o", out_hdrs[0].dirname] ctx.actions.run( tools = ctx.attr._interface_generator_tool[DefaultInfo].data_runfiles.files, inputs = [ctx.file.license], outputs = out_srcs + out_hdrs, executable = ctx.executable._interface_generator_tool, arguments = args, mnemonic = "GenerateInterface", ) compilation_ctx = cc_common.create_compilation_context( headers = depset(out_hdrs), includes = depset([out_hdrs[0].dirname]), ) return [ DefaultInfo(files = depset(out_srcs)), CcInfo(compilation_context = compilation_ctx), ] generate_interface_rule = rule( implementation = _generate_interface_impl, attrs = { "interface": attr.string(), "license": attr.label(allow_single_file = True), "_interface_generator_tool": attr.label( executable = True, cfg = "exec", allow_files = True, providers = [DefaultInfo], default = Label("//bin:interface_generator"), ), "outs": attr.output_list(), }, ) def generate_interface(name, interface, license, visibility = None): generate_interface_rule( name = name, interface = interface, outs = [name + "_mock.cpp"], license = license, visibility = visibility, )