Skip to content

Commit 8cbbef1

Browse files
authored
Remove ctx.resolve_tools in favor of ctx.actions.run(executable = …) and ctx.actions.run(tools = ...). (#2438)
By passing the files_to_run for a tool into the `executable` or `tools` argument to `ctx.actions.run` or `ctx.actions.run_shell`, it's no longer necessary to pass the return values of `ctx.resolve_tools` into the `inputs` and `input_manifests` arguments. Each struct field of the AppleMacToolsToolchainInfo and AppleXPlatToolsToolchainInfo providers previously populated with the return values of `ctx.resolve_tools` is now populated with the files_to_run for the respective tool. The `resolved_` prefix is removed from field and variable names; in addition to it no longer making sense, this change provides proof that all usages have been audited. This lets us retire the `ctx.resolve_tools` API in a future Bazel version.
1 parent c00a35f commit 8cbbef1

32 files changed

+276
-398
lines changed

apple/internal/apple_toolchains.bzl

Lines changed: 45 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -33,57 +33,57 @@ A `File` referencing a plist template for dSYM bundles.
3333
"process_and_sign_template": """\
3434
A `File` referencing a template for a shell script to process and sign.
3535
""",
36-
"resolved_alticonstool": """\
37-
A `struct` from `ctx.resolve_tools` referencing a tool to insert alternate icons entries in the app
36+
"alticonstool": """\
37+
The files_to_run for a tool to insert alternate icons entries in the app
3838
bundle's `Info.plist`.
3939
""",
40-
"resolved_bundletool_experimental": """\
41-
A `struct` from `ctx.resolve_tools` referencing an experimental tool to create an Apple bundle by
40+
"bundletool_experimental": """\
41+
The files_to_run for an experimental tool to create an Apple bundle by
4242
combining the bundling, post-processing, and signing steps into a single action that eliminates the
4343
archiving step.
4444
""",
45-
"resolved_clangrttool": """\
46-
A `struct` from `ctx.resolve_tools` referencing a tool to find all Clang runtime libs linked to a
45+
"clangrttool": """\
46+
The files_to_run for a tool to find all Clang runtime libs linked to a
4747
binary.
4848
""",
49-
"resolved_codesigningtool": """\
50-
A `struct` from `ctx.resolve_tools` referencing a tool to select the appropriate signing identity
49+
"codesigningtool": """\
50+
The files_to_run for a tool to select the appropriate signing identity
5151
for Apple apps and Apple executable bundles.
5252
""",
53-
"resolved_dossier_codesigningtool": """\
54-
A `struct` from `ctx.resolve_tools` referencing a tool to generate codesigning dossiers.
53+
"dossier_codesigningtool": """\
54+
The files_to_run for a tool to generate codesigning dossiers.
5555
""",
56-
"resolved_environment_plist_tool": """\
57-
A `struct` from `ctx.resolve_tools` referencing a tool for collecting dev environment values.
56+
"environment_plist_tool": """\
57+
The files_to_run for a tool for collecting dev environment values.
5858
""",
59-
"resolved_imported_dynamic_framework_processor": """\
60-
A `struct` from `ctx.resolve_tools` referencing a tool to process an imported dynamic framework
59+
"imported_dynamic_framework_processor": """\
60+
The files_to_run for a tool to process an imported dynamic framework
6161
such that the given framework only contains the same slices as the app binary, every file belonging
6262
to the dynamic framework is copied to a temporary location, and the dynamic framework is codesigned
6363
and zipped as a cacheable artifact.
6464
""",
65-
"resolved_main_thread_checker_tool": """\
66-
A `struct` from `ctx.resolve_tools` referencing a tool to find libMainThreadChecker.dylib linked to a
65+
"main_thread_checker_tool": """\
66+
The files_to_run for a tool to find libMainThreadChecker.dylib linked to a
6767
binary.
6868
""",
69-
"resolved_plisttool": """\
70-
A `struct` from `ctx.resolve_tools` referencing a tool to perform plist operations such as variable
69+
"plisttool": """\
70+
The files_to_run for a tool to perform plist operations such as variable
7171
substitution, merging, and conversion of plist files to binary format.
7272
""",
73-
"resolved_provisioning_profile_tool": """\
74-
A `struct` from `ctx.resolve_tools` referencing a tool that extracts entitlements from a
73+
"provisioning_profile_tool": """\
74+
The files_to_run for a tool that extracts entitlements from a
7575
provisioning profile.
7676
""",
77-
"resolved_swift_stdlib_tool": """\
78-
A `struct` from `ctx.resolve_tools` referencing a tool that copies and lipos Swift stdlibs required
77+
"swift_stdlib_tool": """\
78+
The files_to_run for a tool that copies and lipos Swift stdlibs required
7979
for the target to run.
8080
""",
81-
"resolved_xcframework_processor_tool": """\
82-
A `struct` from `ctx.resolve_tools` referencing a tool that extracts and copies an XCFramework
81+
"xcframework_processor_tool": """\
82+
The files_to_run for a tool that extracts and copies an XCFramework
8383
library for a target triplet.
8484
""",
85-
"resolved_xctoolrunner": """\
86-
A `struct` from `ctx.resolve_tools` referencing a tool that acts as a wrapper for xcrun actions.
85+
"xctoolrunner": """\
86+
The files_to_run for a tool that acts as a wrapper for xcrun actions.
8787
""",
8888
},
8989
)
@@ -106,12 +106,12 @@ target name and values are retrieved from the BuildSettingInfo provider for each
106106
107107
e.g. apple_xplat_tools_toolchaininfo.build_settings.signing_certificate_name
108108
""",
109-
"resolved_bundletool": """\
110-
A `struct` from `ctx.resolve_tools` referencing a tool to create an Apple bundle by taking a list of
109+
"bundletool": """\
110+
A files_to_run for a tool to create an Apple bundle by taking a list of
111111
files/ZIPs and destinations paths to build the directory structure for those files.
112112
""",
113-
"resolved_versiontool": """\
114-
A `struct` from `ctx.resolve_tools` referencing a tool that acts as a wrapper for xcrun actions.
113+
"versiontool": """\
114+
A files_to_run for a tool that acts as a wrapper for xcrun actions.
115115
""",
116116
},
117117
)
@@ -131,79 +131,24 @@ def _shared_attrs():
131131
),
132132
}
133133

134-
def _resolve_tools_for_executable(*, rule_ctx, attr_name):
135-
"""Helper macro to resolve executable runfile dependencies across the rule boundary."""
136-
137-
# TODO(b/111036105) Migrate away from this helper and its outputs once ctx.executable works
138-
# across rule boundaries.
139-
executable = getattr(rule_ctx.executable, attr_name)
140-
target = getattr(rule_ctx.attr, attr_name)
141-
files_to_run = target[DefaultInfo].files_to_run
142-
inputs, input_manifests = rule_ctx.resolve_tools(tools = [target])
143-
return struct(
144-
executable = executable,
145-
files_to_run = files_to_run,
146-
inputs = inputs,
147-
input_manifests = input_manifests,
148-
)
149-
150134
def _apple_mac_tools_toolchain_impl(ctx):
151135
return [
152136
AppleMacToolsToolchainInfo(
153137
dsym_info_plist_template = ctx.file.dsym_info_plist_template,
154138
process_and_sign_template = ctx.file.process_and_sign_template,
155-
resolved_alticonstool = _resolve_tools_for_executable(
156-
attr_name = "alticonstool",
157-
rule_ctx = ctx,
158-
),
159-
resolved_bundletool_experimental = _resolve_tools_for_executable(
160-
attr_name = "bundletool_experimental",
161-
rule_ctx = ctx,
162-
),
163-
resolved_codesigningtool = _resolve_tools_for_executable(
164-
attr_name = "codesigningtool",
165-
rule_ctx = ctx,
166-
),
167-
resolved_dossier_codesigningtool = _resolve_tools_for_executable(
168-
attr_name = "dossier_codesigningtool",
169-
rule_ctx = ctx,
170-
),
171-
resolved_clangrttool = _resolve_tools_for_executable(
172-
attr_name = "clangrttool",
173-
rule_ctx = ctx,
174-
),
175-
resolved_main_thread_checker_tool = _resolve_tools_for_executable(
176-
attr_name = "main_thread_checker_tool",
177-
rule_ctx = ctx,
178-
),
179-
resolved_environment_plist_tool = _resolve_tools_for_executable(
180-
attr_name = "environment_plist_tool",
181-
rule_ctx = ctx,
182-
),
183-
resolved_imported_dynamic_framework_processor = _resolve_tools_for_executable(
184-
attr_name = "imported_dynamic_framework_processor",
185-
rule_ctx = ctx,
186-
),
187-
resolved_plisttool = _resolve_tools_for_executable(
188-
attr_name = "plisttool",
189-
rule_ctx = ctx,
190-
),
191-
resolved_provisioning_profile_tool = _resolve_tools_for_executable(
192-
attr_name = "provisioning_profile_tool",
193-
rule_ctx = ctx,
194-
),
195-
resolved_swift_stdlib_tool = _resolve_tools_for_executable(
196-
attr_name = "swift_stdlib_tool",
197-
rule_ctx = ctx,
198-
),
199-
resolved_xcframework_processor_tool = _resolve_tools_for_executable(
200-
attr_name = "xcframework_processor_tool",
201-
rule_ctx = ctx,
202-
),
203-
resolved_xctoolrunner = _resolve_tools_for_executable(
204-
attr_name = "xctoolrunner",
205-
rule_ctx = ctx,
206-
),
139+
alticonstool = ctx.attr.alticonstool.files_to_run,
140+
bundletool_experimental = ctx.attr.bundletool_experimental.files_to_run,
141+
codesigningtool = ctx.attr.codesigningtool.files_to_run,
142+
dossier_codesigningtool = ctx.attr.dossier_codesigningtool.files_to_run,
143+
clangrttool = ctx.attr.clangrttool.files_to_run,
144+
main_thread_checker_tool = ctx.attr.main_thread_checker_tool.files_to_run,
145+
environment_plist_tool = ctx.attr.environment_plist_tool.files_to_run,
146+
imported_dynamic_framework_processor = ctx.attr.imported_dynamic_framework_processor.files_to_run,
147+
plisttool = ctx.attr.plisttool.files_to_run,
148+
provisioning_profile_tool = ctx.attr.provisioning_profile_tool.files_to_run,
149+
swift_stdlib_tool = ctx.attr.swift_stdlib_tool.files_to_run,
150+
xcframework_processor_tool = ctx.attr.xcframework_processor_tool.files_to_run,
151+
xctoolrunner = ctx.attr.xctoolrunner.files_to_run,
207152
),
208153
DefaultInfo(),
209154
]
@@ -321,14 +266,8 @@ def _apple_xplat_tools_toolchain_impl(ctx):
321266
for build_setting in ctx.attr.build_settings
322267
}
323268
),
324-
resolved_bundletool = _resolve_tools_for_executable(
325-
attr_name = "bundletool",
326-
rule_ctx = ctx,
327-
),
328-
resolved_versiontool = _resolve_tools_for_executable(
329-
attr_name = "versiontool",
330-
rule_ctx = ctx,
331-
),
269+
bundletool = ctx.attr.bundletool.files_to_run,
270+
versiontool = ctx.attr.versiontool.files_to_run,
332271
),
333272
DefaultInfo(),
334273
]

apple/internal/apple_xcframework_import.bzl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,14 @@ def _get_xcframework_library_with_xcframework_processor(
347347
)
348348
outputs.append(swiftinterface_file)
349349

350-
xcframework_processor_tool = apple_mac_toolchain_info.resolved_xcframework_processor_tool
350+
xcframework_processor_tool = apple_mac_toolchain_info.xcframework_processor_tool
351351

352352
apple_support.run(
353353
actions = actions,
354354
apple_fragment = apple_fragment,
355355
arguments = [args],
356-
executable = xcframework_processor_tool.files_to_run,
357-
inputs = depset(
358-
inputs,
359-
transitive = [xcframework_processor_tool.inputs],
360-
),
361-
input_manifests = xcframework_processor_tool.input_manifests,
356+
executable = xcframework_processor_tool,
357+
inputs = inputs,
362358
mnemonic = "ProcessXCFrameworkFiles",
363359
outputs = outputs,
364360
xcode_config = xcode_config,

0 commit comments

Comments
 (0)