[shac] Make default buildifier tool parameter a function call.

In fuchsia.git, shac checks need access to the 'ctx' variable
in order to determine the location of the prebuilt tools.

This changes the default tool parameter from a string to
a lambda, so this check can be used in both environments.

Tested by pinning this change in fuchsia.git and running the tools.

Change-Id: I41b45e4f0e9bb7bd2c7ac0110612e7589bae8668
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/checks-starlark/+/1040133
Reviewed-by: Darren Chan <chandarren@google.com>
diff --git a/checks/buildifier/common.star b/checks/buildifier/common.star
index bb3e2d6..81ca450 100644
--- a/checks/buildifier/common.star
+++ b/checks/buildifier/common.star
@@ -2,7 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-"""Rule for running size checker on product and package."""
+"""Common helper functions for the starlark checks."""
 
 def get_affected_files(ctx, file_filter = lambda x: True):
     return [
diff --git a/checks/buildifier/format.star b/checks/buildifier/format.star
index ce22e89..af9d226 100644
--- a/checks/buildifier/format.star
+++ b/checks/buildifier/format.star
@@ -13,7 +13,7 @@
 
 def _buildifier_format(
         ctx,
-        tool = "buildifier",
+        tool_ctx = lambda ctx: "buildifier",
         extra_args = [],
         emit_level = "error",
         emit_message = "File is not formatted",
@@ -21,6 +21,7 @@
         # For testing
         file_filter = lambda x: True):
     """Formats Starlark/Bazel files using buildifier."""
+    tool = tool_ctx(ctx)
 
     # Get list of affected starlark files in the workspace.
     files = get_affected_files(ctx, file_filter = file_filter)
diff --git a/checks/buildifier/lint.star b/checks/buildifier/lint.star
index 149b6ae..c90a35c 100644
--- a/checks/buildifier/lint.star
+++ b/checks/buildifier/lint.star
@@ -13,7 +13,7 @@
 
 def _buildifier_lint(
         ctx,
-        tool = "buildifier",
+        tool_ctx = lambda ctx: "buildifier",
         extra_args = [],
         emit_level = "error",
         emit_message = "File is not linted",
@@ -21,6 +21,7 @@
         # For testing
         file_filter = lambda x: True):
     """Lints Starlark/Bazel files using buildifier."""
+    tool = tool_ctx(ctx)
 
     # Get list of affected starlark files in the workspace.
     files = get_affected_files(ctx, file_filter = file_filter)
diff --git a/register.star b/register.star
index b0e2513..d96ebc6 100644
--- a/register.star
+++ b/register.star
@@ -8,8 +8,9 @@
 def register_buildifier_format(**kwargs):
     # Available arguments:
     #
-    #   tool: Path to buildifier host-tool
-    #     Must exist in and be rlative to the local workspace.
+    #   tool_ctx: Lambda function returning a path to buildifier host-tool
+    #     Takes one parameter of type "ctx".
+    #     Must exist in and be relative to the local workspace.
     #
     #   extra_args: Additional arguments passed directly to buildifier.
     #     list of strings
@@ -25,8 +26,9 @@
 def register_buildifier_lint(**kwargs):
     # Available arguments:
     #
-    #   tool: Path to buildifier host-tool
-    #     Must exist in and be rlative to the local workspace.
+    #   tool_ctx: Lambda function returning a path to buildifier host-tool
+    #     Takes one parameter of type "ctx".
+    #     Must exist in and be relative to the local workspace.
     #
     #   extra_args: Additional arguments passed directly to buildifier.
     #     list of strings