Skip to content

Commit

Permalink
Add a helper method to create DependenciesInfo.
Browse files Browse the repository at this point in the history
The provider now has more fields in it, and all of them are optional dependant on the context. Move the definition of the default values to a helper method to allow the codepaths that create it to only provide the values relevant to them.

PiperOrigin-RevId: 578475132
  • Loading branch information
Googler authored and copybara-github committed Nov 1, 2023
1 parent f8c3614 commit 32783ff
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions aspect/build_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ DependenciesInfo = provider(
},
)

def create_dependencies_info(
compile_time_jars = depset(),
target_to_artifacts = {},
aars = depset(),
gensrcs = depset(),
test_mode_own_files = None,
cc_info = None,
cc_headers = depset(),
cc_toolchain_info = None):
"""A helper function to create a DependenciesInfo provider instance."""
return DependenciesInfo(
compile_time_jars = compile_time_jars,
target_to_artifacts = target_to_artifacts,
aars = aars,
gensrcs = gensrcs,
test_mode_own_files = test_mode_own_files,
cc_info = cc_info,
cc_headers = cc_headers,
cc_toolchain_info = cc_toolchain_info,
)

def _encode_target_info_proto(target_to_artifacts):
contents = []
for label, target_info in target_to_artifacts.items():
Expand Down Expand Up @@ -432,15 +453,12 @@ def _collect_java_dependencies_core_impl(
)

return [
DependenciesInfo(
create_dependencies_info(
target_to_artifacts = target_to_artifacts,
compile_time_jars = compile_jars,
aars = aars,
gensrcs = gensrcs,
test_mode_own_files = test_mode_own_files,
cc_info = None,
cc_headers = depset(),
cc_toolchain_info = None,
),
]

Expand All @@ -449,12 +467,7 @@ def _collect_cc_dependencies_core_impl(target, ctx):

cc_info = _collect_own_and_dependency_cc_info(target, dependency_info)

return DependenciesInfo(
target_to_artifacts = {},
compile_time_jars = depset(),
aars = depset(),
gensrcs = depset(),
test_mode_own_files = None,
return create_dependencies_info(
cc_info = cc_info.compilation_info,
cc_headers = cc_info.gen_headers,
cc_toolchain_info = cc_info.cc_toolchain_info,
Expand Down Expand Up @@ -525,14 +538,7 @@ def _collect_cc_toolchain_info(target, ctx):
),
)

return DependenciesInfo(
target_to_artifacts = {},
compile_time_jars = depset(),
aars = depset(),
gensrcs = depset(),
test_mode_own_files = None,
cc_info = None,
cc_headers = depset(),
return create_dependencies_info(
cc_toolchain_info = struct(file = cc_toolchain_file, id = toolchain_id),
)

Expand Down

0 comments on commit 32783ff

Please sign in to comment.