Skip to content

Commit

Permalink
Write used-jars.json for kotlin/java builds
Browse files Browse the repository at this point in the history
Summary:
- used-classes.json files are used to remove unused dependencies from android/java/kotlin targets
- However, as [suggested](https://www.internalfb.com/diff/D66472678?dst_version_fbid=843546227744657&transaction_fbid=1102626487937834) by navidqar exposing them through providers isn't ideal because their format isn't guaranteed.
- As a solution this diff adds a new output to kotlincd_jar and javacd_jar actions - used-jars.json, which will then be exposed through Providers for further processing

Reviewed By: navidqar

Differential Revision: D68231809

fbshipit-source-id: c664bfc2c6ab3f72204858e1bd477869f968a051
  • Loading branch information
Arsen Tumanyan authored and facebook-github-bot committed Jan 17, 2025
1 parent ddf17fa commit 1af3758
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prelude/java/javacd_jar_creator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,15 @@ def _define_javacd_action(
elif compiling_deps_tset:
abi_to_abi_dir_map = compiling_deps_tset.project_as_args("abi_to_abi_dir")
used_classes_json_outputs = [output_paths.jar_parent.project("used-classes.json")]
used_jars_json_output = output_paths.jar_parent.project("used-jars.json")
args = setup_dep_files(
actions,
actions_identifier,
args,
post_build_params,
classpath_jars_tag,
used_classes_json_outputs,
used_jars_json_output,
abi_to_abi_dir_map,
hidden = hidden,
)
Expand Down
2 changes: 2 additions & 0 deletions prelude/jvm/cd_jar_creator_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def setup_dep_files(
post_build_params: dict,
classpath_jars_tag: ArtifactTag,
used_classes_json_outputs: list[Artifact],
used_jars_json_output: Artifact,
abi_to_abi_dir_map: [TransitiveSetArgsProjection, list[cmd_args], None],
hidden = ["artifact"]) -> cmd_args:
dep_file = declare_prefixed_output(actions, actions_identifier, "dep_file.txt")
Expand All @@ -357,6 +358,7 @@ def setup_dep_files(
for used_classes_json in used_classes_json_outputs
]
post_build_params["depFile"] = classpath_jars_tag.tag_artifacts(dep_file.as_output())
post_build_params["usedJarsFile"] = used_jars_json_output.as_output()

if abi_to_abi_dir_map:
abi_to_abi_dir_map_file = declare_prefixed_output(actions, actions_identifier, "abi_to_abi_dir_map")
Expand Down
2 changes: 2 additions & 0 deletions prelude/kotlin/kotlincd_jar_creator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,15 @@ def _define_kotlincd_action(
output_paths.jar_parent.project("used-classes.json"),
output_paths.jar_parent.project("kotlin-used-classes.json"),
]
used_jars_json_output = output_paths.jar_parent.project("used-jars.json")
args = setup_dep_files(
actions,
actions_identifier,
args,
post_build_params,
classpath_jars_tag,
used_classes_json_outputs,
used_jars_json_output,
compiling_deps_tset.project_as_args("abi_to_abi_dir") if kotlin_toolchain.dep_files == DepFiles("per_class") and compiling_deps_tset else None,
)

Expand Down

0 comments on commit 1af3758

Please sign in to comment.