refactor: give internal impl methods meaningful names (#252)

This commit is contained in:
Jason Bedard 2022-09-20 15:23:56 -07:00 committed by GitHub
parent fa7fdc177e
commit 475015bee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 20 deletions

View File

@ -112,7 +112,7 @@ def copy_files_to_bin_actions(ctx, files, is_windows = None):
# TODO(2.0): remove depcreated & unused is_windows parameter
return [copy_file_to_bin_action(ctx, file, is_windows = is_windows) for file in files]
def _impl(ctx):
def _copy_to_bin_impl(ctx):
files = copy_files_to_bin_actions(ctx, ctx.files.srcs)
return DefaultInfo(
files = depset(files),
@ -120,7 +120,7 @@ def _impl(ctx):
)
_copy_to_bin = rule(
implementation = _impl,
implementation = _copy_to_bin_impl,
provides = [DefaultInfo],
attrs = {
"srcs": attr.label_list(mandatory = True, allow_files = True),

View File

@ -3,7 +3,7 @@
load("@bazel_skylib//lib:versions.bzl", "versions")
load(":repo_utils.bzl", "repo_utils")
def _impl(rctx):
def _host_repo_impl(rctx):
# Base BUILD file for this repository
rctx.file("BUILD.bazel", """# @generated by @aspect_bazel_lib//lib/private:host_repo.bzl
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
@ -35,6 +35,6 @@ host = struct(
))
host_repo = repository_rule(
implementation = _impl,
implementation = _host_repo_impl,
doc = "Exposes information about the host platform",
)

View File

@ -19,7 +19,7 @@ def _expand_locations(ctx, s):
# locations has a space in the name, we will incorrectly split it into multiple arguments
return expand_locations(ctx, s, targets = ctx.attr.data).split(" ")
def _impl(ctx):
def _params_file_impl(ctx):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
if ctx.attr.newline == "auto":
@ -49,7 +49,7 @@ def _impl(ctx):
return [DefaultInfo(files = files, runfiles = runfiles)]
params_file = rule(
implementation = _impl,
implementation = _params_file_impl,
provides = [DefaultInfo],
attrs = _ATTRS,
)

View File

@ -19,7 +19,7 @@ load(":expand_locations.bzl", "expand_locations")
load(":expand_variables.bzl", "expand_variables")
load("//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
def _impl(ctx):
def _run_binary_impl(ctx):
tool_as_list = [ctx.attr.tool]
tool_inputs, tool_input_mfs = ctx.resolve_tools(tools = tool_as_list)
args = ctx.actions.args()
@ -86,7 +86,7 @@ Possible fixes:
)
_run_binary = rule(
implementation = _impl,
implementation = _run_binary_impl,
attrs = dict({
"tool": attr.label(
executable = True,

View File

@ -9,14 +9,14 @@ _attrs = {
"others": attr.label_list(allow_files = True),
}
def _impl(ctx):
def _lib_impl(ctx):
return [
DefaultInfo(files = depset(ctx.files.srcs)),
OtherInfo(files = depset(ctx.files.others)),
]
lib = rule(
implementation = _impl,
implementation = _lib_impl,
attrs = _attrs,
provides = [DefaultInfo, OtherInfo],
)

View File

@ -10,7 +10,7 @@ _attrs = {
"out": attr.string(mandatory = True),
}
def _impl(ctx):
def _pkg_impl(ctx):
dst = ctx.actions.declare_directory(ctx.attr.out)
additional_files_depsets = []
@ -32,7 +32,7 @@ def _impl(ctx):
]
pkg = rule(
implementation = _impl,
implementation = _pkg_impl,
attrs = _attrs,
provides = [DefaultInfo],
)

View File

@ -1,6 +1,6 @@
"""A simple rule that generates provides a DefaultOutput with some files"""
def _impl(ctx):
def _generate_outputs_impl(ctx):
if len(ctx.attr.output_files) != len(ctx.attr.output_contents):
fail("Number of output_files must match number of output_contents")
outputs = []
@ -24,7 +24,7 @@ def _impl(ctx):
return provide
generate_outputs = rule(
implementation = _impl,
implementation = _generate_outputs_impl,
provides = [DefaultInfo],
attrs = {
"output_files": attr.string_list(),

View File

@ -4,7 +4,7 @@
load("//lib/private:write_source_file.bzl", _write_source_file = "write_source_file")
load("//lib/private:directory_path.bzl", "DirectoryPathInfo")
def _impl_sh(ctx, in_file_path, out_file_path):
def _write_source_file_test_impl_sh(ctx, in_file_path, out_file_path):
test = ctx.actions.declare_file(
ctx.label.name + "_test.sh",
)
@ -54,7 +54,7 @@ assert_same {in_file} {out_file}""".format(
return test
def _impl_bat(ctx, in_file_path, out_file_path):
def _write_source_file_test_impl_bat(ctx, in_file_path, out_file_path):
test = ctx.actions.declare_file(
ctx.label.name + "_test.bat",
)
@ -122,7 +122,7 @@ exit /b 1
return test
def _impl(ctx):
def _write_source_file_test_impl(ctx):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
if DirectoryPathInfo in ctx.attr.in_file:
@ -135,9 +135,9 @@ def _impl(ctx):
in_file_path = in_file.short_path
if is_windows:
test = _impl_bat(ctx, in_file_path, ctx.file.out_file.short_path)
test = _write_source_file_test_impl_bat(ctx, in_file_path, ctx.file.out_file.short_path)
else:
test = _impl_sh(ctx, in_file_path, ctx.file.out_file.short_path)
test = _write_source_file_test_impl_sh(ctx, in_file_path, ctx.file.out_file.short_path)
return DefaultInfo(
executable = test,
@ -147,7 +147,7 @@ def _impl(ctx):
)
_write_source_file_test = rule(
implementation = _impl,
implementation = _write_source_file_test_impl,
attrs = {
"write_source_file_target": attr.label(
allow_single_file = True,