Skip to content

Commit

Permalink
Move write_target_ids_list to target_id.bzl (#2124)
Browse files Browse the repository at this point in the history
Anything to make `xcodeproj_rule.bzl` smaller…

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones authored Apr 26, 2023
1 parent 48ac5ab commit 78b463d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
26 changes: 26 additions & 0 deletions xcodeproj/internal/target_id.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ def get_id(*, label, configuration):
An opaque string that uniquely identifies the target.
"""
return "{} {}".format(label, configuration)

def write_target_ids_list(*, actions, name, target_dtos):
"""Writes the list of target IDs for a set of `xcode_target`s to a file.
Args:
actions: `ctx.actions`.
name: `ctx.attr.name`.
target_dtos: A `dict` with target IDs as keys.
Returns:
The `File` that was written.
"""
output = actions.declare_file(
"{}_target_ids".format(name),
)

args = actions.args()
args.set_param_file_format("multiline")
args.add_all(sorted(target_dtos.keys()))

actions.write(
output,
args,
)

return output
22 changes: 4 additions & 18 deletions xcodeproj/internal/xcodeproj_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load(":platform.bzl", "platform_info")
load(":project_options.bzl", "project_options_to_dto")
load(":providers.bzl", "XcodeProjInfo")
load(":resource_target.bzl", "process_resource_bundles")
load(":target_id.bzl", "write_target_ids_list")
load(":xcode_targets.bzl", "xcode_targets")
load(":xcodeproj_aspect.bzl", "make_xcodeproj_aspect")

Expand Down Expand Up @@ -1350,22 +1351,6 @@ echo "$execution_root" > "{out_full}"

return output

def _write_target_ids_list(*, ctx, target_dtos):
output = ctx.actions.declare_file(
"{}_target_ids".format(ctx.attr.name),
)

args = ctx.actions.args()
args.set_param_file_format("multiline")
args.add_all(sorted(target_dtos.keys()))

ctx.actions.write(
output,
args,
)

return output

def _write_xcodeproj(
*,
ctx,
Expand Down Expand Up @@ -1673,8 +1658,9 @@ configurations: {}""".format(", ".join(xcode_configurations)))
replacement_labels_by_label = replacement_labels_by_label,
inputs = inputs,
)
target_ids_list = _write_target_ids_list(
ctx = ctx,
target_ids_list = write_target_ids_list(
actions = ctx.actions,
name = ctx.attr.name,
target_dtos = target_dtos,
)

Expand Down

0 comments on commit 78b463d

Please sign in to comment.