diff --git a/build_defs/intellij_plugin.bzl b/build_defs/intellij_plugin.bzl index 55e23ef4a56..23aa81939c5 100644 --- a/build_defs/intellij_plugin.bzl +++ b/build_defs/intellij_plugin.bzl @@ -41,11 +41,12 @@ load( "//build_defs:restrictions.bzl", "ALLOWED_EXTERNAL_DEPENDENCIES", "EXISTING_EXTERNAL_VIOLATIONS", + "EXISTING_UNCHECKED", "RestrictedInfo", "restricted_deps_aspect", "validate_restrictions", + "validate_unchecked_internal", ) -load("//intellij_platform_sdk:build_defs.bzl", "select_for_ide") _OptionalPluginXmlInfo = provider(fields = ["optional_plugin_xmls"]) @@ -226,10 +227,14 @@ def _intellij_plugin_jar_impl(ctx): if ctx.attr.restrict_deps: dependencies = {} + unchecked_transitive = [] for k in ctx.attr.restricted_deps: if RestrictedInfo in k: dependencies.update(k[RestrictedInfo].dependencies) + unchecked_transitive.append(k[RestrictedInfo].unchecked) validate_restrictions(dependencies, ctx.attr.allowed_external_dependencies, ctx.attr.existing_external_violations) + unchecked = [str(t.label) for t in depset(direct = [], transitive = unchecked_transitive).to_list()] + validate_unchecked_internal(unchecked, ctx.attr.existing_unchecked) return DefaultInfo( files = files, @@ -245,6 +250,7 @@ _intellij_plugin_jar = rule( "deps": attr.label_list(providers = [[_IntellijPluginLibraryInfo]]), "allowed_external_dependencies": attr.string_list(), "existing_external_violations": attr.string_list(), + "existing_unchecked": attr.string_list(), "restrict_deps": attr.bool(), "restricted_deps": attr.label_list(aspects = [restricted_deps_aspect]), "plugin_icons": attr.label_list(allow_files = True), @@ -318,14 +324,16 @@ def intellij_plugin(name, deps, plugin_xml, optional_plugin_xmls = [], jar_name deploy_jar = deploy_jar, jar_name = jar_name or (name + ".jar"), deps = deps, - restrict_deps = select_for_ide( - android_studio = restrict_deps, - default = False, - ), + restrict_deps = + select({ + "//intellij_platform_sdk:android-studio-intellij-ext": restrict_deps, + "//conditions:default": False, + }), restricted_deps = deps if restrict_deps else [], plugin_xml = plugin_xml, allowed_external_dependencies = ALLOWED_EXTERNAL_DEPENDENCIES, existing_external_violations = EXISTING_EXTERNAL_VIOLATIONS, + existing_unchecked = EXISTING_UNCHECKED, optional_plugin_xmls = optional_plugin_xmls, plugin_icons = plugin_icons, ) diff --git a/build_defs/restrictions.bzl b/build_defs/restrictions.bzl index 69ed44e94e8..4d688d8cc89 100644 --- a/build_defs/restrictions.bzl +++ b/build_defs/restrictions.bzl @@ -26,10 +26,14 @@ ALLOWED_EXTERNAL_DEPENDENCIES = [ EXISTING_EXTERNAL_VIOLATIONS = [ ] +EXISTING_UNCHECKED = [ +] + RestrictedInfo = provider( doc = "The dependencies, per target, outside the project", fields = { "dependencies": "A map from target to external dependencies", + "unchecked": "A list of targets that are still unchecked for guava internal APIs", }, ) @@ -60,18 +64,41 @@ def _restricted_deps_aspect_impl(target, ctx): if not _in_project(target): return [] + unchecked = [] + if ctx.rule.kind == "java_library": + if ctx.rule.attr.plugins: + labels = [t.label for t in ctx.rule.attr.plugins] + if (Label("//java/com/google/devtools/build/buildjar/plugin/annotations:google_internal_checker") not in labels): + unchecked.append(target) + else: + unchecked.append(target) + dependencies = {} + nested_unchecked = [] outside_project = [] for d in _get_deps(ctx): if not _in_project(d) and not _in_set(d, _valid): outside_project.append(d) if RestrictedInfo in d: dependencies.update(d[RestrictedInfo].dependencies) + nested_unchecked.append(d[RestrictedInfo].unchecked) if outside_project: dependencies[target] = outside_project - return [RestrictedInfo(dependencies = dependencies)] + return [RestrictedInfo(dependencies = dependencies, unchecked = depset(direct = unchecked, transitive = nested_unchecked))] + +# buildifier: disable=function-docstring +def validate_unchecked_internal(unchecked, existing_unchecked): + not_allowed_to_be_unchecked = [t for t in unchecked if t not in existing_unchecked] + checked_still_in_list = [t for t in existing_unchecked if t not in unchecked] + error = "" + if not_allowed_to_be_unchecked: + error += "The following targets do not have either google_internal_checker or beta_checker on:\n " + "\n ".join(not_allowed_to_be_unchecked) + "\n" + if checked_still_in_list: + error += "The following targets are checked but still in the EXISTING_UNCHECKED list:\n " + "\n ".join(checked_still_in_list) + "\n" + if error: + fail(error) # buildifier: disable=function-docstring def validate_restrictions(dependencies, allowed_external, existing_violations): diff --git a/kotlin/BUILD b/kotlin/BUILD index ec868686085..5ea11d1f599 100644 --- a/kotlin/BUILD +++ b/kotlin/BUILD @@ -1,3 +1,9 @@ +load( + "//:build-visibility.bzl", + "ASWB_SUBPACKAGES_VISIBILITY", + "KOTLIN_PACKAGE_VISIBILITY", + "PLUGIN_PACKAGES_VISIBILITY", +) load( "//build_defs:build_defs.bzl", "intellij_plugin", @@ -5,20 +11,14 @@ load( "optional_plugin_xml", "stamped_plugin_xml", ) -load( - "//intellij_platform_sdk:build_defs.bzl", - "combine_visibilities", -) load( "//testing:test_defs.bzl", "intellij_integration_test_suite", "intellij_unit_test_suite", ) load( - "//:build-visibility.bzl", - "ASWB_SUBPACKAGES_VISIBILITY", - "KOTLIN_PACKAGE_VISIBILITY", - "PLUGIN_PACKAGES_VISIBILITY", + "//intellij_platform_sdk:build_defs.bzl", + "combine_visibilities", ) licenses(["notice"]) diff --git a/plugin_dev/BUILD b/plugin_dev/BUILD index 730831e4a88..de8daca4eed 100644 --- a/plugin_dev/BUILD +++ b/plugin_dev/BUILD @@ -1,3 +1,7 @@ +load( + "//:build-visibility.bzl", + "PLUGIN_PACKAGES_VISIBILITY", +) load( "//build_defs:build_defs.bzl", "intellij_plugin", @@ -9,10 +13,6 @@ load( "//testing:test_defs.bzl", "intellij_integration_test_suite", ) -load( - "//:build-visibility.bzl", - "PLUGIN_PACKAGES_VISIBILITY", -) licenses(["notice"]) diff --git a/proto/BUILD b/proto/BUILD index 980e9912ead..4677de051e6 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -1,3 +1,10 @@ +load( + "//:build-visibility.bzl", + "ASPECT_PROTO_VISIBILITY", + "PLUGIN_PACKAGES_VISIBILITY", + "create_proto_visibility_group", +) + # # Description: # Proto dependencies from bazel. @@ -6,12 +13,6 @@ load( "//intellij_platform_sdk:build_defs.bzl", "combine_visibilities", ) -load( - "//:build-visibility.bzl", - "ASPECT_PROTO_VISIBILITY", - "PLUGIN_PACKAGES_VISIBILITY", - "create_proto_visibility_group", -) licenses(["notice"]) diff --git a/skylark/BUILD b/skylark/BUILD index 4ffb67488f2..ca976384f9f 100644 --- a/skylark/BUILD +++ b/skylark/BUILD @@ -2,12 +2,12 @@ # Description: A Skylark debugging client for IntelliJ. # -load("//build_defs:build_defs.bzl", "intellij_plugin_library") load( "//:build-visibility.bzl", "PLUGIN_PACKAGES_VISIBILITY", "SKYLARK_PACKAGES_VISIBILITY", ) +load("//build_defs:build_defs.bzl", "intellij_plugin_library") licenses(["notice"]) diff --git a/terminal/BUILD b/terminal/BUILD index 1a948522319..84230d5646d 100644 --- a/terminal/BUILD +++ b/terminal/BUILD @@ -1,12 +1,12 @@ +load( + "//:build-visibility.bzl", + "PLUGIN_PACKAGES_VISIBILITY", +) load( "//build_defs:build_defs.bzl", "intellij_plugin_library", "optional_plugin_xml", ) -load( - "//:build-visibility.bzl", - "PLUGIN_PACKAGES_VISIBILITY", -) licenses(["notice"])