Skip to content

Commit e930d52

Browse files
luispadronnglevin
andauthored
Use actions.args() for handling remaining actions.run* arguments. (#2779)
PiperOrigin-RevId: 803012867 Cherry-pick: 8071945 Co-authored-by: Nicholas Levin <[email protected]>
1 parent 1e45668 commit e930d52

File tree

6 files changed

+73
-92
lines changed

6 files changed

+73
-92
lines changed

apple/internal/partials/swift_dylibs.bzl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,22 @@ def _swift_dylib_action(
8585
strip_bitcode,
8686
swift_stdlib_tool):
8787
"""Registers a swift-stlib-tool action to gather Swift dylibs to bundle."""
88-
swift_stdlib_tool_args = [
89-
"--platform",
90-
platform_name,
91-
"--output_path",
92-
output_dir.path,
93-
]
94-
for x in binary_files:
95-
swift_stdlib_tool_args.extend([
96-
"--binary",
97-
x.path,
98-
])
88+
89+
swift_stdlib_tool_args = actions.args()
90+
swift_stdlib_tool_args.add("--platform", platform_name)
91+
swift_stdlib_tool_args.add("--output_path", output_dir.path)
92+
swift_stdlib_tool_args.add_all(
93+
binary_files,
94+
before_each = "--binary",
95+
)
9996

10097
if strip_bitcode:
101-
swift_stdlib_tool_args.append("--strip_bitcode")
98+
swift_stdlib_tool_args.add("--strip_bitcode")
10299

103100
apple_support.run(
104101
actions = actions,
105102
apple_fragment = platform_prerequisites.apple_fragment,
106-
arguments = swift_stdlib_tool_args,
103+
arguments = [swift_stdlib_tool_args],
107104
executable = swift_stdlib_tool,
108105
inputs = binary_files,
109106
mnemonic = "SwiftStdlibCopy",

apple/internal/resource_actions/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ bzl_library(
1717
"//apple:utils",
1818
"//apple/internal:apple_product_type",
1919
"//apple/internal/utils:xctoolrunner",
20-
"@bazel_skylib//lib:collections",
2120
"@bazel_skylib//lib:paths",
2221
"@bazel_skylib//lib:sets",
2322
"@build_bazel_apple_support//lib:apple_support",
@@ -56,7 +55,6 @@ bzl_library(
5655
],
5756
deps = [
5857
"//apple/internal/utils:xctoolrunner",
59-
"@bazel_skylib//lib:collections",
6058
"@bazel_skylib//lib:paths",
6159
"@build_bazel_apple_support//lib:apple_support",
6260
],

apple/internal/resource_actions/actool.bzl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
"""ACTool related actions."""
1616

17-
load(
18-
"@bazel_skylib//lib:collections.bzl",
19-
"collections",
20-
)
2117
load(
2218
"@bazel_skylib//lib:paths.bzl",
2319
"paths",
@@ -330,7 +326,8 @@ def compile_asset_catalog(
330326
platform = platform_prerequisites.platform
331327
actool_platform = platform.name_in_plist.lower()
332328

333-
args = [
329+
args = actions.args()
330+
args.add_all([
334331
"actool",
335332
"--compile",
336333
xctoolrunner_support.prefixed_path(output_dir.path),
@@ -344,7 +341,7 @@ def compile_asset_catalog(
344341
"--minimum-deployment-target",
345342
platform_prerequisites.minimum_os,
346343
"--compress-pngs",
347-
]
344+
])
348345

349346
xcode_config = platform_prerequisites.xcode_version_config
350347

@@ -353,19 +350,19 @@ def compile_asset_catalog(
353350
):
354351
# Required for the Icon Composer .icon bundles to work as inputs, even though it's not
355352
# documented. Xcode 26 currently relies on this flag to be set.
356-
args.extend(["--lightweight-asset-runtime-mode", "enabled"])
353+
args.add_all(["--lightweight-asset-runtime-mode", "enabled"])
357354

358-
args.extend(_actool_args_for_special_file_types(
355+
args.add_all(_actool_args_for_special_file_types(
359356
asset_files = asset_files,
360357
bundle_id = bundle_id,
361358
platform_prerequisites = platform_prerequisites,
362359
primary_icon_name = primary_icon_name,
363360
product_type = product_type,
364361
))
365-
args.extend(collections.before_each(
366-
"--target-device",
362+
args.add_all(
367363
platform_prerequisites.device_families,
368-
))
364+
before_each = "--target-device",
365+
)
369366

370367
alticons_outputs = []
371368
actool_output_plist = None
@@ -383,7 +380,7 @@ def compile_asset_catalog(
383380
actool_output_plist = output_plist
384381

385382
actool_outputs.append(actool_output_plist)
386-
args.extend([
383+
args.add_all([
387384
"--output-partial-info-plist",
388385
xctoolrunner_support.prefixed_path(actool_output_plist.path),
389386
])
@@ -394,11 +391,11 @@ def compile_asset_catalog(
394391
attr = "asset_catalogs",
395392
).keys()
396393

397-
args.extend([xctoolrunner_support.prefixed_path(xcasset) for xcasset in xcassets])
394+
args.add_all([xctoolrunner_support.prefixed_path(xcasset) for xcasset in xcassets])
398395

399396
apple_support.run(
400397
actions = actions,
401-
arguments = args,
398+
arguments = [args],
402399
apple_fragment = platform_prerequisites.apple_fragment,
403400
executable = xctoolrunner,
404401
execution_requirements = {"no-sandbox": "1"},

apple/internal/resource_actions/datamodel.bzl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,14 @@ def compile_mappingmodel(
8686
platform_prerequisites: Struct containing information on the platform being targeted.
8787
xctoolrunner: A files_to_run for the wrapper around the "xcrun" tool.
8888
"""
89-
args = [
90-
"mapc",
91-
xctoolrunner_support.prefixed_path(mappingmodel_path),
92-
xctoolrunner_support.prefixed_path(output_file.path),
93-
]
89+
args = actions.args()
90+
args.add("mapc")
91+
args.add(xctoolrunner_support.prefixed_path(mappingmodel_path))
92+
args.add(xctoolrunner_support.prefixed_path(output_file.path))
9493

9594
apple_support.run(
9695
actions = actions,
97-
arguments = args,
96+
arguments = [args],
9897
apple_fragment = platform_prerequisites.apple_fragment,
9998
executable = xctoolrunner,
10099
inputs = input_files,

apple/internal/resource_actions/ibtool.bzl

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
"""IBTool related actions."""
1616

17-
load(
18-
"@bazel_skylib//lib:collections.bzl",
19-
"collections",
20-
)
2117
load(
2218
"@bazel_skylib//lib:paths.bzl",
2319
"paths",
@@ -31,28 +27,6 @@ load(
3127
xctoolrunner_support = "xctoolrunner",
3228
)
3329

34-
def _ibtool_arguments(min_os, families):
35-
"""Returns common `ibtool` command line arguments.
36-
37-
This function returns the common arguments used by both xib and storyboard
38-
compilation, as well as storyboard linking. Callers should add their own
39-
arguments to the returned array for their specific purposes.
40-
41-
Args:
42-
min_os: The minimum OS version to use when compiling interface files.
43-
families: The families that should be supported by the compiled interfaces.
44-
45-
Returns:
46-
An array of command-line arguments to pass to ibtool.
47-
"""
48-
return [
49-
"--minimum-deployment-target",
50-
min_os,
51-
] + collections.before_each(
52-
"--target-device",
53-
families,
54-
)
55-
5630
def compile_storyboard(
5731
*,
5832
actions,
@@ -73,7 +47,8 @@ def compile_storyboard(
7347
xctoolrunner: A files_to_run for the wrapper around the "xcrun" tool.
7448
"""
7549

76-
args = [
50+
args = actions.args()
51+
args.add_all([
7752
"ibtool",
7853
"--compilation-directory",
7954
xctoolrunner_support.prefixed_path(output_dir.dirname),
@@ -83,20 +58,24 @@ def compile_storyboard(
8358
"--auto-activate-custom-fonts",
8459
"--output-format",
8560
"human-readable-text",
86-
]
61+
])
8762

8863
min_os = platform_prerequisites.minimum_os
8964
families = platform_prerequisites.device_families
90-
args.extend(_ibtool_arguments(min_os, families))
91-
args.extend([
65+
66+
# Standard ibtool options.
67+
args.add("--minimum-deployment-target", min_os)
68+
args.add_all(families, before_each = "--target-device")
69+
70+
args.add_all([
9271
"--module",
9372
swift_module,
9473
xctoolrunner_support.prefixed_path(input_file.path),
9574
])
9675

9776
apple_support.run(
9877
actions = actions,
99-
arguments = args,
78+
arguments = [args],
10079
apple_fragment = platform_prerequisites.apple_fragment,
10180
executable = xctoolrunner,
10281
execution_requirements = {"no-sandbox": "1"},
@@ -131,20 +110,25 @@ def link_storyboards(
131110
min_os = platform_prerequisites.minimum_os
132111
families = platform_prerequisites.device_families
133112

134-
args = [
113+
args = actions.args()
114+
args.add_all([
135115
"ibtool",
136116
"--link",
137117
xctoolrunner_support.prefixed_path(output_dir.path),
138-
]
139-
args.extend(_ibtool_arguments(min_os, families))
140-
args.extend([
118+
])
119+
120+
# Standard ibtool options.
121+
args.add("--minimum-deployment-target", min_os)
122+
args.add_all(families, before_each = "--target-device")
123+
124+
args.add_all([
141125
xctoolrunner_support.prefixed_path(f.path)
142126
for f in storyboardc_dirs
143127
])
144128

145129
apple_support.run(
146130
actions = actions,
147-
arguments = args,
131+
arguments = [args],
148132
apple_fragment = platform_prerequisites.apple_fragment,
149133
executable = xctoolrunner,
150134
execution_requirements = {"no-sandbox": "1"},
@@ -179,21 +163,26 @@ def compile_xib(
179163

180164
nib_name = paths.replace_extension(paths.basename(input_file.short_path), ".nib")
181165

182-
args = [
166+
args = actions.args()
167+
args.add_all([
183168
"ibtool",
184169
"--compile",
185170
xctoolrunner_support.prefixed_path(paths.join(output_dir.path, nib_name)),
186-
]
187-
args.extend(_ibtool_arguments(min_os, families))
188-
args.extend([
171+
])
172+
173+
# Standard ibtool options.
174+
args.add("--minimum-deployment-target", min_os)
175+
args.add_all(families, before_each = "--target-device")
176+
177+
args.add_all([
189178
"--module",
190179
swift_module,
191180
xctoolrunner_support.prefixed_path(input_file.path),
192181
])
193182

194183
apple_support.run(
195184
actions = actions,
196-
arguments = args,
185+
arguments = [args],
197186
apple_fragment = platform_prerequisites.apple_fragment,
198187
executable = xctoolrunner,
199188
execution_requirements = {"no-sandbox": "1"},

apple/internal/resource_actions/mlmodel.bzl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ def compile_mlmodel(
4141
platform_prerequisites: Struct containing information on the platform being targeted.
4242
xctoolrunner: A files_to_run for the wrapper around the "xcrun" tool.
4343
"""
44-
args = [
45-
"coremlc",
46-
"compile",
47-
xctoolrunner_support.prefixed_path(input_file.path),
48-
output_bundle.dirname,
44+
45+
args = actions.args()
46+
args.add("coremlc")
47+
args.add("compile")
48+
args.add(xctoolrunner_support.prefixed_path(input_file.path))
49+
args.add(output_bundle.dirname)
50+
args.add(
4951
"--output-partial-info-plist",
5052
xctoolrunner_support.prefixed_path(output_plist.path),
51-
]
53+
)
5254

5355
apple_support.run(
5456
actions = actions,
5557
apple_fragment = platform_prerequisites.apple_fragment,
56-
arguments = args,
58+
arguments = [args],
5759
executable = xctoolrunner,
5860
inputs = [input_file],
5961
mnemonic = "MlmodelCompile",
@@ -86,29 +88,28 @@ def generate_mlmodel_sources(
8688

8789
is_swift = language == "Swift"
8890

89-
arguments = [
90-
"coremlc",
91-
"generate",
92-
xctoolrunner_support.prefixed_path(input_file.path),
93-
]
91+
arguments = actions.args()
92+
arguments.add("coremlc")
93+
arguments.add("generate")
94+
arguments.add(xctoolrunner_support.prefixed_path(input_file.path))
9495

9596
outputs = []
9697
if is_swift:
97-
arguments += [
98+
arguments.add_all([
9899
"--public-access",
99100
"--language",
100101
"Swift",
101102
swift_output_src.dirname,
102-
]
103+
])
103104
outputs = [swift_output_src]
104105
else:
105-
arguments.append(objc_output_src.dirname)
106+
arguments.add(objc_output_src.dirname)
106107
outputs = [objc_output_src, objc_output_hdr]
107108

108109
apple_support.run(
109110
actions = actions,
110111
apple_fragment = platform_prerequisites.apple_fragment,
111-
arguments = arguments,
112+
arguments = [arguments],
112113
executable = xctoolrunner,
113114
inputs = [input_file],
114115
mnemonic = "MlmodelGenerate",

0 commit comments

Comments
 (0)