<gh_stars>0
# Primitive reimplementation of the buildflag_header scripts used in the gn build

def _buildflag_header_impl(ctx):
    content = "// Generated by build/buildflag_header.bzl\n"
    content += '// From "' + ctx.attr.name + '"\n'
    content += "\n#ifndef %s_h\n" % ctx.attr.name
    content += "#define %s_h\n\n" % ctx.attr.name
    content += '#include "build/buildflag.h"\n\n'
    for key in ctx.attr.flags:
        content += "#define BUILDFLAG_INTERNAL_%s() (%s)\n" % (key, ctx.attr.flags[key])
    content += "\n#endif  // %s_h\n" % ctx.attr.name
    ctx.actions.write(output = ctx.outputs.header, content = content)

buildflag_header = rule(
    implementation = _buildflag_header_impl,
    attrs = {
        "flags": attr.string_dict(mandatory = True),
        "header": attr.string(mandatory = True),
        "header_dir": attr.string(),
    },
    outputs = {"header": "%{header_dir}%{header}"},
    output_to_genfiles = True,
)

# Primitive reimplementation of the buildflag_header scripts used in the gn build

def _buildflag_header_impl(ctx):
    content = "// Generated by build/buildflag_header.bzl\n"
    content += '// From "' + ctx.attr.name + '"\n'
    content += "\n#ifndef %s_h\n" % ctx.attr.name
    content += "#define %s_h\n\n" % ctx.attr.name
    content += '#include "build/buildflag.h"\n\n'
    for key in ctx.attr.flags:
        content += "#define BUILDFLAG_INTERNAL_%s() (%s)\n" % (key, ctx.attr.flags[key])
    content += "\n#endif  // %s_h\n" % ctx.attr.name
    ctx.actions.write(output = ctx.outputs.header, content = content)

buildflag_header = rule(
    implementation = _buildflag_header_impl,
    attrs = {
        "flags": attr.string_dict(mandatory = True),
        "header": attr.string(mandatory = True),
        "header_dir": attr.string(),
    },
    outputs = {"header": "%{header_dir}%{header}"},
    output_to_genfiles = True,
)
# Primitive reimplementation of the buildflag_header scripts used in the gn build #ifndef %s_h\n" % ctx.attr.name #endif  // %s_h\n" % ctx.attr.name