Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions swift/internal/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _apply_action_configs(
A `ConfigResultInfo` value that contains the files that are required
inputs of the action, as determined by the configurators.
"""
additional_tools = []
inputs = []
transitive_inputs = []

Expand Down Expand Up @@ -82,26 +83,32 @@ def _apply_action_configs(
should_apply_configurators = False
break

if not should_apply_configurators:
continue

# If one of the feature lists is completely satisfied, invoke the
# configurators.
if should_apply_configurators:
for configurator in action_config.configurators:
action_inputs = configurator(prerequisites, args)

# If we create an action configurator from a lambda that calls
# `Args.add*`, the result will be the `Args` objects (rather
# than `None`) because those methods return the same `Args`
# object for chaining. We can guard against this (and possibly
# other errors) by checking that the value is a struct. If it
# is, then it's not `None` and it probably came from the
# provider used by `ConfigResultInfo`. If it's some other kind
# of struct, then we'll error out trying to access the fields.
if type(action_inputs) == "struct":
inputs.extend(action_inputs.inputs)
transitive_inputs.extend(action_inputs.transitive_inputs)
for configurator in action_config.configurators:
action_inputs = configurator(prerequisites, args)

# If we create an action configurator from a lambda that calls
# `Args.add*`, the result will be the `Args` objects (rather than
# `None`) because those methods return the same `Args` object for
# chaining. We can guard against this (and possibly other errors) by
# checking that the value is a struct. If it is, then it's not
# `None` and it probably came from the provider used by
# `ConfigResultInfo`. If it's some other kind of struct, then we'll
# error out trying to access the fields.
if not type(action_inputs) == "struct":
continue

additional_tools.extend(action_inputs.additional_tools)
inputs.extend(action_inputs.inputs)
transitive_inputs.extend(action_inputs.transitive_inputs)

# Merge the action results into a single result that we return.
return ConfigResultInfo(
additional_tools = additional_tools,
inputs = inputs,
transitive_inputs = transitive_inputs,
)
Expand Down Expand Up @@ -219,7 +226,10 @@ def run_toolchain_action(
),
mnemonic = mnemonic if mnemonic else action_name,
resource_set = tool_config.resource_set,
tools = tools,
tools = depset(
tools,
transitive = action_inputs.additional_tools,
),
use_default_shell_env = USE_DEFAULT_SHELL_ENV,
**kwargs
)
14 changes: 11 additions & 3 deletions swift/toolchains/config/action_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ def _action_config_init(
"not_features": _normalize_action_config_features(not_features),
}

def _config_result_init(*, inputs = [], transitive_inputs = []):
def _config_result_init(
*,
additional_tools = [],
inputs = [],
transitive_inputs = []):
"""Validates and initializes an action configurator result.

Args:
additional_tools: A list of `depset`s of `File`s that should be passed
as additional tool inputs to the action being configured.
inputs: A list of `File`s that should be passed as inputs to the action
being configured.
transitive_inputs: A list of `depset`s of `File`s that should be passed
Expand All @@ -131,6 +137,7 @@ def _config_result_init(*, inputs = [], transitive_inputs = []):
A new config result that can be returned from a configurator.
"""
return {
"additional_tools": additional_tools,
"inputs": inputs,
"transitive_inputs": transitive_inputs,
}
Expand Down Expand Up @@ -184,8 +191,9 @@ ActionConfigInfo, _action_config_init_unchecked = provider(
ConfigResultInfo, _config_result_init_unchecked = provider(
doc = "The inputs required by an action configurator.",
fields = [
"inputs",
"transitive_inputs",
"additional_tools", # List[depset[File]]
"inputs", # list[File]
"transitive_inputs", # List[depset[File]]
],
init = _config_result_init,
)
12 changes: 9 additions & 3 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,21 @@ def compile_action_configs(
]

if generated_header_rewriter:
# Only add the generated header rewriter to the command line only if the
# toolchain provides one, the relevant feature is requested, and the
# particular compilation action is generating a header.
# Only add the generated header rewriter to the command line and to the
# action's tool inputs only if the toolchain provides one, the relevant
# feature is requested, and the particular compilation action is
# generating a header.
def generated_header_rewriter_configurator(prerequisites, args):
additional_tools = []
if prerequisites.generated_header_file:
additional_tools.append(depset([generated_header_rewriter]))
args.add(
generated_header_rewriter,
format = "-Xwrapped-swift=-generated-header-rewriter=%s",
)
return ConfigResultInfo(
additional_tools = additional_tools,
)

action_configs.append(
ActionConfigInfo(
Expand Down
13 changes: 1 addition & 12 deletions swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ def _all_tool_configs(
custom_toolchain,
env,
execution_requirements,
generated_header_rewriter,
swift_executable,
toolchain_root):
"""Returns the tool configurations for the Swift toolchain.
Expand All @@ -500,8 +499,6 @@ def _all_tool_configs(
one was requested.
env: The environment variables to set when launching tools.
execution_requirements: The execution requirements for tools.
generated_header_rewriter: The optional executable that will be invoked
after compilation to rewrite the generated header.
swift_executable: A custom Swift driver executable to be used during the
build, if provided.
toolchain_root: The root directory of the toolchain, if provided.
Expand All @@ -525,9 +522,6 @@ def _all_tool_configs(
}

tool_config = ToolConfigInfo(
additional_tools = (
[generated_header_rewriter] if generated_header_rewriter else []
),
driver_config = _driver_config(mode = "swiftc"),
env = env,
execution_requirements = execution_requirements,
Expand All @@ -551,9 +545,6 @@ def _all_tool_configs(
),
SWIFT_ACTION_COMPILE_MODULE_INTERFACE: (
ToolConfigInfo(
additional_tools = (
[generated_header_rewriter] if generated_header_rewriter else []
),
driver_config = _driver_config(mode = "swiftc"),
args = ["-frontend"],
env = env,
Expand Down Expand Up @@ -739,7 +730,6 @@ def _xcode_swift_toolchain_impl(ctx):
custom_toolchain = custom_toolchain,
env = env,
execution_requirements = execution_requirements,
generated_header_rewriter = generated_header_rewriter,
swift_executable = swift_executable,
toolchain_root = toolchain_root,
)
Expand Down Expand Up @@ -897,8 +887,7 @@ generated header.

This tool is expected to have a command line interface such that the Swift
compiler invocation is passed to it following a `"--"` argument, and any
arguments preceding the `"--"` can be defined by the tool itself (however, at
this time the worker does not support passing additional flags to the tool).
arguments preceding the `"--"` can be defined by the tool itself.
""",
executable = True,
),
Expand Down