From 4c7841f6952e0008bbe6ad58571f3216411c85e5 Mon Sep 17 00:00:00 2001 From: Tomasz Pasternak Date: Fri, 4 Oct 2024 12:57:33 +0200 Subject: [PATCH 1/2] chore: Aspect templating - 4/n - extract apply_hack.bzl --- aspect/BUILD | 3 ++- aspect/BUILD.aspect | 2 +- aspect/flag_hack.bzl | 32 +++++++++++++++++++++++++++++++ aspect/intellij_info_impl.bzl | 36 ++--------------------------------- 4 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 aspect/flag_hack.bzl diff --git a/aspect/BUILD b/aspect/BUILD index 5b75ae6852d..512f38d4a84 100644 --- a/aspect/BUILD +++ b/aspect/BUILD @@ -3,7 +3,7 @@ # load( - ":intellij_info_impl.bzl", + ":flag_hack.bzl", "define_flag_hack", ) @@ -33,6 +33,7 @@ filegroup( "artifacts.bzl", "build_dependencies.bzl", "fast_build_info_bundled.bzl", + "flag_hack.bzl", "intellij_info.bzl", "intellij_info_bundled.bzl", "intellij_info_impl_bundled.bzl", diff --git a/aspect/BUILD.aspect b/aspect/BUILD.aspect index 70f85a82c12..85caf6afb91 100644 --- a/aspect/BUILD.aspect +++ b/aspect/BUILD.aspect @@ -5,7 +5,7 @@ licenses(["notice"]) # Apache 2.0 -load(":intellij_info_impl_bundled.bzl", +load(":flag_hack.bzl", "define_flag_hack") java_binary( diff --git a/aspect/flag_hack.bzl b/aspect/flag_hack.bzl new file mode 100644 index 00000000000..8d4494f63e6 --- /dev/null +++ b/aspect/flag_hack.bzl @@ -0,0 +1,32 @@ +##### Begin bazel-flag-hack +# The flag hack stuff below is a way to detect flags that bazel has been invoked with from the +# aspect. Once PY3-as-default is stable, it can be removed. When removing, also remove the +# define_flag_hack() call in BUILD and the "_flag_hack" attr on the aspect below. See +# "PY3-as-default" in: +# https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java + +FlagHackInfo = provider(fields = ["incompatible_py2_outputs_are_suffixed"]) + +def _flag_hack_impl(ctx): + return [FlagHackInfo(incompatible_py2_outputs_are_suffixed = ctx.attr.incompatible_py2_outputs_are_suffixed)] + +_flag_hack_rule = rule( + attrs = {"incompatible_py2_outputs_are_suffixed": attr.bool()}, + implementation = _flag_hack_impl, +) + +def define_flag_hack(): + native.config_setting( + name = "incompatible_py2_outputs_are_suffixed_setting", + values = {"incompatible_py2_outputs_are_suffixed": "true"}, + ) + _flag_hack_rule( + name = "flag_hack", + incompatible_py2_outputs_are_suffixed = select({ + ":incompatible_py2_outputs_are_suffixed_setting": True, + "//conditions:default": False, + }), + visibility = ["//visibility:public"], + ) + +##### End bazel-flag-hack diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index 0d421daf2d5..be5d50936a8 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -4,6 +4,7 @@ load( "@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES", ) +load("@intellij_aspect_variadic//:java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") load( ":artifacts.bzl", "artifact_location", @@ -13,7 +14,7 @@ load( "struct_omit_none", "to_artifact_location", ) -load(":java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") +load(":flag_hack.bzl", "FlagHackInfo") load( ":make_variables.bzl", "expand_make_variables", @@ -78,39 +79,6 @@ PY2 = 1 PY3 = 2 -##### Begin bazel-flag-hack -# The flag hack stuff below is a way to detect flags that bazel has been invoked with from the -# aspect. Once PY3-as-default is stable, it can be removed. When removing, also remove the -# define_flag_hack() call in BUILD and the "_flag_hack" attr on the aspect below. See -# "PY3-as-default" in: -# https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java - -FlagHackInfo = provider(fields = ["incompatible_py2_outputs_are_suffixed"]) - -def _flag_hack_impl(ctx): - return [FlagHackInfo(incompatible_py2_outputs_are_suffixed = ctx.attr.incompatible_py2_outputs_are_suffixed)] - -_flag_hack_rule = rule( - attrs = {"incompatible_py2_outputs_are_suffixed": attr.bool()}, - implementation = _flag_hack_impl, -) - -def define_flag_hack(): - native.config_setting( - name = "incompatible_py2_outputs_are_suffixed_setting", - values = {"incompatible_py2_outputs_are_suffixed": "true"}, - ) - _flag_hack_rule( - name = "flag_hack", - incompatible_py2_outputs_are_suffixed = select({ - ":incompatible_py2_outputs_are_suffixed_setting": True, - "//conditions:default": False, - }), - visibility = ["//visibility:public"], - ) - -##### End bazel-flag-hack - # PythonCompatVersion enum; must match PyIdeInfo.PythonSrcsVersion SRC_PY2 = 1 From f1d6bd892a0ba1691bc22c3a20e3af84b058dcf0 Mon Sep 17 00:00:00 2001 From: Tomasz Pasternak Date: Fri, 4 Oct 2024 14:34:51 +0200 Subject: [PATCH 2/2] fix tests --- aspect/intellij_info_impl.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index be5d50936a8..161d9929c7a 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -4,7 +4,6 @@ load( "@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES", ) -load("@intellij_aspect_variadic//:java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") load( ":artifacts.bzl", "artifact_location", @@ -15,6 +14,7 @@ load( "to_artifact_location", ) load(":flag_hack.bzl", "FlagHackInfo") +load(":java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") load( ":make_variables.bzl", "expand_make_variables",