-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an aspect to validate the transitive deps of an android_feature_m…
…odule. This is prework before we filter out all dexes to ensure users aren't confused. PiperOrigin-RevId: 684587452 Change-Id: Ie0b783725730ee17075120c52dc61f0ca0e60d40
- Loading branch information
1 parent
c0f424e
commit 559a915
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
rules/android_application/android_feature_module_validation_aspect.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# 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. | ||
|
||
"""Aspect to validate the transitive dependencies of an android_feature_module.""" | ||
_SRCS_DISALLOWED_EXTENSIONS = ["java", "kt", "srcjar"] | ||
|
||
_DISALLOWED_RULE_TYPES = ["java_import", "aar_import"] | ||
|
||
def _has_disallowed_srcs(srcs): | ||
if not srcs: | ||
return False | ||
for src in srcs: | ||
if src.extension in _SRCS_DISALLOWED_EXTENSIONS: | ||
return True | ||
return False | ||
|
||
def _impl(target, ctx): | ||
if ctx.rule.kind in _DISALLOWED_RULE_TYPES: | ||
fail("android_feature_module cannot transitively depend on {} rules".format(ctx.rule.kind)) | ||
srcs = getattr(ctx.rule.files, "srcs", []) | ||
if _has_disallowed_srcs(srcs): | ||
fail("android_feature_module cannot transitively depend on Java/Kotlin sources and {} has Java/Kotlin sources".format(target.label)) | ||
if getattr(ctx.rule.attr, "resource_files", False): | ||
fail("android_feature_module cannot transitively depend on resource_files and {} has resource_files".format(target.label)) | ||
return [] | ||
|
||
android_feature_module_validation_aspect = aspect( | ||
implementation = _impl, | ||
attr_aspects = ["deps", "exports"], | ||
doc = "An aspect that validates the dependencies of an android_feature_module.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters