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 17HidlPackageRoot = provider(fields = [ 18 "root", 19 "root_path", 20 "root_interface_file", 21]) 22 23def _hidl_package_rule_impl(ctx): 24 path = ctx.attr.path 25 if ctx.attr.path == ".": 26 path = paths.dirname(ctx.build_file_path) 27 current = ctx.file.current 28 currents = [] 29 if current: 30 currents.append(current) 31 return [ 32 DefaultInfo( 33 files = depset(direct = currents), 34 runfiles = ctx.runfiles(files = currents), 35 ), 36 HidlPackageRoot( 37 root = ctx.attr.name, 38 root_path = path, 39 root_interface_file = current, 40 ), 41 ] 42 43hidl_package_root = rule( 44 implementation = _hidl_package_rule_impl, 45 attrs = { 46 "path": attr.string(default = "."), 47 "current": attr.label(allow_single_file = ["current.txt"]), 48 }, 49) 50