diff --git a/lib/apple_support.bzl b/lib/apple_support.bzl index 97189ff..cf1c10a 100644 --- a/lib/apple_support.bzl +++ b/lib/apple_support.bzl @@ -127,16 +127,6 @@ done "$TOOLNAME" "${ARGS[@]}" """ -def _validate_ctx_xor_platform_requirements(*, ctx, actions, apple_fragment, xcode_config): - """Raises an error if there is overlap in platform requirements or if they are insufficent.""" - - if ctx != None and any([actions, xcode_config, apple_fragment]): - fail("Can't specific ctx along with actions, xcode_config, apple_fragment.") - if ctx == None and not all([actions, xcode_config, apple_fragment]): - fail("Must specify all of actions, xcode_config, and apple_fragment.") - if ctx != None: - _validate_ctx_attribute_present(ctx, "_xcode_config") - def _platform_frameworks_path_placeholder(*, apple_fragment): """Returns the platform's frameworks directory, anchored to the Xcode path placeholder. @@ -210,29 +200,6 @@ def _kwargs_for_apple_platform( processed_args["execution_requirements"] = merged_execution_requirements return processed_args -def _validate_ctx_attribute_present(ctx, attribute_name): - """Validates that the given attribute is present for the rule, failing otherwise.""" - if not hasattr(ctx.attr, attribute_name): - fail("\n".join([ - "", - "ERROR: This rule requires the '{}' attribute to be present. ".format(attribute_name), - "To add this attribute, modify your rule definition like this:", - "", - "load(\"@bazel_skylib//lib:dicts.bzl\", \"dicts\")", - "load(", - " \"@build_bazel_apple_support//lib:apple_support.bzl\",", - " \"apple_support\",", - ")", - "", - "your_rule_name = rule(", - " attrs = dicts.add(apple_support.action_required_attrs(), {", - " # other attributes", - " }),", - " # other rule arguments", - ")", - "", - ])) - def _action_required_attrs(): """Returns a dictionary with required attributes for registering actions on Apple platforms. @@ -308,12 +275,11 @@ def _platform_constraint_attrs(): } def _run( - ctx = None, - xcode_path_resolve_level = _XCODE_PATH_RESOLVE_LEVEL.none, *, - actions = None, - xcode_config = None, - apple_fragment = None, + actions, + xcode_config, + apple_fragment, + xcode_path_resolve_level = _XCODE_PATH_RESOLVE_LEVEL.none, **kwargs): """Registers an action to run on an Apple machine. @@ -353,30 +319,13 @@ def _run( path argument beginning with `@`) will be replaced. Args: - ctx: The context of the rule registering the action. Deprecated. - xcode_path_resolve_level: The level of Xcode path replacement required for the action. - actions: The actions provider from ctx.actions. Required if ctx is not given. + actions: The actions provider from ctx.actions. xcode_config: The xcode_config as found in the current rule or aspect's context. Typically from `ctx.attr._xcode_config[apple_common.XcodeVersionConfig]`. - Required if ctx is not given. apple_fragment: A reference to the apple fragment. Typically from `ctx.fragments.apple`. - Required if ctx is not given. + xcode_path_resolve_level: The level of Xcode path replacement required for the action. **kwargs: See `ctx.actions.run` for the rest of the available arguments. """ - _validate_ctx_xor_platform_requirements( - ctx = ctx, - actions = actions, - apple_fragment = apple_fragment, - xcode_config = xcode_config, - ) - - if not actions: - actions = ctx.actions - if not xcode_config: - xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig] - if not apple_fragment: - apple_fragment = ctx.fragments.apple - if xcode_path_resolve_level == _XCODE_PATH_RESOLVE_LEVEL.none: actions.run(**_kwargs_for_apple_platform( xcode_config = xcode_config, @@ -454,11 +403,10 @@ def _run( ) def _run_shell( - ctx = None, *, - actions = None, - xcode_config = None, - apple_fragment = None, + actions, + xcode_config, + apple_fragment, **kwargs): """Registers a shell action to run on an Apple machine. @@ -476,21 +424,12 @@ def _run_shell( please use `run` instead. Args: - ctx: The context of the rule registering the action. Deprecated. actions: The actions provider from ctx.actions. xcode_config: The xcode_config as found in the current rule or aspect's context. Typically from `ctx.attr._xcode_config[apple_common.XcodeVersionConfig]`. - Required if ctx is not given. apple_fragment: A reference to the apple fragment. Typically from `ctx.fragments.apple`. - Required if ctx is not given. **kwargs: See `ctx.actions.run_shell` for the rest of the available arguments. """ - _validate_ctx_xor_platform_requirements( - ctx = ctx, - actions = actions, - apple_fragment = apple_fragment, - xcode_config = xcode_config, - ) # TODO(b/77637734) remove "workaround" once the bazel issue is resolved. # Bazel doesn't always get the shell right for a single string `commands`; @@ -503,13 +442,6 @@ def _run_shell( processed_args["command"] = ["/bin/sh", "-c", command] kwargs = processed_args - if not actions: - actions = ctx.actions - if not xcode_config: - xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig] - if not apple_fragment: - apple_fragment = ctx.fragments.apple - actions.run_shell(**_kwargs_for_apple_platform( xcode_config = xcode_config, apple_fragment = apple_fragment, diff --git a/test/apple_support_test.bzl b/test/apple_support_test.bzl index 8d9a512..34b1ade 100644 --- a/test/apple_support_test.bzl +++ b/test/apple_support_test.bzl @@ -117,18 +117,6 @@ def _apple_support_test_impl(ctx): run_shell_output = ctx.actions.declare_file( "{}_run_shell_output".format(ctx.label.name), ) - run_output_ctx = ctx.actions.declare_file( - "{}_run_output_ctx".format(ctx.label.name), - ) - run_output_xcode_path_in_args_ctx = ctx.actions.declare_file( - "{}_run_output_xcode_path_in_args_ctx".format(ctx.label.name), - ) - run_output_xcode_path_in_file_ctx = ctx.actions.declare_file( - "{}_run_output_xcode_path_in_file_ctx".format(ctx.label.name), - ) - run_shell_output_ctx = ctx.actions.declare_file( - "{}_run_shell_output_ctx".format(ctx.label.name), - ) test_tool = ctx.actions.declare_file("{}_test_tool".format(ctx.label.name)) ctx.actions.write(test_tool, _TEST_TOOL_CONTENTS, is_executable = True) @@ -144,13 +132,6 @@ def _apple_support_test_impl(ctx): arguments = [run_output.path], exec_group = "mac_exec_group", ) - apple_support.run( - ctx, - outputs = [run_output_ctx], - executable = test_tool, - arguments = [run_output_ctx.path], - exec_group = "mac_exec_group", - ) platform_frameworks = apple_support.path_placeholders.platform_frameworks( apple_fragment = ctx.fragments.apple, @@ -171,19 +152,6 @@ def _apple_support_test_impl(ctx): xcode_path_resolve_level = apple_support.xcode_path_resolve_level.args, exec_group = "mac_exec_group", ) - apple_support.run( - ctx, - outputs = [run_output_xcode_path_in_args_ctx], - executable = test_tool, - arguments = [ - run_output_xcode_path_in_args_ctx.path, - "XCODE_PATH_ARG={}".format(apple_support.path_placeholders.xcode()), - "FRAMEWORKS_PATH_ARG={}".format(platform_frameworks), - "SDKROOT_PATH_ARG={}".format(apple_support.path_placeholders.sdkroot()), - ], - xcode_path_resolve_level = apple_support.xcode_path_resolve_level.args, - exec_group = "mac_exec_group", - ) action_args = ctx.actions.args() action_args.add( @@ -211,17 +179,6 @@ def _apple_support_test_impl(ctx): xcode_path_resolve_level = apple_support.xcode_path_resolve_level.args_and_files, exec_group = "mac_exec_group", ) - apple_support.run( - ctx, - outputs = [run_output_xcode_path_in_file_ctx], - executable = test_tool, - arguments = [ - run_output_xcode_path_in_file_ctx.path, - action_args, - ], - xcode_path_resolve_level = apple_support.xcode_path_resolve_level.args_and_files, - exec_group = "mac_exec_group", - ) apple_support.run_shell( actions = ctx.actions, @@ -235,26 +192,12 @@ def _apple_support_test_impl(ctx): )], exec_group = "mac_exec_group", ) - apple_support.run_shell( - ctx, - outputs = [run_shell_output_ctx], - tools = [test_tool], - command = ["/bin/bash", "-c", "{tool} {output}".format( - output = run_shell_output_ctx.path, - tool = test_tool.path, - )], - exec_group = "mac_exec_group", - ) test_files = [ run_output, - run_output_ctx, run_output_xcode_path_in_args, - run_output_xcode_path_in_args_ctx, run_output_xcode_path_in_file, - run_output_xcode_path_in_file_ctx, run_shell_output, - run_shell_output_ctx, ] test_script = ctx.actions.declare_file("{}_test_script".format(ctx.label.name))