diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-22 02:25:36 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-22 02:25:36 +0000 |
commit | 8febd412314bf79b61b579c9ec85ca906f9c8993 (patch) | |
tree | 74393ec5dcc68491e5308c0f4d3bdc3fa1f58fcb | |
parent | 1abbf68fa1408aa94ba6548292dc06757e67075d (diff) | |
parent | a3e70cd4777fad3f42f63cddce76ae45b69061ac (diff) | |
download | bazel-8febd412314bf79b61b579c9ec85ca906f9c8993.tar.gz |
Snap for 8485504 from c7d5439fbb542949f0f44fbc825f3dd48ce344ff to tm-release am: a3e70cd477
Original change: https://googleplex-android-review.googlesource.com/c/platform/build/bazel/+/17893773
Change-Id: I4c0e926741599a981218029ac8058e560ab4988a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | rules/apex.bzl | 19 | ||||
-rw-r--r-- | rules/prebuilt_etc.bzl | 65 | ||||
-rw-r--r-- | rules/prebuilt_file.bzl | 89 |
3 files changed, 95 insertions, 78 deletions
diff --git a/rules/apex.bzl b/rules/apex.bzl index ed514bd9..e5fc11ef 100644 --- a/rules/apex.bzl +++ b/rules/apex.bzl @@ -15,7 +15,7 @@ limitations under the License. """ load(":apex_key.bzl", "ApexKeyInfo") -load(":prebuilt_etc.bzl", "PrebuiltEtcInfo") +load(":prebuilt_file.bzl", "PrebuiltFileInfo") load(":sh_binary.bzl", "ShBinaryInfo") load("//build/bazel/rules/cc:stripped_cc_common.bzl", "StrippedCcBinaryInfo") load("//build/bazel/rules/android:android_app_certificate.bzl", "AndroidAppCertificateInfo") @@ -52,19 +52,12 @@ def _prepare_apexer_wrapper_inputs(ctx): # Handle prebuilts for dep in ctx.attr.prebuilts: - # TODO: Support more prebuilts than just PrebuiltEtc - prebuilt_etc_info = dep[PrebuiltEtcInfo] - - directory = "etc" - if prebuilt_etc_info.sub_dir != None and prebuilt_etc_info.sub_dir != "": - directory = "/".join([directory, prebuilt_etc_info.sub_dir]) - - if prebuilt_etc_info.filename != None and prebuilt_etc_info.filename != "": - filename = prebuilt_etc_info.filename + prebuilt_file_info = dep[PrebuiltFileInfo] + if prebuilt_file_info.filename: + filename = prebuilt_file_info.filename else: filename = dep.label.name - - apex_manifest[(directory, filename)] = prebuilt_etc_info.src + apex_manifest[(prebuilt_file_info.dir, filename)] = prebuilt_file_info.src # Handle binaries for dep in ctx.attr.binaries: @@ -350,7 +343,7 @@ _apex = rule( ], cfg = apex_transition, ), - "prebuilts": attr.label_list(providers = [PrebuiltEtcInfo], cfg = apex_transition), + "prebuilts": attr.label_list(providers = [PrebuiltFileInfo], cfg = apex_transition), "apex_output": attr.output(doc = "signed .apex output"), "capex_output": attr.output(doc = "signed .capex output"), diff --git a/rules/prebuilt_etc.bzl b/rules/prebuilt_etc.bzl deleted file mode 100644 index 7fa93b08..00000000 --- a/rules/prebuilt_etc.bzl +++ /dev/null @@ -1,65 +0,0 @@ -""" -Copyright (C) 2021 The Android Open Source Project - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -""" - -PrebuiltEtcInfo = provider( - "Info needed for prebuilt_etc modules", - fields = { - "src": "Source file of this prebuilt", - "sub_dir": "Optional subdirectory to install into", - "filename": "Optional name for the installed file", - "installable": "Whether this is directly installable into one of the partitions", - }, -) - -def _prebuilt_etc_rule_impl(ctx): - return [ - PrebuiltEtcInfo( - src = ctx.file.src, - sub_dir = ctx.attr.sub_dir, - filename = ctx.attr.filename, - installable = ctx.attr.installable, - ), - ] - -_prebuilt_etc = rule( - implementation = _prebuilt_etc_rule_impl, - attrs = { - "src": attr.label(mandatory = True, allow_single_file = True), - "sub_dir": attr.string(), - "filename": attr.string(), - "installable": attr.bool(default = True), - }, -) - -def prebuilt_etc( - name, - src, - sub_dir = None, - filename = None, - installable = True, - # TODO(b/207489266): Fully support; data is currently simply dropped to prevent breakages. - data = [], - **kwargs): - "Bazel macro to correspond with the prebuilt_etc Soong module." - - _prebuilt_etc( - name = name, - src = src, - sub_dir = sub_dir, - filename = filename, - installable = installable, - **kwargs - ) diff --git a/rules/prebuilt_file.bzl b/rules/prebuilt_file.bzl new file mode 100644 index 00000000..12e69824 --- /dev/null +++ b/rules/prebuilt_file.bzl @@ -0,0 +1,89 @@ +""" +Copyright (C) 2021 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +PrebuiltFileInfo = provider( + "Info needed for prebuilt_file modules", + fields = { + "src": "Source file of this prebuilt", + "dir": "Directory into which to install", + "filename": "Optional name for the installed file", + "installable": "Whether this is directly installable into one of the partitions", + }, +) +_handled_dirs = ["etc", "usr/share"] + +def _prebuilt_file_rule_impl(ctx): + srcs = ctx.files.src + if len(srcs) != 1: + fail("src for", ctx.label.name, "is expected to be singular, but is of len", len(srcs), ":\n", srcs) + + # Is this an acceptable directory, or a subdir under one? + dir = ctx.attr.dir + acceptable = False + for d in _handled_dirs: + if dir == d or dir.startswith(d + "/"): + acceptable = True + break + if not acceptable: + fail("dir for", ctx.label.name, "is `", dir, "`, but we only handle these:\n", _handled_dirs) + + return [ + PrebuiltFileInfo( + src = srcs[0], + dir = dir, + filename = ctx.attr.filename, + installable = ctx.attr.installable, + ), + DefaultInfo( + files = depset(srcs), + ), + ] + +_prebuilt_file = rule( + implementation = _prebuilt_file_rule_impl, + attrs = { + "src": attr.label( + mandatory = True, + allow_files = True, + # TODO(b/217908237): reenable allow_single_file + # allow_single_file = True, + ), + "dir": attr.string(mandatory = True), + "filename": attr.string(), + "installable": attr.bool(default = True), + }, +) + +def prebuilt_file( + name, + src, + dir, + filename = None, + installable = True, + # TODO(b/207489266): Fully support; + # data is currently dropped to prevent breakages from e.g. prebuilt_etc + data = [], + **kwargs): + "Bazel macro to correspond with the e.g. prebuilt_etc and prebuilt_usr_share Soong modules." + + _prebuilt_file( + name = name, + src = src, + dir = dir, + filename = filename, + installable = installable, + **kwargs + ) |