1# Copyright (C) 2023 The Android Open Source Project 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 cocc 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"""CcInfo testing subject.""" 16 17load("@rules_testing//lib:truth.bzl", "subjects") 18 19def cc_info_subject(info, *, meta): 20 """Creates a new `CcInfoSubject` for a CcInfo provider instance. 21 22 Method: CcInfoSubject.new 23 24 Args: 25 info: The CcInfo object 26 meta: ExpectMeta object. 27 28 Returns: 29 A `CcInfoSubject` struct 30 """ 31 32 # buildifier: disable=uninitialized 33 public = struct( 34 # go/keep-sorted start 35 headers = lambda *a, **k: _cc_info_subject_headers(self, *a, **k), 36 includes = lambda *a, **k: _cc_info_subject_includes(self, *a, **k), 37 system_includes = lambda *a, **k: _cc_info_subject_system_includes(self, *a, **k), 38 # go/keep-sorted end 39 ) 40 self = struct( 41 actual = info, 42 meta = meta, 43 ) 44 return public 45 46def _cc_info_subject_includes(self): 47 """Returns a `CollectionSubject` for the `includes` attribute. 48 49 Method: CcInfoSubject.includes 50 """ 51 return subjects.collection( 52 self.actual.compilation_context.includes, 53 meta = self.meta.derive("includes()"), 54 ) 55 56def _cc_info_subject_system_includes(self): 57 """Returns a `CollectionSubject` for the `system_includes` attribute. 58 59 Method: CcInfoSubject.system_includes 60 """ 61 return subjects.collection( 62 self.actual.compilation_context.system_includes, 63 meta = self.meta.derive("system_includes()"), 64 ) 65 66def _cc_info_subject_headers(self): 67 """Returns a `CollectionSubject` for the `headers` attribute. 68 69 Method: CcInfoSubject.headers 70 """ 71 return subjects.depset_file( 72 self.actual.compilation_context.headers, 73 meta = self.meta.derive("headers()"), 74 ) 75