[shac] Make default clang-format 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: I641616402d0cc8ae0aa161adc74bd36ceef1643c Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/checks-cpp/+/1040134 Reviewed-by: Darren Chan <chandarren@google.com>
diff --git a/checks/clang-format/clang_format.star b/checks/clang-format/clang_format.star index 6f70332..c2d7837 100644 --- a/checks/clang-format/clang_format.star +++ b/checks/clang-format/clang_format.star
@@ -4,7 +4,7 @@ def _clang_format( ctx, - tool = "clang-format", + tool_ctx = lambda ctx: "clang-format", extra_args = [], emit_level = "error", emit_message = "File is not formatted.", @@ -12,6 +12,7 @@ # For testing file_filter = lambda x: True): """Formats C/C++ files using clang-format.""" + tool = tool_ctx(ctx) base_cmd = [tool]
diff --git a/register.star b/register.star index 672d03d..0658943 100644 --- a/register.star +++ b/register.star
@@ -7,8 +7,9 @@ def register_clang_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 clang-format 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