diff --git a/prelude/java/java_library.bzl b/prelude/java/java_library.bzl index b92fe3291fc6..520eabfc606d 100644 --- a/prelude/java/java_library.bzl +++ b/prelude/java/java_library.bzl @@ -688,6 +688,7 @@ def build_java_library( sources_jar = sources_jar, gwt_module = gwt_output, preprocessed_library = outputs.preprocessed_library if outputs else None, + used_jars_json = outputs.used_jars_json if outputs else None, ) default_info = get_default_info( diff --git a/prelude/java/java_providers.bzl b/prelude/java/java_providers.bzl index 6c0098d213a4..fc896d109424 100644 --- a/prelude/java/java_providers.bzl +++ b/prelude/java/java_providers.bzl @@ -209,6 +209,7 @@ JavaLibraryIntellijInfo = provider( # If this library has a jar_postprocessor, this is the jar prior to post-processing. # Otherwise, it is the same as library_output in JavaLibraryInfo. "preprocessed_library": provider_field(typing.Any, default = None), # ["artifact", None] + "used_jars_json": provider_field(typing.Any, default = None), # ["artifact"] }, ) @@ -237,6 +238,7 @@ JavaCompileOutputs = record( annotation_processor_output = Artifact | None, preprocessed_library = Artifact, incremental_state_dir = Artifact | None, + used_jars_json = Artifact | None, ) JavaProviders = record( @@ -281,7 +283,8 @@ def make_compile_outputs( required_for_source_only_abi: bool = False, annotation_processor_output: Artifact | None = None, incremental_state_dir: Artifact | None = None, - abi_jar_snapshot: Artifact | None = None) -> JavaCompileOutputs: + abi_jar_snapshot: Artifact | None = None, + used_jars_json: Artifact | None = None) -> JavaCompileOutputs: expect(classpath_abi != None or classpath_abi_dir == None, "A classpath_abi_dir should only be provided if a classpath_abi is provided!") return JavaCompileOutputs( full_library = full_library, @@ -298,6 +301,7 @@ def make_compile_outputs( annotation_processor_output = annotation_processor_output, preprocessed_library = preprocessed_library, incremental_state_dir = incremental_state_dir, + used_jars_json = used_jars_json, ) def create_abi(actions: AnalysisActions, class_abi_generator: Dependency, library: Artifact) -> Artifact: @@ -636,7 +640,8 @@ def create_java_library_providers( proguard_config: Artifact | None = None, gwt_module: Artifact | None = None, lint_jar: Artifact | None = None, - preprocessed_library: Artifact | None = None) -> (JavaLibraryInfo, JavaPackagingInfo, JavaGlobalCodeInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph, TemplatePlaceholderInfo, JavaLibraryIntellijInfo): + preprocessed_library: Artifact | None = None, + used_jars_json: Artifact | None = None) -> (JavaLibraryInfo, JavaPackagingInfo, JavaGlobalCodeInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph, TemplatePlaceholderInfo, JavaLibraryIntellijInfo): first_order_classpath_deps = filter(None, [x.get(JavaLibraryInfo) for x in declared_deps + exported_deps + runtime_deps]) first_order_classpath_libs = [dep.output_for_classpath_macro for dep in first_order_classpath_deps] @@ -672,6 +677,7 @@ def create_java_library_providers( annotation_jars_dir = annotation_jars_dir, lint_jar = lint_jar, preprocessed_library = preprocessed_library, + used_jars_json = used_jars_json, ) return (library_info, packaging_info, global_code_info, shared_library_info, cxx_resource_info, linkable_graph, template_info, intellij_info) diff --git a/prelude/java/javacd_jar_creator.bzl b/prelude/java/javacd_jar_creator.bzl index 2e36ce50ea2d..27676362d90a 100644 --- a/prelude/java/javacd_jar_creator.bzl +++ b/prelude/java/javacd_jar_creator.bzl @@ -140,7 +140,7 @@ def create_jar_artifact_javacd( source_only_abi_compiling_deps = [], track_class_usage = track_class_usage, ) - define_javacd_action( + used_jars_json = define_javacd_action( category_prefix = "", actions_identifier = actions_identifier, encoded_command = command, @@ -196,6 +196,7 @@ def create_jar_artifact_javacd( required_for_source_only_abi = required_for_source_only_abi, annotation_processor_output = output_paths.annotations, abi_jar_snapshot = abi_jar_snapshot, + used_jars_json = used_jars_json, ) else: full_jar_snapshot = generate_java_classpath_snapshot(ctx.actions, java_toolchain.cp_snapshot_generator, ClasspathSnapshotGranularity("CLASS_MEMBER_LEVEL"), final_jar_output.final_jar, actions_identifier) @@ -205,6 +206,7 @@ def create_jar_artifact_javacd( required_for_source_only_abi = required_for_source_only_abi, annotation_processor_output = output_paths.annotations, abi_jar_snapshot = full_jar_snapshot, + used_jars_json = used_jars_json, ) return result @@ -298,6 +300,7 @@ def _define_javacd_action( post_build_params["abiOutputDir"] = abi_dir.as_output() dep_files = {} + used_jars_json_output = None if not is_creating_subtarget and srcs and (java_toolchain.dep_files == DepFiles("per_jar") or java_toolchain.dep_files == DepFiles("per_class")) and track_class_usage: abi_to_abi_dir_map = None hidden = [] @@ -354,3 +357,5 @@ def _define_javacd_action( weight = 2, error_handler = java_toolchain.java_error_handler, ) + + return used_jars_json_output diff --git a/prelude/kotlin/kotlin_library.bzl b/prelude/kotlin/kotlin_library.bzl index 581001c05bab..64ba69cbb3ff 100644 --- a/prelude/kotlin/kotlin_library.bzl +++ b/prelude/kotlin/kotlin_library.bzl @@ -481,6 +481,7 @@ def build_kotlin_library( has_srcs = bool(srcs), sources_jar = sources_jar, preprocessed_library = outputs.preprocessed_library if outputs else None, + used_jars_json = outputs.used_jars_json if outputs else None, ) default_info = get_default_info( diff --git a/prelude/kotlin/kotlincd_jar_creator.bzl b/prelude/kotlin/kotlincd_jar_creator.bzl index 7959f50d4349..ff2d1f648ed6 100644 --- a/prelude/kotlin/kotlincd_jar_creator.bzl +++ b/prelude/kotlin/kotlincd_jar_creator.bzl @@ -174,7 +174,7 @@ def create_jar_artifact_kotlincd( source_only_abi_compiling_deps = [], track_class_usage = track_class_usage, ) - proto = define_kotlincd_action( + proto, used_jars_json = define_kotlincd_action( category_prefix = "", actions_identifier = actions_identifier, encoded_command = command, @@ -249,6 +249,7 @@ def create_jar_artifact_kotlincd( annotation_processor_output = output_paths.annotations, incremental_state_dir = incremental_state_dir, abi_jar_snapshot = abi_jar_snapshot, + used_jars_json = used_jars_json, ), proto else: full_jar_snapshot = generate_java_classpath_snapshot(actions, java_toolchain.cp_snapshot_generator, ClasspathSnapshotGranularity("CLASS_MEMBER_LEVEL"), final_jar_output.final_jar, actions_identifier) @@ -258,6 +259,7 @@ def create_jar_artifact_kotlincd( required_for_source_only_abi = required_for_source_only_abi, annotation_processor_output = output_paths.annotations, abi_jar_snapshot = full_jar_snapshot, + used_jars_json = used_jars_json, ), proto def _encode_kotlin_extra_params( @@ -458,6 +460,7 @@ def _define_kotlincd_action( post_build_params["incrementalStateDir"] = incremental_state_dir.as_output() dep_files = {} + used_jars_json_output = None if not is_creating_subtarget and srcs and (kotlin_toolchain.dep_files == DepFiles("per_jar") or kotlin_toolchain.dep_files == DepFiles("per_class")) and target_type == TargetType("library") and track_class_usage: used_classes_json_outputs = [ output_paths.jar_parent.project("used-classes.json"), @@ -512,4 +515,4 @@ def _define_kotlincd_action( error_handler = kotlin_toolchain.kotlin_error_handler, **incremental_run_params ) - return proto + return proto, used_jars_json_output