Skip to content

Commit f563df7

Browse files
authored
Remove unnecessary uses of ctx.resolve_tools. (#1183)
We'd like to retire this API, which is redundant with the `executable` and `tools` arguments to `ctx.actions.run|run_shell`.
1 parent 2b3f730 commit f563df7

File tree

5 files changed

+19
-71
lines changed

5 files changed

+19
-71
lines changed

swift/internal/actions.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ def run_toolchain_action(
246246
else:
247247
executable = tool_config.executable
248248

249+
if tool_config.tools:
250+
tools.extend(tool_config.tools)
251+
249252
# If the tool configuration has any required arguments, add those first.
250253
if tool_config.args:
251254
args.add_all(tool_config.args)
@@ -266,13 +269,12 @@ def run_toolchain_action(
266269
env = tool_config.env,
267270
executable = executable,
268271
execution_requirements = execution_requirements,
269-
input_manifests = tool_config.tool_input_manifests,
270272
inputs = depset(
271273
action_inputs.inputs,
272274
transitive = action_inputs.transitive_inputs,
273275
),
274276
mnemonic = mnemonic if mnemonic else action_name,
275-
tools = depset(tools, transitive = [tool_config.tool_inputs]),
277+
tools = tools,
276278
use_default_shell_env = USE_DEFAULT_SHELL_ENV,
277279
**kwargs
278280
)

swift/internal/swift_toolchain.bzl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def _all_tool_configs(
8282
flags.
8383
use_module_wrap: If True, the compile action should embed the
8484
swiftmodule into the final image.
85-
additional_tools: Any extra tool inputs to pass to each driver config
85+
additional_tools: A list of extra tools to pass to each driver config,
86+
in a format suitable for the `tools` argument to `ctx.actions.run`.
8687
tool_executable_suffix: The suffix for executable tools to use (e.g.
8788
`.exe` on Windows).
8889
@@ -91,12 +92,10 @@ def _all_tool_configs(
9192
"""
9293
_swift_driver_tool_config = swift_toolchain_config.driver_tool_config
9394

94-
tool_inputs = depset(additional_tools)
95-
9695
compile_tool_config = _swift_driver_tool_config(
9796
driver_mode = "swiftc",
9897
swift_executable = swift_executable,
99-
tool_inputs = tool_inputs,
98+
tools = additional_tools,
10099
toolchain_root = toolchain_root,
101100
tool_executable_suffix = tool_executable_suffix,
102101
use_param_file = use_param_file,
@@ -114,7 +113,7 @@ def _all_tool_configs(
114113
configs[swift_action_names.AUTOLINK_EXTRACT] = _swift_driver_tool_config(
115114
driver_mode = "swift-autolink-extract",
116115
swift_executable = swift_executable,
117-
tool_inputs = tool_inputs,
116+
tools = additional_tools,
118117
toolchain_root = toolchain_root,
119118
tool_executable_suffix = tool_executable_suffix,
120119
worker_mode = "wrap",
@@ -126,7 +125,7 @@ def _all_tool_configs(
126125
args = ["-modulewrap"],
127126
driver_mode = "swift",
128127
swift_executable = swift_executable,
129-
tool_inputs = tool_inputs,
128+
tools = additional_tools,
130129
toolchain_root = toolchain_root,
131130
tool_executable_suffix = tool_executable_suffix,
132131
worker_mode = "wrap",

swift/internal/toolchain_config.bzl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ _ToolConfigInfo = provider(
4343
"env",
4444
"executable",
4545
"execution_requirements",
46-
"tool_input_manifests",
47-
"tool_inputs",
46+
"tools",
4847
"use_param_file",
4948
"worker_mode",
5049
],
@@ -300,8 +299,7 @@ def _tool_config(
300299
args = [],
301300
env = {},
302301
execution_requirements = {},
303-
tool_input_manifests = [],
304-
tool_inputs = depset(),
302+
tools = [],
305303
use_param_file = False,
306304
worker_mode = None):
307305
"""Returns a new Swift toolchain tool configuration.
@@ -316,14 +314,8 @@ def _tool_config(
316314
invoking actions using this tool.
317315
execution_requirements: A dictionary of execution requirements that
318316
should be passed when creating actions with this tool.
319-
tool_input_manifests: A list of input runfiles metadata for tools that
320-
should be passed into the `input_manifests` argument of the
321-
`ctx.actions.run` call that registers actions using this tool (see
322-
also Bazel's `ctx.resolve_tools`).
323-
tool_inputs: A `depset` of additional inputs for tools that should be
324-
passed into the `tools` argument of the `ctx.actions.run` call that
325-
registers actions using this tool (see also Bazel's
326-
`ctx.resolve_tools`).
317+
tools: A list of additional tools to pass to spawned actions, in a
318+
format suitable for the `tools` argument to `ctx.actions.run`.
327319
use_param_file: If True, actions invoked using this tool will have their
328320
arguments written to a param file.
329321
worker_mode: A string, or `None`, describing how the tool is invoked
@@ -343,8 +335,7 @@ def _tool_config(
343335
env = env,
344336
executable = executable,
345337
execution_requirements = execution_requirements,
346-
tool_input_manifests = tool_input_manifests,
347-
tool_inputs = tool_inputs,
338+
tools = tools,
348339
use_param_file = use_param_file,
349340
worker_mode = _validate_worker_mode(worker_mode),
350341
)

swift/internal/utils.bzl

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -356,44 +356,6 @@ def owner_relative_path(file):
356356
else:
357357
return paths.relativize(file.short_path, package)
358358

359-
def resolve_optional_tool(ctx, *, target):
360-
"""Resolves a tool and returns a `struct` describing its inputs.
361-
362-
This function uses `ctx.resolve_tools` which allows an executable and any of
363-
its required runfiles to be propagated correctly across the target boundary.
364-
365-
Args:
366-
ctx: The rule or aspect context.
367-
target: The `Target` representing the tool whose inputs should be
368-
resolved. This may be `None`, in which case the returned `struct`
369-
will be valid but its fields will be appropriately empty.
370-
371-
Returns:
372-
A `struct` containing three fields:
373-
374-
* `executable`: The `File` representing the tool's executable (or
375-
`None` if `target` was `None`).
376-
* `input_manifests`: A list of input manifests that should be passed
377-
as `tool_input_manifests` when configuring the tool in the
378-
toolchain (or the empty list if `target` was `None`.)
379-
* `inputs`: A `depset` of `File`s that should be passed as
380-
`tool_inputs` when configuring the tool in the toolchain (or the
381-
empty `depset` if `target` was `None`.)
382-
"""
383-
if target:
384-
executable = target[DefaultInfo].files_to_run.executable
385-
inputs, input_manifests = ctx.resolve_tools(tools = [target])
386-
else:
387-
executable = None
388-
input_manifests = []
389-
inputs = depset()
390-
391-
return struct(
392-
executable = executable,
393-
input_manifests = input_manifests,
394-
inputs = inputs,
395-
)
396-
397359
def struct_fields(s):
398360
"""Returns a dictionary containing the fields in the struct `s`.
399361

swift/internal/xcode_swift_toolchain.bzl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ load(
6767
":utils.bzl",
6868
"collect_implicit_deps_providers",
6969
"get_swift_executable_for_toolchain",
70-
"resolve_optional_tool",
7170
)
7271

7372
# TODO: Remove once we drop bazel 7.x
@@ -421,7 +420,7 @@ def _all_action_configs(
421420
action_configs.extend(compile_action_configs(
422421
additional_objc_copts = additional_objc_copts,
423422
additional_swiftc_copts = additional_swiftc_copts,
424-
generated_header_rewriter = generated_header_rewriter.executable,
423+
generated_header_rewriter = generated_header_rewriter,
425424
))
426425
return action_configs
427426

@@ -439,9 +438,8 @@ def _all_tool_configs(
439438
one was requested.
440439
env: The environment variables to set when launching tools.
441440
execution_requirements: The execution requirements for tools.
442-
generated_header_rewriter: A `struct` returned by
443-
`resolve_optional_tool` that represents an executable that will be
444-
invoked after compilation to rewrite the generated header.
441+
generated_header_rewriter: The optional executable that will be invoked
442+
after compilation to rewrite the generated header.
445443
swift_executable: A custom Swift driver executable to be used during the
446444
build, if provided.
447445
toolchain_root: The root directory of the toolchain, if provided.
@@ -464,8 +462,7 @@ def _all_tool_configs(
464462
env = env,
465463
execution_requirements = execution_requirements,
466464
swift_executable = swift_executable,
467-
tool_input_manifests = generated_header_rewriter.input_manifests,
468-
tool_inputs = generated_header_rewriter.inputs,
465+
tools = [generated_header_rewriter] if generated_header_rewriter else [],
469466
toolchain_root = toolchain_root,
470467
use_param_file = True,
471468
worker_mode = "persistent",
@@ -643,10 +640,7 @@ def _xcode_swift_toolchain_impl(ctx):
643640

644641
env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config)
645642
execution_requirements = xcode_config.execution_info()
646-
generated_header_rewriter = resolve_optional_tool(
647-
ctx,
648-
target = ctx.attr.generated_header_rewriter,
649-
)
643+
generated_header_rewriter = ctx.executable.generated_header_rewriter
650644

651645
all_tool_configs = _all_tool_configs(
652646
custom_toolchain = custom_toolchain,

0 commit comments

Comments
 (0)