From 65ffdafc16ba18dfb957ae3b667b7a7bbec2e1b0 Mon Sep 17 00:00:00 2001 From: Mike Lundy Date: Fri, 8 Aug 2025 19:54:50 -0700 Subject: [PATCH] Add TemplateVariableInfo to the supported providers --- docgen/BUILD | 1 + lib/private/BUILD | 9 +++ lib/private/target_subject.bzl | 6 ++ .../template_variable_info_subject.bzl | 60 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 lib/private/template_variable_info_subject.bzl diff --git a/docgen/BUILD b/docgen/BUILD index dbb8391..e996433 100644 --- a/docgen/BUILD +++ b/docgen/BUILD @@ -45,6 +45,7 @@ sphinx_stardocs( "//lib/private:str_subject_bzl", "//lib/private:struct_subject_bzl", "//lib/private:target_subject_bzl", + "//lib/private:template_variable_info_subject_bzl", "//lib/private:default_info_subject_bzl", ], tags = ["docs"], diff --git a/lib/private/BUILD b/lib/private/BUILD index 8ef5703..8d6bb10 100644 --- a/lib/private/BUILD +++ b/lib/private/BUILD @@ -252,11 +252,20 @@ bzl_library( ":label_subject_bzl", ":run_environment_info_subject_bzl", ":runfiles_subject_bzl", + ":template_variable_info_subject_bzl", ":truth_common_bzl", "//lib:util_bzl", ], ) +bzl_library( + name = "template_variable_info_subject_bzl", + srcs = ["template_variable_info_subject.bzl"], + deps = [ + ":dict_subject_bzl", + ], +) + bzl_library( name = "expect_bzl", srcs = ["expect.bzl"], diff --git a/lib/private/target_subject.bzl b/lib/private/target_subject.bzl index 6961e6d..7161a0f 100644 --- a/lib/private/target_subject.bzl +++ b/lib/private/target_subject.bzl @@ -32,6 +32,7 @@ load(":instrumented_files_info_subject.bzl", "InstrumentedFilesInfoSubject") load(":label_subject.bzl", "LabelSubject") load(":run_environment_info_subject.bzl", "RunEnvironmentInfoSubject") load(":runfiles_subject.bzl", "RunfilesSubject") +load(":template_variable_info_subject.bzl", "TemplateVariableInfoSubject") load(":truth_common.bzl", "enumerate_list_as_lines") def _target_subject_new(target, meta): @@ -423,6 +424,11 @@ PROVIDER_SUBJECT_FACTORIES = [ name = "testing.ExecutionInfo", factory = ExecutionInfoSubject.new, ), + struct( + type = platform_common.TemplateVariableInfo, + name = "platform_common.TemplateVariableInfo", + factory = TemplateVariableInfoSubject.new, + ), ] # We use this name so it shows up nice in docs. diff --git a/lib/private/template_variable_info_subject.bzl b/lib/private/template_variable_info_subject.bzl new file mode 100644 index 0000000..3fef42d --- /dev/null +++ b/lib/private/template_variable_info_subject.bzl @@ -0,0 +1,60 @@ +# Copyright 2023 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""# TemplateVariableInfoSubject""" + +load(":dict_subject.bzl", "DictSubject") + +def _template_variable_info_subject_new(info, *, meta): + """Creates a new `TemplateVariableInfoSubject` + + Method: TemplateVariableInfoSubject.new + + Args: + info: ([`TemplateVariableInfo`]) provider instance. + meta: ([`ExpectMeta`]) of call chain information. + """ + + # buildifier: disable=uninitialized + public = struct( + variables = lambda *a, **k: _template_variable_info_subject_variables(self, *a, **k), + ) + self = struct( + actual = info, + meta = meta, + ) + return public + +def _template_variable_info_subject_variables(self): + """Creates a `DictSubject` to assert on the variables dict. + + Method: TemplateVariableInfoSubject.variables + + Args: + self: implicitly added + + Returns: + [`DictSubject`] of the str->str variables map. + """ + return DictSubject.new( + self.actual.variables, + meta = self.meta.derive("variables()"), + ) + +# We use this name so it shows up nice in docs. +# buildifier: disable=name-conventions +TemplateVariableInfoSubject = struct( + new = _template_variable_info_subject_new, + variables = _template_variable_info_subject_variables, +)