1# Copyright (C) 2022 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 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 15load("@bazel_skylib//lib:paths.bzl", "paths") 16 17HidlInfo = provider(fields = [ 18 "srcs", 19 "transitive_srcs", 20 "transitive_roots", 21 "transitive_root_interface_files", 22 "fq_name", 23 "root", 24 "root_interface_file", 25]) 26 27def _hidl_library_rule_impl(ctx): 28 transitive_srcs = [] 29 transitive_root_interface_files = [] 30 transitive_roots = [] 31 32 for dep in ctx.attr.deps: 33 transitive_srcs.append(dep[HidlInfo].transitive_srcs) 34 transitive_root_interface_files.append(dep[HidlInfo].transitive_root_interface_files) 35 transitive_roots.append(dep[HidlInfo].transitive_roots) 36 37 root_interface_path = ctx.file.root_interface_file.path 38 return [ 39 DefaultInfo(files = depset(ctx.files.srcs)), 40 HidlInfo( 41 srcs = depset(ctx.files.srcs), 42 transitive_srcs = depset( 43 direct = ctx.files.srcs, 44 transitive = transitive_srcs, 45 ), 46 # These transitive roots will be used as -r arguments later when calling 47 # hidl-gen, for example, -r android.hardware:hardware/interfaces 48 transitive_roots = depset( 49 direct = [ctx.attr.root + ":" + paths.dirname(root_interface_path)], 50 transitive = transitive_roots, 51 ), 52 transitive_root_interface_files = depset( 53 direct = [ctx.file.root_interface_file], 54 transitive = transitive_root_interface_files, 55 ), 56 fq_name = ctx.attr.fq_name, 57 root = ctx.attr.root, 58 root_interface_file = ctx.attr.root_interface_file, 59 ), 60 ] 61 62hidl_library = rule( 63 implementation = _hidl_library_rule_impl, 64 attrs = { 65 "srcs": attr.label_list( 66 allow_files = [".hal"], 67 ), 68 "deps": attr.label_list( 69 providers = [HidlInfo], 70 doc = "hidl_interface targets that this one depends on", 71 ), 72 "fq_name": attr.string(), 73 "root": attr.string(), 74 "root_interface_file": attr.label(allow_single_file = ["current.txt"]), 75 }, 76 provides = [HidlInfo], 77) 78