0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 16:46:00 +01:00
mongodb/bazel/config/render_template.bzl
Daniel Moody 554901cea9 SERVER-93200 fix windows incremental builds (#26297)
GitOrigin-RevId: c8bf78533cd740cd89ff62d06872e53c2da780a6
2024-08-20 20:08:54 +00:00

49 lines
1.7 KiB
Python

def render_template_impl(ctx):
python = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime
python_libs = [py_dep[PyInfo].transitive_sources for py_dep in ctx.attr.python_libs]
python_path = []
for py_dep in ctx.attr.python_libs:
for path in py_dep[PyInfo].imports.to_list():
if path not in python_path:
python_path.append(ctx.expand_make_variables("python_library_imports", "$(BINDIR)/external/" + path, ctx.var))
expanded_args = [
ctx.expand_make_variables("render_template_expand", ctx.expand_location(arg, ctx.attr.srcs), ctx.var)
for arg in ctx.attr.cmd
]
ctx.actions.run(
executable = python.interpreter.path,
outputs = [ctx.outputs.output],
inputs = depset(transitive = [python.files, depset([arg.files.to_list()[0] for arg in ctx.attr.srcs])] + python_libs),
arguments = expanded_args,
env = {"PYTHONPATH": ctx.configuration.host_path_separator.join(python_path)},
mnemonic = "TemplateRenderer",
)
return [DefaultInfo(files = depset([ctx.outputs.output]))]
render_template = rule(
render_template_impl,
attrs = {
"srcs": attr.label_list(
doc = "The input files of this rule.",
allow_files = True,
),
"output": attr.output(
doc = "The output of this rule.",
mandatory = True,
),
"cmd": attr.string_list(
doc = "The command line arguments to pass to python",
),
"python_libs": attr.label_list(
providers = [PyInfo],
default = [],
),
},
toolchains = ["@bazel_tools//tools/python:toolchain_type"],
output_to_genfiles = True,
)