xref: /aosp_15_r20/external/bazelbuild-rules_testing/lib/private/execution_info_subject.bzl (revision d605057434dcabba796c020773aab68d9790ff9f)
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"""# ExecutionInfoSubject"""
16
17load(":dict_subject.bzl", "DictSubject")
18load(":str_subject.bzl", "StrSubject")
19
20def _execution_info_subject_new(info, *, meta):
21    """Create a new `ExecutionInfoSubject`
22
23    Method: ExecutionInfoSubject.new
24
25    Args:
26        info: ([`testing.ExecutionInfo`]) provider instance.
27        meta: ([`ExpectMeta`]) of call chain information.
28
29    Returns:
30        `ExecutionInfoSubject` struct.
31    """
32
33    # buildifier: disable=uninitialized
34    public = struct(
35        # keep sorted start
36        requirements = lambda *a, **k: _execution_info_subject_requirements(self, *a, **k),
37        exec_group = lambda *a, **k: _execution_info_subject_exec_group(self, *a, **k),
38        # keep sorted end
39    )
40    self = struct(
41        actual = info,
42        meta = meta,
43    )
44    return public
45
46def _execution_info_subject_requirements(self):
47    """Create a `DictSubject` for the requirements values.
48
49    Method: ExecutionInfoSubject.requirements
50
51    Args:
52        self: implicitly added
53
54    Returns:
55        `DictSubject` of the requirements.
56    """
57    return DictSubject.new(
58        self.actual.requirements,
59        meta = self.meta.derive("requirements()"),
60    )
61
62def _execution_info_subject_exec_group(self):
63    """Create a `StrSubject` for the `exec_group` value.
64
65    Method: ExecutionInfoSubject.exec_group
66
67    Args:
68        self: implicitly added
69
70    Returns:
71        A [`StrSubject`] for the exec group.
72    """
73    return StrSubject.new(
74        self.actual.exec_group,
75        meta = self.meta.derive("exec_group()"),
76    )
77
78# We use this name so it shows up nice in docs.
79# buildifier: disable=name-conventions
80ExecutionInfoSubject = struct(
81    new = _execution_info_subject_new,
82    requirements = _execution_info_subject_requirements,
83    exec_group = _execution_info_subject_exec_group,
84)
85