Skip to content

Commit

Permalink
Remove internal references from kythe service
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 606148312
  • Loading branch information
Googler authored and copybara-github committed Feb 12, 2024
1 parent e6e68f5 commit c256527
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 29 deletions.
18 changes: 13 additions & 5 deletions build_defs/intellij_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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,
)
Expand Down
29 changes: 28 additions & 1 deletion build_defs/restrictions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)

Expand Down Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions kotlin/BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
load(
"//:build-visibility.bzl",
"ASWB_SUBPACKAGES_VISIBILITY",
"KOTLIN_PACKAGE_VISIBILITY",
"PLUGIN_PACKAGES_VISIBILITY",
)
load(
"//build_defs:build_defs.bzl",
"intellij_plugin",
"intellij_plugin_library",
"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"])
Expand Down
8 changes: 4 additions & 4 deletions plugin_dev/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load(
"//:build-visibility.bzl",
"PLUGIN_PACKAGES_VISIBILITY",
)
load(
"//build_defs:build_defs.bzl",
"intellij_plugin",
Expand All @@ -9,10 +13,6 @@ load(
"//testing:test_defs.bzl",
"intellij_integration_test_suite",
)
load(
"//:build-visibility.bzl",
"PLUGIN_PACKAGES_VISIBILITY",
)

licenses(["notice"])

Expand Down
13 changes: 7 additions & 6 deletions proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
load(
"//:build-visibility.bzl",
"ASPECT_PROTO_VISIBILITY",
"PLUGIN_PACKAGES_VISIBILITY",
"create_proto_visibility_group",
)

#
# Description:
# Proto dependencies from bazel.
Expand All @@ -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"])

Expand Down
2 changes: 1 addition & 1 deletion skylark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
8 changes: 4 additions & 4 deletions terminal/BUILD
Original file line number Diff line number Diff line change
@@ -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"])

Expand Down

0 comments on commit c256527

Please sign in to comment.