Skip to content

Commit

Permalink
Aspect parameter attribute 'optimize_building_jars' must have type 's…
Browse files Browse the repository at this point in the history
…tring' and use the 'values' restriction.
  • Loading branch information
nkoroste committed Jul 17, 2024
1 parent 1c3eed9 commit bf1696c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
22 changes: 14 additions & 8 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ def _collect_generated_files(java):
return [(java.annotation_processing.class_jar, java.annotation_processing.source_jar)]
return []

def _should_optimize_building_jars(ctx):
if ctx.attr.optimize_building_jars == "enabled":
return True
return False

def collect_java_info(target, ctx, semantics, ide_info, ide_info_file, output_groups):
"""Updates Java-specific output groups, returns false if not a Java target."""
java = get_java_provider(target)
Expand All @@ -625,7 +630,7 @@ def collect_java_info(target, ctx, semantics, ide_info, ide_info_file, output_gr
sources = sources_from_target(ctx)
jars = [library_artifact(output, ctx.rule.kind) for output in java_outputs]
class_jars = [output.class_jar for output in java_outputs if output and output.class_jar]
output_jars = [jar for output in java_outputs for jar in jars_from_output(output, ctx.attr.optimize_building_jars)]
output_jars = [jar for output in java_outputs for jar in jars_from_output(output, _should_optimize_building_jars(ctx))]
resolve_files = output_jars
compile_files = class_jars

Expand Down Expand Up @@ -768,18 +773,18 @@ def _build_filtered_gen_jar(ctx, target, java_outputs, gen_java_sources, srcjars
"""Filters the passed jar to contain only classes from the given manifest."""
jar_artifacts = []
source_jar_artifacts = []
should_should_optimize_building_jars = ctx.attr.optimize_building_jars
should_optimize_building_jars = _should_optimize_building_jars(ctx)
for jar in java_outputs:
if jar.ijar:
jar_artifacts.append(jar.ijar)
elif jar.class_jar and not should_should_optimize_building_jars:
elif jar.class_jar and not should_optimize_building_jars:
jar_artifacts.append(jar.class_jar)
if hasattr(jar, "source_jars") and jar.source_jars:
source_jar_artifacts.extend(_list_or_depset_to_list(jar.source_jars))
elif hasattr(jar, "source_jar") and jar.source_jar:
source_jar_artifacts.append(jar.source_jar)

if should_should_optimize_building_jars:
if should_optimize_building_jars:
if len(source_jar_artifacts) == 0 or len(jar_artifacts) == 0:
jar_artifacts.extend([jar.class_jar for jar in java_outputs.jars if jar.class_jar])

Expand Down Expand Up @@ -888,7 +893,7 @@ def _collect_android_ide_info(target, ctx, semantics, ide_info, ide_info_file, o

resources = []
res_folders = []
resolve_files = jars_from_output(output_jar, ctx.attr.optimize_building_jars)
resolve_files = jars_from_output(output_jar, _should_optimize_building_jars(ctx))
if hasattr(ctx.rule.attr, "resource_files"):
for artifact_path_fragments, res_files in get_res_artifacts(ctx.rule.attr.resource_files).items():
# Generate unique ArtifactLocation for resource directories.
Expand Down Expand Up @@ -960,7 +965,7 @@ def _collect_android_ide_info(target, ctx, semantics, ide_info, ide_info_file, o
# b/176209293: expose resource jar to make sure empty library
# knows they are remote output artifact
if android.resource_jar:
resolve_files += [jar for jar in jars_from_output(android.resource_jar, ctx.attr.optimize_building_jars)]
resolve_files += [jar for jar in jars_from_output(android.resource_jar, _should_optimize_building_jars(ctx))]

ide_info["android_ide_info"] = android_info
update_sync_output_groups(output_groups, "intellij-resolve-android", depset(resolve_files))
Expand Down Expand Up @@ -1272,9 +1277,10 @@ def make_intellij_info_aspect(aspect_impl, semantics):
executable = True,
allow_files = True,
),
"optimize_building_jars": attr.bool(
"optimize_building_jars": attr.string(
doc = "Reduce the number of jars built by the aspect and tracked by the ide",
default = False,
default = "disabled",
values = ["enabled", "disabled"],
),
}

Expand Down
9 changes: 5 additions & 4 deletions aspect/testing/rules/intellij_aspect_test_fixture.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ _intellij_aspect_test_fixture = rule(
executable = True,
allow_files = True,
),
"optimize_building_jars": attr.bool(
default = False,
doc = "Whether to optimize building jars by using the same jar for all targets that have the same jar dependencies.",
"optimize_building_jars": attr.string(
doc = "Reduce the number of jars built by the aspect and tracked by the ide",
default = "disabled",
values = ["enabled", "disabled"],
),
},
)

def intellij_aspect_test_fixture(name, deps, transitive_configs = [], optimize_building_jars = False):
def intellij_aspect_test_fixture(name, deps, transitive_configs = [], optimize_building_jars = "disabled"):
_intellij_aspect_test_fixture(
name = name,
output = name + ".intellij-aspect-test-fixture",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ java_library(

intellij_aspect_test_fixture(
name = "noide_fixture",
optimize_building_jars = False,
optimize_building_jars = "disabled",
deps = [
":baz",
":foo",
Expand All @@ -34,7 +34,7 @@ intellij_aspect_test_fixture(

intellij_aspect_test_fixture(
name = "noide_fixture_optimize_building_jars",
optimize_building_jars = True,
optimize_building_jars = "enabled",
deps = [
":baz",
":foo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ java_library(

intellij_aspect_test_fixture(
name = "foo_fixture",
optimize_building_jars = False,
optimize_building_jars = "disabled",
deps = [":foo"],
)

intellij_aspect_test_fixture(
name = "foo_fixture_optimize_building_jars",
optimize_building_jars = True,
optimize_building_jars = "enabled",
deps = [":foo"],
)

Expand All @@ -63,7 +63,7 @@ java_library(

intellij_aspect_test_fixture(
name = "foo_exports_fixture",
optimize_building_jars = False,
optimize_building_jars = "disabled",
deps = [":foo_exports"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ java_library(

intellij_aspect_test_fixture(
name = "lib_fixture",
optimize_building_jars = False,
optimize_building_jars = "disabled",
deps = [":lib"],
)

intellij_aspect_test_fixture(
name = "lib_fixture_optimized_jars",
optimize_building_jars = True,
optimize_building_jars = "enabled",
deps = [":lib"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public final void addAspectAndOutputGroups(
if (optimize_building_jars.isEnabled()){
builder
.addBlazeFlags(getAspectFlag().map(List::of).orElse(List.of()))
.addBlazeFlags("--aspects_parameters=optimize_building_jars=True")
.addBlazeFlags("--aspects_parameters=optimize_building_jars=enabled")
.addBlazeFlags("--output_groups=" + Joiner.on(',').join(groups));
} else {
builder
Expand Down

0 comments on commit bf1696c

Please sign in to comment.