Skip to content

Commit 65ffdaf

Browse files
committed
Add TemplateVariableInfo to the supported providers
1 parent db007bf commit 65ffdaf

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

docgen/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ sphinx_stardocs(
4545
"//lib/private:str_subject_bzl",
4646
"//lib/private:struct_subject_bzl",
4747
"//lib/private:target_subject_bzl",
48+
"//lib/private:template_variable_info_subject_bzl",
4849
"//lib/private:default_info_subject_bzl",
4950
],
5051
tags = ["docs"],

lib/private/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,20 @@ bzl_library(
252252
":label_subject_bzl",
253253
":run_environment_info_subject_bzl",
254254
":runfiles_subject_bzl",
255+
":template_variable_info_subject_bzl",
255256
":truth_common_bzl",
256257
"//lib:util_bzl",
257258
],
258259
)
259260

261+
bzl_library(
262+
name = "template_variable_info_subject_bzl",
263+
srcs = ["template_variable_info_subject.bzl"],
264+
deps = [
265+
":dict_subject_bzl",
266+
],
267+
)
268+
260269
bzl_library(
261270
name = "expect_bzl",
262271
srcs = ["expect.bzl"],

lib/private/target_subject.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ load(":instrumented_files_info_subject.bzl", "InstrumentedFilesInfoSubject")
3232
load(":label_subject.bzl", "LabelSubject")
3333
load(":run_environment_info_subject.bzl", "RunEnvironmentInfoSubject")
3434
load(":runfiles_subject.bzl", "RunfilesSubject")
35+
load(":template_variable_info_subject.bzl", "TemplateVariableInfoSubject")
3536
load(":truth_common.bzl", "enumerate_list_as_lines")
3637

3738
def _target_subject_new(target, meta):
@@ -423,6 +424,11 @@ PROVIDER_SUBJECT_FACTORIES = [
423424
name = "testing.ExecutionInfo",
424425
factory = ExecutionInfoSubject.new,
425426
),
427+
struct(
428+
type = platform_common.TemplateVariableInfo,
429+
name = "platform_common.TemplateVariableInfo",
430+
factory = TemplateVariableInfoSubject.new,
431+
),
426432
]
427433

428434
# We use this name so it shows up nice in docs.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""# TemplateVariableInfoSubject"""
16+
17+
load(":dict_subject.bzl", "DictSubject")
18+
19+
def _template_variable_info_subject_new(info, *, meta):
20+
"""Creates a new `TemplateVariableInfoSubject`
21+
22+
Method: TemplateVariableInfoSubject.new
23+
24+
Args:
25+
info: ([`TemplateVariableInfo`]) provider instance.
26+
meta: ([`ExpectMeta`]) of call chain information.
27+
"""
28+
29+
# buildifier: disable=uninitialized
30+
public = struct(
31+
variables = lambda *a, **k: _template_variable_info_subject_variables(self, *a, **k),
32+
)
33+
self = struct(
34+
actual = info,
35+
meta = meta,
36+
)
37+
return public
38+
39+
def _template_variable_info_subject_variables(self):
40+
"""Creates a `DictSubject` to assert on the variables dict.
41+
42+
Method: TemplateVariableInfoSubject.variables
43+
44+
Args:
45+
self: implicitly added
46+
47+
Returns:
48+
[`DictSubject`] of the str->str variables map.
49+
"""
50+
return DictSubject.new(
51+
self.actual.variables,
52+
meta = self.meta.derive("variables()"),
53+
)
54+
55+
# We use this name so it shows up nice in docs.
56+
# buildifier: disable=name-conventions
57+
TemplateVariableInfoSubject = struct(
58+
new = _template_variable_info_subject_new,
59+
variables = _template_variable_info_subject_variables,
60+
)

0 commit comments

Comments
 (0)