1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Implementation of pw_cc_action_files.""" 15 16load( 17 ":providers.bzl", 18 "PwActionNameSetInfo", 19 "PwExtraActionFilesInfo", 20 "PwExtraActionFilesSetInfo", 21) 22 23def _pw_cc_action_files_impl(ctx): 24 actions = depset(transitive = [ 25 action[PwActionNameSetInfo].actions 26 for action in ctx.attr.actions 27 ]).to_list() 28 files = depset(ctx.files.srcs) 29 return [ 30 PwExtraActionFilesSetInfo(srcs = depset([ 31 PwExtraActionFilesInfo(action = action, files = files) 32 for action in actions 33 ])), 34 DefaultInfo(files = files), 35 ] 36 37pw_cc_action_files = rule( 38 implementation = _pw_cc_action_files_impl, 39 attrs = { 40 "actions": attr.label_list( 41 providers = [PwActionNameSetInfo], 42 mandatory = True, 43 doc = "The actions that the files are required for", 44 ), 45 "srcs": attr.label_list( 46 allow_files = True, 47 doc = "Files required for these actions to correctly operate.", 48 ), 49 }, 50 provides = [PwExtraActionFilesSetInfo], 51) 52 53def _pw_cc_action_files_set_impl(ctx): 54 return [ 55 PwExtraActionFilesSetInfo(srcs = depset(transitive = [ 56 ffa[PwExtraActionFilesSetInfo].srcs 57 for ffa in ctx.attr.srcs 58 ])), 59 DefaultInfo(files = depset(transitive = [ 60 src[DefaultInfo].files 61 for src in ctx.attr.srcs 62 ])), 63 ] 64 65pw_cc_action_files_set = rule( 66 implementation = _pw_cc_action_files_set_impl, 67 attrs = { 68 "srcs": attr.label_list( 69 providers = [PwExtraActionFilesSetInfo], 70 doc = "The pw_cc_action_files to combine.", 71 ), 72 }, 73 provides = [PwExtraActionFilesSetInfo], 74) 75