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"""# DefaultInfoSubject""" 16 17load(":runfiles_subject.bzl", "RunfilesSubject") 18load(":depset_file_subject.bzl", "DepsetFileSubject") 19load(":file_subject.bzl", "FileSubject") 20 21def _default_info_subject_new(info, *, meta): 22 """Creates a `DefaultInfoSubject` 23 24 Args: 25 info: ([`DefaultInfo`]) the DefaultInfo object to wrap. 26 meta: ([`ExpectMeta`]) call chain information. 27 28 Returns: 29 [`DefaultInfoSubject`] object. 30 """ 31 self = struct(actual = info, meta = meta) 32 public = struct( 33 # keep sorted start 34 actual = info, 35 runfiles = lambda *a, **k: _default_info_subject_runfiles(self, *a, **k), 36 data_runfiles = lambda *a, **k: _default_info_subject_data_runfiles(self, *a, **k), 37 default_outputs = lambda *a, **k: _default_info_subject_default_outputs(self, *a, **k), 38 executable = lambda *a, **k: _default_info_subject_executable(self, *a, **k), 39 runfiles_manifest = lambda *a, **k: _default_info_subject_runfiles_manifest(self, *a, **k), 40 # keep sorted end 41 ) 42 return public 43 44def _default_info_subject_runfiles(self): 45 """Creates a subject for the default runfiles. 46 47 Args: 48 self: implicitly added. 49 50 Returns: 51 [`RunfilesSubject`] object 52 """ 53 return RunfilesSubject.new( 54 self.actual.default_runfiles, 55 meta = self.meta.derive("runfiles()"), 56 kind = "default", 57 ) 58 59def _default_info_subject_data_runfiles(self): 60 """Creates a subject for the data runfiles. 61 62 Args: 63 self: implicitly added. 64 65 Returns: 66 [`RunfilesSubject`] object 67 """ 68 return RunfilesSubject.new( 69 self.actual.data_runfiles, 70 meta = self.meta.derive("data_runfiles()"), 71 kind = "data", 72 ) 73 74def _default_info_subject_default_outputs(self): 75 """Creates a subject for the default outputs. 76 77 Args: 78 self: implicitly added. 79 80 Returns: 81 [`DepsetFileSubject`] object. 82 """ 83 return DepsetFileSubject.new( 84 self.actual.files, 85 meta = self.meta.derive("default_outputs()"), 86 ) 87 88def _default_info_subject_executable(self): 89 """Creates a subject for the executable file. 90 91 Args: 92 self: implicitly added. 93 94 Returns: 95 [`FileSubject`] object. 96 """ 97 return FileSubject.new( 98 self.actual.files_to_run.executable, 99 meta = self.meta.derive("executable()"), 100 ) 101 102def _default_info_subject_runfiles_manifest(self): 103 """Creates a subject for the runfiles manifest. 104 105 Args: 106 self: implicitly added. 107 108 Returns: 109 [`FileSubject`] object. 110 """ 111 return FileSubject.new( 112 self.actual.files_to_run.runfiles_manifest, 113 meta = self.meta.derive("runfiles_manifest()"), 114 ) 115 116# We use this name so it shows up nice in docs. 117# buildifier: disable=name-conventions 118DefaultInfoSubject = struct( 119 # keep sorted start 120 new = _default_info_subject_new, 121 runfiles = _default_info_subject_runfiles, 122 data_runfiles = _default_info_subject_data_runfiles, 123 default_outputs = _default_info_subject_default_outputs, 124 executable = _default_info_subject_executable, 125 runfiles_manifest = _default_info_subject_runfiles_manifest, 126 # keep sorted end 127) 128