Skip to content

Commit

Permalink
Remove ctx.resolve_tools in favor of `ctx.actions.run(executable = …
Browse files Browse the repository at this point in the history
……)` 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.
  • Loading branch information
tjgq authored Mar 28, 2024
1 parent c00a35f commit 8cbbef1
Show file tree
Hide file tree
Showing 32 changed files with 276 additions and 398 deletions.
151 changes: 45 additions & 106 deletions apple/internal/apple_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,57 @@ A `File` referencing a plist template for dSYM bundles.
"process_and_sign_template": """\
A `File` referencing a template for a shell script to process and sign.
""",
"resolved_alticonstool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to insert alternate icons entries in the app
"alticonstool": """\
The files_to_run for a tool to insert alternate icons entries in the app
bundle's `Info.plist`.
""",
"resolved_bundletool_experimental": """\
A `struct` from `ctx.resolve_tools` referencing an experimental tool to create an Apple bundle by
"bundletool_experimental": """\
The files_to_run for an experimental tool to create an Apple bundle by
combining the bundling, post-processing, and signing steps into a single action that eliminates the
archiving step.
""",
"resolved_clangrttool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to find all Clang runtime libs linked to a
"clangrttool": """\
The files_to_run for a tool to find all Clang runtime libs linked to a
binary.
""",
"resolved_codesigningtool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to select the appropriate signing identity
"codesigningtool": """\
The files_to_run for a tool to select the appropriate signing identity
for Apple apps and Apple executable bundles.
""",
"resolved_dossier_codesigningtool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to generate codesigning dossiers.
"dossier_codesigningtool": """\
The files_to_run for a tool to generate codesigning dossiers.
""",
"resolved_environment_plist_tool": """\
A `struct` from `ctx.resolve_tools` referencing a tool for collecting dev environment values.
"environment_plist_tool": """\
The files_to_run for a tool for collecting dev environment values.
""",
"resolved_imported_dynamic_framework_processor": """\
A `struct` from `ctx.resolve_tools` referencing a tool to process an imported dynamic framework
"imported_dynamic_framework_processor": """\
The files_to_run for a tool to process an imported dynamic framework
such that the given framework only contains the same slices as the app binary, every file belonging
to the dynamic framework is copied to a temporary location, and the dynamic framework is codesigned
and zipped as a cacheable artifact.
""",
"resolved_main_thread_checker_tool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to find libMainThreadChecker.dylib linked to a
"main_thread_checker_tool": """\
The files_to_run for a tool to find libMainThreadChecker.dylib linked to a
binary.
""",
"resolved_plisttool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to perform plist operations such as variable
"plisttool": """\
The files_to_run for a tool to perform plist operations such as variable
substitution, merging, and conversion of plist files to binary format.
""",
"resolved_provisioning_profile_tool": """\
A `struct` from `ctx.resolve_tools` referencing a tool that extracts entitlements from a
"provisioning_profile_tool": """\
The files_to_run for a tool that extracts entitlements from a
provisioning profile.
""",
"resolved_swift_stdlib_tool": """\
A `struct` from `ctx.resolve_tools` referencing a tool that copies and lipos Swift stdlibs required
"swift_stdlib_tool": """\
The files_to_run for a tool that copies and lipos Swift stdlibs required
for the target to run.
""",
"resolved_xcframework_processor_tool": """\
A `struct` from `ctx.resolve_tools` referencing a tool that extracts and copies an XCFramework
"xcframework_processor_tool": """\
The files_to_run for a tool that extracts and copies an XCFramework
library for a target triplet.
""",
"resolved_xctoolrunner": """\
A `struct` from `ctx.resolve_tools` referencing a tool that acts as a wrapper for xcrun actions.
"xctoolrunner": """\
The files_to_run for a tool that acts as a wrapper for xcrun actions.
""",
},
)
Expand All @@ -106,12 +106,12 @@ target name and values are retrieved from the BuildSettingInfo provider for each
e.g. apple_xplat_tools_toolchaininfo.build_settings.signing_certificate_name
""",
"resolved_bundletool": """\
A `struct` from `ctx.resolve_tools` referencing a tool to create an Apple bundle by taking a list of
"bundletool": """\
A files_to_run for a tool to create an Apple bundle by taking a list of
files/ZIPs and destinations paths to build the directory structure for those files.
""",
"resolved_versiontool": """\
A `struct` from `ctx.resolve_tools` referencing a tool that acts as a wrapper for xcrun actions.
"versiontool": """\
A files_to_run for a tool that acts as a wrapper for xcrun actions.
""",
},
)
Expand All @@ -131,79 +131,24 @@ def _shared_attrs():
),
}

def _resolve_tools_for_executable(*, rule_ctx, attr_name):
"""Helper macro to resolve executable runfile dependencies across the rule boundary."""

# TODO(b/111036105) Migrate away from this helper and its outputs once ctx.executable works
# across rule boundaries.
executable = getattr(rule_ctx.executable, attr_name)
target = getattr(rule_ctx.attr, attr_name)
files_to_run = target[DefaultInfo].files_to_run
inputs, input_manifests = rule_ctx.resolve_tools(tools = [target])
return struct(
executable = executable,
files_to_run = files_to_run,
inputs = inputs,
input_manifests = input_manifests,
)

def _apple_mac_tools_toolchain_impl(ctx):
return [
AppleMacToolsToolchainInfo(
dsym_info_plist_template = ctx.file.dsym_info_plist_template,
process_and_sign_template = ctx.file.process_and_sign_template,
resolved_alticonstool = _resolve_tools_for_executable(
attr_name = "alticonstool",
rule_ctx = ctx,
),
resolved_bundletool_experimental = _resolve_tools_for_executable(
attr_name = "bundletool_experimental",
rule_ctx = ctx,
),
resolved_codesigningtool = _resolve_tools_for_executable(
attr_name = "codesigningtool",
rule_ctx = ctx,
),
resolved_dossier_codesigningtool = _resolve_tools_for_executable(
attr_name = "dossier_codesigningtool",
rule_ctx = ctx,
),
resolved_clangrttool = _resolve_tools_for_executable(
attr_name = "clangrttool",
rule_ctx = ctx,
),
resolved_main_thread_checker_tool = _resolve_tools_for_executable(
attr_name = "main_thread_checker_tool",
rule_ctx = ctx,
),
resolved_environment_plist_tool = _resolve_tools_for_executable(
attr_name = "environment_plist_tool",
rule_ctx = ctx,
),
resolved_imported_dynamic_framework_processor = _resolve_tools_for_executable(
attr_name = "imported_dynamic_framework_processor",
rule_ctx = ctx,
),
resolved_plisttool = _resolve_tools_for_executable(
attr_name = "plisttool",
rule_ctx = ctx,
),
resolved_provisioning_profile_tool = _resolve_tools_for_executable(
attr_name = "provisioning_profile_tool",
rule_ctx = ctx,
),
resolved_swift_stdlib_tool = _resolve_tools_for_executable(
attr_name = "swift_stdlib_tool",
rule_ctx = ctx,
),
resolved_xcframework_processor_tool = _resolve_tools_for_executable(
attr_name = "xcframework_processor_tool",
rule_ctx = ctx,
),
resolved_xctoolrunner = _resolve_tools_for_executable(
attr_name = "xctoolrunner",
rule_ctx = ctx,
),
alticonstool = ctx.attr.alticonstool.files_to_run,
bundletool_experimental = ctx.attr.bundletool_experimental.files_to_run,
codesigningtool = ctx.attr.codesigningtool.files_to_run,
dossier_codesigningtool = ctx.attr.dossier_codesigningtool.files_to_run,
clangrttool = ctx.attr.clangrttool.files_to_run,
main_thread_checker_tool = ctx.attr.main_thread_checker_tool.files_to_run,
environment_plist_tool = ctx.attr.environment_plist_tool.files_to_run,
imported_dynamic_framework_processor = ctx.attr.imported_dynamic_framework_processor.files_to_run,
plisttool = ctx.attr.plisttool.files_to_run,
provisioning_profile_tool = ctx.attr.provisioning_profile_tool.files_to_run,
swift_stdlib_tool = ctx.attr.swift_stdlib_tool.files_to_run,
xcframework_processor_tool = ctx.attr.xcframework_processor_tool.files_to_run,
xctoolrunner = ctx.attr.xctoolrunner.files_to_run,
),
DefaultInfo(),
]
Expand Down Expand Up @@ -321,14 +266,8 @@ def _apple_xplat_tools_toolchain_impl(ctx):
for build_setting in ctx.attr.build_settings
}
),
resolved_bundletool = _resolve_tools_for_executable(
attr_name = "bundletool",
rule_ctx = ctx,
),
resolved_versiontool = _resolve_tools_for_executable(
attr_name = "versiontool",
rule_ctx = ctx,
),
bundletool = ctx.attr.bundletool.files_to_run,
versiontool = ctx.attr.versiontool.files_to_run,
),
DefaultInfo(),
]
Expand Down
10 changes: 3 additions & 7 deletions apple/internal/apple_xcframework_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,14 @@ def _get_xcframework_library_with_xcframework_processor(
)
outputs.append(swiftinterface_file)

xcframework_processor_tool = apple_mac_toolchain_info.resolved_xcframework_processor_tool
xcframework_processor_tool = apple_mac_toolchain_info.xcframework_processor_tool

apple_support.run(
actions = actions,
apple_fragment = apple_fragment,
arguments = [args],
executable = xcframework_processor_tool.files_to_run,
inputs = depset(
inputs,
transitive = [xcframework_processor_tool.inputs],
),
input_manifests = xcframework_processor_tool.input_manifests,
executable = xcframework_processor_tool,
inputs = inputs,
mnemonic = "ProcessXCFrameworkFiles",
outputs = outputs,
xcode_config = xcode_config,
Expand Down
Loading

0 comments on commit 8cbbef1

Please sign in to comment.