| # Copyright 2022 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Adds a rule emulating the GN buildflags behavior""" |
| |
| def _buildflags_impl(ctx): |
| out = ctx.outputs.out.short_path |
| guard = out.upper() |
| guard = guard.replace("/", "_") |
| guard = guard.replace(".", "_") |
| guard += "_" |
| |
| file_content = "// Generated by builflags.srl\n\n" |
| file_content += "#ifndef " + guard + "\n" |
| file_content += "#define " + guard + "\n" |
| file_content += "\n" |
| file_content += "#include \"build/buildflag.h\"\n" |
| file_content += "\n" |
| for flag in ctx.attr.flags: |
| file_content += "#define MINI_CHROMIUM_INTERNAL_BUILDFLAG_VALUE_" + \ |
| flag + "() (" + ctx.attr.flags[flag] + ")\n" |
| file_content += "\n" |
| file_content += "#endif // " + guard + "\n" |
| |
| ctx.actions.write(ctx.outputs.out, file_content) |
| |
| buildflags = rule( |
| implementation = _buildflags_impl, |
| attrs = { |
| "out": attr.output(mandatory = True), |
| "flags": attr.string_dict(mandatory = True), |
| }, |
| ) |