Skip to content

Commit

Permalink
chore: Aspect templating - 1/n
Browse files Browse the repository at this point in the history
  • Loading branch information
tpasternak committed Sep 26, 2024
1 parent 6bfd117 commit e01e6d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
13 changes: 13 additions & 0 deletions aspect/get_java_provider.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def get_java_provider(target):
"""Find a provider exposing java compilation/outputs data."""

# Check for kt providers before JavaInfo. e.g. kt targets have
# JavaInfo, but their data lives in the "kt" provider and not JavaInfo.
# See https://github.com/bazelbuild/intellij/pull/1202
if hasattr(target, "kt") and hasattr(target.kt, "outputs"):
return target.kt
if JavaInfo in target:
return target[JavaInfo]
if hasattr(java_common, "JavaPluginInfo") and java_common.JavaPluginInfo in target:
return target[java_common.JavaPluginInfo]
return None
23 changes: 5 additions & 18 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Implementation of IntelliJ-specific information collecting aspect."""

load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"ACTION_NAMES",
)
load(
":artifacts.bzl",
"artifact_location",
Expand All @@ -9,14 +13,11 @@ load(
"struct_omit_none",
"to_artifact_location",
)
load(":get_java_provider.bzl", "get_java_provider")
load(
":make_variables.bzl",
"expand_make_variables",
)
load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"ACTION_NAMES",
)

IntelliJInfo = provider(
doc = "Collected infromation about the targets visited by the aspect.",
Expand Down Expand Up @@ -586,20 +587,6 @@ def collect_c_toolchain_info(target, ctx, semantics, ide_info, ide_info_file, ou
update_sync_output_groups(output_groups, "intellij-info-cpp", depset([ide_info_file]))
return True

def get_java_provider(target):
"""Find a provider exposing java compilation/outputs data."""

# Check for kt providers before JavaInfo. e.g. kt targets have
# JavaInfo, but their data lives in the "kt" provider and not JavaInfo.
# See https://github.com/bazelbuild/intellij/pull/1202
if hasattr(target, "kt") and hasattr(target.kt, "outputs"):
return target.kt
if JavaInfo in target:
return target[JavaInfo]
if hasattr(java_common, "JavaPluginInfo") and java_common.JavaPluginInfo in target:
return target[java_common.JavaPluginInfo]
return None

def _collect_generated_files(java):
"""Collects generated files from a Java target"""
if hasattr(java, "java_outputs"):
Expand Down

0 comments on commit e01e6d2

Please sign in to comment.