From 475015bee0da48269181e1ddbfe9679d6670930b Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 20 Sep 2022 15:23:56 -0700 Subject: [PATCH] refactor: give internal impl methods meaningful names (#252) --- lib/private/copy_to_bin.bzl | 4 ++-- lib/private/host_repo.bzl | 4 ++-- lib/private/params_file.bzl | 4 ++-- lib/private/run_binary.bzl | 4 ++-- lib/tests/copy_to_directory_action/lib.bzl | 4 ++-- lib/tests/copy_to_directory_action/pkg.bzl | 4 ++-- lib/tests/generate_outputs.bzl | 4 ++-- .../write_source_files/write_source_file_test.bzl | 12 ++++++------ 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/private/copy_to_bin.bzl b/lib/private/copy_to_bin.bzl index 2ac5a79..53f01af 100644 --- a/lib/private/copy_to_bin.bzl +++ b/lib/private/copy_to_bin.bzl @@ -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), diff --git a/lib/private/host_repo.bzl b/lib/private/host_repo.bzl index c1fa53e..5f946ef 100644 --- a/lib/private/host_repo.bzl +++ b/lib/private/host_repo.bzl @@ -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", ) diff --git a/lib/private/params_file.bzl b/lib/private/params_file.bzl index 11d02c8..9f6e963 100644 --- a/lib/private/params_file.bzl +++ b/lib/private/params_file.bzl @@ -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, ) diff --git a/lib/private/run_binary.bzl b/lib/private/run_binary.bzl index d390c3d..d7fe14d 100644 --- a/lib/private/run_binary.bzl +++ b/lib/private/run_binary.bzl @@ -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, diff --git a/lib/tests/copy_to_directory_action/lib.bzl b/lib/tests/copy_to_directory_action/lib.bzl index 19cf3d6..14544a5 100644 --- a/lib/tests/copy_to_directory_action/lib.bzl +++ b/lib/tests/copy_to_directory_action/lib.bzl @@ -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], ) diff --git a/lib/tests/copy_to_directory_action/pkg.bzl b/lib/tests/copy_to_directory_action/pkg.bzl index 906ca53..b60c4d3 100644 --- a/lib/tests/copy_to_directory_action/pkg.bzl +++ b/lib/tests/copy_to_directory_action/pkg.bzl @@ -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], ) diff --git a/lib/tests/generate_outputs.bzl b/lib/tests/generate_outputs.bzl index bba5a04..269f649 100644 --- a/lib/tests/generate_outputs.bzl +++ b/lib/tests/generate_outputs.bzl @@ -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(), diff --git a/lib/tests/write_source_files/write_source_file_test.bzl b/lib/tests/write_source_files/write_source_file_test.bzl index 5d77ff8..4c7e40d 100644 --- a/lib/tests/write_source_files/write_source_file_test.bzl +++ b/lib/tests/write_source_files/write_source_file_test.bzl @@ -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,