Internal change PiperOrigin-RevId: 874441487 Change-Id: Id054a171e3f5f2e8a477353c16bf2cc1ff8b8c3a
diff --git a/java/common/rules/impl/bazel_java_import_impl.bzl b/java/common/rules/impl/bazel_java_import_impl.bzl index 2a107a1..c402fc4 100644 --- a/java/common/rules/impl/bazel_java_import_impl.bzl +++ b/java/common/rules/impl/bazel_java_import_impl.bzl
@@ -63,11 +63,10 @@ return file_dict -def _check_export_error(ctx, exports): - not_in_allowlist = hasattr(ctx.attr, "_allowlist_java_import_exports") and not getattr(ctx.attr, "_allowlist_java_import_exports")[PackageSpecificationInfo].contains(ctx.label) +def _check_export_error(ctx, exports, permit_exports): disallow_java_import_exports = ctx.fragments.java.disallow_java_import_exports() - if len(exports) != 0 and (disallow_java_import_exports or not_in_allowlist): + if len(exports) != 0 and (disallow_java_import_exports or not permit_exports): fail("java_import.exports is no longer supported; use java_import.deps instead") def _check_empty_jars_error(ctx, jars): @@ -84,7 +83,9 @@ neverlink = False, proguard_specs = [], add_exports = [], - add_opens = []): + add_opens = [], + permit_exports = True, + skip_incomplete_deps_check = True): """Implements java_import. This rule allows the use of precompiled .jar files as libraries in other Java rules. @@ -100,6 +101,8 @@ proguard_specs: (list[File]) Files to be used as Proguard specification. add_exports: (list[str]) Allow this library to access the given <module>/<package>. add_opens: (list[str]) Allow this library to reflectively access the given <module>/<package>. + permit_exports: (bool) Allow using exports + skip_incomplete_deps_check: (bool) If this target is allowed to have incomplete deps Returns: (list[provider]) A list containing DefaultInfo, JavaInfo, @@ -107,15 +110,14 @@ """ _check_empty_jars_error(ctx, jars) - _check_export_error(ctx, exports) + _check_export_error(ctx, exports, permit_exports) collected_jars = _collect_jars(ctx, jars) all_deps = _filter_provider(JavaInfo, deps, exports) jdeps_artifact = None merged_java_info = java_common.merge(all_deps) - not_in_allowlist = hasattr(ctx.attr, "_allowlist_java_import_deps_checking") and not ctx.attr._allowlist_java_import_deps_checking[PackageSpecificationInfo].contains(ctx.label) - if not_in_allowlist and "incomplete-deps" not in ctx.attr.tags: + if not skip_incomplete_deps_check and "incomplete-deps" not in ctx.attr.tags: jdeps_artifact = import_deps_check( ctx, collected_jars,