Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Aspect templating - 4/n - extract apply_hack.bzl #6844

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aspect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

load(
":intellij_info_impl.bzl",
":flag_hack.bzl",
"define_flag_hack",
)

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion aspect/BUILD.aspect
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

licenses(["notice"]) # Apache 2.0

load(":intellij_info_impl_bundled.bzl",
load(":flag_hack.bzl",
"define_flag_hack")

java_binary(
Expand Down
32 changes: 32 additions & 0 deletions aspect/flag_hack.bzl
Original file line number Diff line number Diff line change
@@ -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
36 changes: 2 additions & 34 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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

Expand Down