Skip to content

Commit 86e45c3

Browse files
nektos/actgithub-actions[bot]
authored andcommitted
Protobuf schema change detected
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 17c1028 commit 86e45c3

22 files changed

Lines changed: 3896 additions & 126 deletions

.bazelbsp/.bazelproject

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This project view file may be overwritten by the Bazel plugin.
2+
# To use it as default, place it in the Bazel module or workspace root directory.
3+
# For more options, see project view file documentation: https://www.jetbrains.com/help/idea/bazel-project-view.html
4+
5+
derive_targets_from_directories: true
6+
directories: .
7+
8+
# Uncomment these lines to make indexing quicker:
9+
# import_depth: 0
10+
# import_ijars: true

.bazelbsp/BUILD

Whitespace-only changes.

.bazelbsp/WORKSPACE

Whitespace-only changes.

.bazelbsp/aspects/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
filegroup(
2+
name = "aspects",
3+
srcs = glob(["**"]),
4+
visibility = ["//visibility:public"],
5+
)
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Copyright 2019-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
3+
load("//aspects:extensions.bzl", "EXTENSIONS", "TOOLCHAINS")
4+
load("//aspects:utils/utils.bzl", "ALL_DEPS", "COMPILE_DEPS", "PRIVATE_COMPILE_DEPS", "RUNTIME_DEPS", "abs", "collect_targets_from_attrs", "create_struct", "file_location", "get_aspect_ids", "update_sync_output_groups")
5+
load("//aspects:rules/java/java_info.bzl", "java_info_in_target", "java_info_reference")
6+
7+
def create_all_extension_info(target, ctx, output_groups, dep_targets):
8+
all_info = [create_extension_info(target = target, ctx = ctx, output_groups = output_groups, dep_targets = dep_targets) for create_extension_info in EXTENSIONS]
9+
return [(info, exported_properties) for info, exported_properties in all_info if info != None]
10+
11+
COMPILE = 0
12+
RUNTIME = 1
13+
14+
def make_dep(dep, dependency_type):
15+
return struct(
16+
id = str(dep.bsp_info.id),
17+
dependency_type = dependency_type,
18+
)
19+
20+
def make_deps(deps, dependency_type):
21+
return [make_dep(dep, dependency_type) for dep in deps]
22+
23+
def _is_proto_library_wrapper(target, ctx):
24+
if not ctx.rule.kind.endswith("proto_library") or ctx.rule.kind == "proto_library":
25+
return False
26+
27+
deps = collect_targets_from_attrs(ctx.rule.attr, ["deps"])
28+
return len(deps) == 1 and deps[0].bsp_info and deps[0].bsp_info.kind == "proto_library"
29+
30+
def _get_forwarded_deps(target, ctx):
31+
if _is_proto_library_wrapper(target, ctx):
32+
return collect_targets_from_attrs(ctx.rule.attr, ["deps"])
33+
return []
34+
35+
def _is_analysis_test(target):
36+
"""Returns if the target is an analysis test.
37+
38+
Rules created with analysis_test=True cannot create write actions, so the
39+
aspect should skip them.
40+
"""
41+
return AnalysisTestResultInfo in target
42+
43+
def files_to_list(source):
44+
if not hasattr(source, "files"):
45+
return []
46+
return source.files.to_list()
47+
48+
def _bsp_target_info_aspect_impl(target, ctx):
49+
if target.label.name.endswith(".semanticdb") or _is_analysis_test(target):
50+
return []
51+
52+
rule_attrs = ctx.rule.attr
53+
rule_kind = ctx.rule.kind
54+
55+
direct_dep_targets = collect_targets_from_attrs(rule_attrs, COMPILE_DEPS)
56+
private_direct_dep_targets = collect_targets_from_attrs(rule_attrs, PRIVATE_COMPILE_DEPS)
57+
direct_deps = make_deps(direct_dep_targets, COMPILE)
58+
59+
exported_deps_from_deps = []
60+
if ${isPropagateExportsFromDepsEnabled}:
61+
for dep in direct_dep_targets:
62+
exported_deps_from_deps = exported_deps_from_deps + dep.bsp_info.export_deps
63+
64+
compile_deps = direct_deps + exported_deps_from_deps
65+
66+
runtime_dep_targets = collect_targets_from_attrs(rule_attrs, RUNTIME_DEPS)
67+
runtime_deps = make_deps(runtime_dep_targets, RUNTIME)
68+
69+
all_deps = depset(compile_deps + runtime_deps).to_list()
70+
71+
# Propagate my own exports
72+
export_deps = []
73+
direct_exports = []
74+
if java_info_in_target(target):
75+
direct_exports = collect_targets_from_attrs(rule_attrs, ["exports"])
76+
export_deps.extend(make_deps(direct_exports, COMPILE))
77+
for export in direct_exports:
78+
export_deps.extend(export.bsp_info.export_deps)
79+
export_deps = depset(export_deps).to_list()
80+
81+
forwarded_deps = _get_forwarded_deps(target, ctx) + direct_exports
82+
83+
dep_targets = direct_dep_targets + private_direct_dep_targets + runtime_dep_targets + direct_exports
84+
output_groups = dict()
85+
for dep in dep_targets:
86+
for k, v in dep.bsp_info.output_groups.items():
87+
output_groups[k] = output_groups[k] + [v] if k in output_groups else [v]
88+
89+
for k, v in output_groups.items():
90+
output_groups[k] = depset(transitive = v)
91+
92+
srcs_attr = getattr(ctx.rule.attr, "srcs", [])
93+
sources = []
94+
generated_sources = []
95+
96+
if type(srcs_attr) == "list":
97+
all_sources = [
98+
file_location(f)
99+
for t in srcs_attr
100+
for f in files_to_list(t)
101+
if not f.is_directory
102+
]
103+
104+
sources = [
105+
s
106+
for s in all_sources
107+
if s.is_source
108+
]
109+
110+
generated_sources = [
111+
s
112+
for s in all_sources
113+
if not s.is_source
114+
]
115+
116+
resources_attr = getattr(ctx.rule.attr, "resources", [])
117+
resources = []
118+
119+
if type(resources_attr) == "list":
120+
resources = [
121+
file_location(f)
122+
for t in resources_attr
123+
for f in files_to_list(t)
124+
]
125+
126+
aspect_ids = get_aspect_ids(ctx, target)
127+
128+
default_info = target[DefaultInfo]
129+
executable = default_info and default_info.files_to_run.executable != None
130+
131+
env = getattr(rule_attrs, "env", {})
132+
if type(env) == "Target":
133+
env = str(env.label)
134+
135+
info = dict(
136+
id = str(target.label),
137+
kind = rule_kind,
138+
tags = rule_attrs.tags,
139+
dependencies = list(all_deps),
140+
sources = sources,
141+
generated_sources = generated_sources,
142+
resources = resources,
143+
env = env,
144+
env_inherit = getattr(rule_attrs, "env_inherit", []),
145+
executable = executable,
146+
)
147+
148+
exported_properties = dict(
149+
id = target.label,
150+
kind = rule_kind,
151+
export_deps = export_deps,
152+
output_groups = output_groups,
153+
)
154+
155+
all_extension_info = create_all_extension_info(target, ctx, output_groups, dep_targets)
156+
for (extension_info, extension_exported_properties) in all_extension_info:
157+
info.update(extension_info)
158+
if extension_exported_properties != None:
159+
exported_properties.update(extension_exported_properties)
160+
161+
file_name = target.label.name
162+
file_name = file_name + "-" + str(abs(hash(file_name)))
163+
if aspect_ids:
164+
file_name = file_name + "-" + str(abs(hash(".".join(aspect_ids))))
165+
file_name = "bsp.%s.bsp-info.textproto" % file_name
166+
info_file = ctx.actions.declare_file(file_name)
167+
ctx.actions.write(info_file, proto.encode_text(create_struct(**info)))
168+
update_sync_output_groups(output_groups, "bsp-target-info", depset([info_file]))
169+
170+
return struct(
171+
bsp_info = struct(**exported_properties),
172+
output_groups = output_groups,
173+
)
174+
175+
bsp_target_info_aspect = aspect(
176+
implementation = _bsp_target_info_aspect_impl,
177+
required_aspect_providers = [java_info_reference()],
178+
attr_aspects = ALL_DEPS,
179+
toolchains = TOOLCHAINS,
180+
fragments = ["cpp"]
181+
)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
load("//aspects:utils/utils.bzl", "create_file_location", "create_struct", "file_location")
2+
3+
ANDROID_SDK_TOOLCHAIN_TYPE = ${toolchainType}
4+
5+
def extract_android_info(target, ctx, dep_targets, **kwargs):
6+
if ANDROID_SDK_TOOLCHAIN_TYPE not in ctx.toolchains:
7+
return None, None
8+
android_sdk_toolchain = ctx.toolchains[ANDROID_SDK_TOOLCHAIN_TYPE]
9+
10+
if android_sdk_toolchain == None:
11+
return None, None
12+
android_sdk_info = android_sdk_toolchain.android_sdk_info
13+
if android_sdk_info == None:
14+
return None, None
15+
android_jar = file_location(android_sdk_info.android_jar)
16+
if android_jar == None:
17+
return None, None
18+
19+
manifest = None
20+
if hasattr(ctx.rule.attr, "manifest") and ctx.rule.attr.manifest:
21+
if type(ctx.rule.attr.manifest) == "depset":
22+
manifest_targets = ctx.rule.attr.manifest.to_list()
23+
if manifest_targets:
24+
manifest_target = manifest_targets[0]
25+
elif type(ctx.rule.attr.manifest) == "list" and ctx.rule.attr.manifest:
26+
manifest_target = ctx.rule.attr.manifest[0]
27+
else:
28+
manifest_target = ctx.rule.attr.manifest
29+
if type(manifest_target) == "Target":
30+
manifest_files = manifest_target.files.to_list()
31+
if manifest_files:
32+
manifest = file_location(manifest_files[0])
33+
else:
34+
manifest = file_location(manifest_target)
35+
36+
manifest_overrides = {}
37+
if hasattr(ctx.rule.attr, "manifest_values"):
38+
for key, value in ctx.rule.attr.manifest_values.items():
39+
if key != None and value != None:
40+
manifest_overrides[key] = value
41+
42+
resource_directories_set = {}
43+
if hasattr(ctx.rule.attr, "resource_files"):
44+
for resource in ctx.rule.attr.resource_files:
45+
for resource_file in resource.files.to_list():
46+
resource_file_location = file_location(resource_file)
47+
resource_source_dir_relative_path = android_common.resource_source_directory(resource_file)
48+
if resource_source_dir_relative_path == None:
49+
continue
50+
resource_source_dir_location = \
51+
set_relative_path(resource_file_location, resource_source_dir_relative_path)
52+
53+
# Add to set
54+
resource_directories_set[resource_source_dir_location] = None
55+
56+
resource_java_package = None
57+
if hasattr(ctx.rule.attr, "custom_package"):
58+
resource_java_package = ctx.rule.attr.custom_package
59+
60+
assets_directories = []
61+
if hasattr(ctx.rule.attr, "assets") and ctx.rule.attr.assets and \
62+
hasattr(ctx.rule.attr, "assets_dir") and ctx.rule.attr.assets_dir:
63+
first_asset_files = ctx.rule.attr.assets[0].files.to_list()
64+
if first_asset_files:
65+
first_asset = first_asset_files[0]
66+
first_asset_location = file_location(first_asset)
67+
asset_folder_relative_path = ctx.label.package + "/" + ctx.rule.attr.assets_dir
68+
asset_folder_location = set_relative_path(first_asset_location, asset_folder_relative_path)
69+
assets_directories.append(asset_folder_location)
70+
71+
aidl_binary_jar = None
72+
aidl_source_jar = None
73+
apk = None
74+
if AndroidIdeInfo in target:
75+
android_ide_info = target[AndroidIdeInfo]
76+
if android_ide_info.idl_class_jar:
77+
aidl_binary_jar = file_location(android_ide_info.idl_class_jar)
78+
if android_ide_info.idl_source_jar:
79+
aidl_source_jar = file_location(android_ide_info.idl_source_jar)
80+
if android_ide_info.signed_apk:
81+
apk = file_location(android_ide_info.signed_apk)
82+
83+
android_target_info = create_struct(
84+
android_jar = android_jar,
85+
manifest = manifest,
86+
manifest_overrides = manifest_overrides,
87+
resource_directories = resource_directories_set.keys(),
88+
resource_java_package = resource_java_package,
89+
assets_directories = assets_directories,
90+
aidl_binary_jar = aidl_binary_jar,
91+
aidl_source_jar = aidl_source_jar,
92+
apk = apk,
93+
)
94+
95+
return dict(android_target_info = android_target_info), None
96+
97+
def set_relative_path(location, new_relative_path):
98+
return create_file_location(
99+
relative_path = new_relative_path,
100+
is_source = location.is_source,
101+
is_external = location.is_external,
102+
root_execution_path_fragment = location.root_execution_path_fragment,
103+
)
104+
105+
def extract_android_aar_import_info(target, ctx, dep_targets, **kwargs):
106+
if ctx.rule.kind != "aar_import":
107+
return None, None
108+
109+
if AndroidManifestInfo not in target:
110+
return None, None
111+
manifest = file_location(target[AndroidManifestInfo].manifest)
112+
113+
resource_folder = None
114+
r_txt = None
115+
if AndroidResourcesInfo in target:
116+
direct_android_resources = target[AndroidResourcesInfo].direct_android_resources.to_list()
117+
if direct_android_resources:
118+
direct_android_resource = direct_android_resources[0]
119+
resource_files = direct_android_resource.resources
120+
if resource_files:
121+
resource_folder = file_location(resource_files[0])
122+
r_txt = file_location(direct_android_resource.r_txt)
123+
124+
android_aar_import_info = create_struct(
125+
manifest = manifest,
126+
resource_folder = resource_folder,
127+
r_txt = r_txt,
128+
)
129+
return dict(android_aar_import_info = android_aar_import_info), None

0 commit comments

Comments
 (0)