Skip to content

Commit 4d9104d

Browse files
authored
support processing string catalogs (xcstrings) (#2645)
1 parent f41bc2c commit 4d9104d

File tree

26 files changed

+554
-1
lines changed

26 files changed

+554
-1
lines changed

apple/internal/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ bzl_library(
493493
"//apple/internal/resource_actions:plist",
494494
"//apple/internal/resource_actions:png",
495495
"//apple/internal/resource_actions:texture_atlas",
496+
"//apple/internal/resource_actions:xcstrings",
496497
],
497498
)
498499

apple/internal/aspects/resource_aspect.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def _apple_resource_aspect_impl(target, ctx):
305305
# Avoid processing PNG files that are referenced through the structured_resources
306306
# attribute. This is mostly for legacy reasons and should get cleaned up in the future.
307307
bucketized_owners, unowned_resources, buckets = resources.bucketize_data(
308-
allowed_buckets = ["strings", "plists"],
308+
allowed_buckets = ["strings", "plists", "xcstrings"],
309309
owner = owner,
310310
parent_dir_param = structured_parent_dir_param,
311311
resources = structured_files,

apple/internal/partials/support/resources_support.bzl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,43 @@ def _xibs(
774774
processed_origins = processed_origins,
775775
)
776776

777+
def _xcstrings(
778+
*,
779+
actions,
780+
apple_mac_toolchain_info,
781+
files,
782+
output_discriminator,
783+
parent_dir,
784+
platform_prerequisites,
785+
rule_label,
786+
**_kwargs):
787+
"""Process xcstrings files."""
788+
lproj_files = []
789+
processed_origins = {}
790+
for file in files.to_list():
791+
basename = paths.replace_extension(file.basename, "")
792+
out_path = paths.join("xcstrings", parent_dir or "", basename)
793+
out_dir = intermediates.directory(
794+
actions = actions,
795+
target_name = rule_label.name,
796+
output_discriminator = output_discriminator,
797+
dir_name = out_path,
798+
)
799+
processed_origins[out_dir.short_path] = [file.short_path]
800+
resource_actions.compile_xcstrings(
801+
actions = actions,
802+
input_file = file,
803+
output_dir = out_dir,
804+
platform_prerequisites = platform_prerequisites,
805+
xctoolrunner = apple_mac_toolchain_info.xctoolrunner,
806+
)
807+
lproj_files.append(out_dir)
808+
809+
return struct(
810+
files = [(processor.location.resource, parent_dir, depset(lproj_files))],
811+
processed_origins = processed_origins,
812+
)
813+
777814
def _noop(
778815
*,
779816
parent_dir,
@@ -834,5 +871,6 @@ PROVIDER_TO_FIELD_ACTION = {
834871
"strings": (_plists_and_strings, False),
835872
"texture_atlases": (_texture_atlases, False),
836873
"unprocessed": (_noop, False),
874+
"xcstrings": (_xcstrings, False),
837875
"xibs": (_xibs, True),
838876
}

apple/internal/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ Xcode 26+.""",
441441
"strings": "Localization strings files.",
442442
"texture_atlases": "Texture atlas files.",
443443
"unprocessed": "Generic resources not mapped to the other types.",
444+
"xcstrings": "String catalog files.",
444445
"xibs": "XIB Interface files.",
445446
"owners": """`depset` of (resource, owner) pairs.""",
446447
"processed_origins": """`depset` of (processed resource, resource list) pairs.""",

apple/internal/resource_actions.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ load(
5858
"//apple/internal/resource_actions:texture_atlas.bzl",
5959
_compile_texture_atlas = "compile_texture_atlas",
6060
)
61+
load(
62+
"//apple/internal/resource_actions:xcstrings.bzl",
63+
_compile_xcstrings = "compile_xcstrings",
64+
)
6165

6266
resource_actions = struct(
6367
compile_asset_catalog = _compile_asset_catalog,
@@ -68,6 +72,7 @@ resource_actions = struct(
6872
compile_plist = _compile_plist,
6973
compile_storyboard = _compile_storyboard,
7074
compile_texture_atlas = _compile_texture_atlas,
75+
compile_xcstrings = _compile_xcstrings,
7176
compile_xib = _compile_xib,
7277
copy_png = _copy_png,
7378
generate_datamodels = _generate_datamodels,

apple/internal/resource_actions/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ bzl_library(
135135
],
136136
)
137137

138+
bzl_library(
139+
name = "xcstrings",
140+
srcs = ["xcstrings.bzl"],
141+
visibility = [
142+
"//apple/internal:__pkg__",
143+
],
144+
deps = [
145+
"//apple/internal/utils:xctoolrunner",
146+
"@build_bazel_apple_support//lib:apple_support",
147+
],
148+
)
149+
138150
# Consumed by bazel tests.
139151
filegroup(
140152
name = "for_bazel_tests",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""xcstrings related actions."""
2+
3+
load(
4+
"@build_bazel_apple_support//lib:apple_support.bzl",
5+
"apple_support",
6+
)
7+
load(
8+
"//apple/internal/utils:xctoolrunner.bzl",
9+
xctoolrunner_support = "xctoolrunner",
10+
)
11+
12+
def compile_xcstrings(
13+
*,
14+
actions,
15+
input_file,
16+
output_dir,
17+
platform_prerequisites,
18+
xctoolrunner):
19+
args = [
20+
"xcstringstool",
21+
"compile",
22+
"--output-directory",
23+
xctoolrunner_support.prefixed_path(output_dir.path),
24+
xctoolrunner_support.prefixed_path(input_file.path),
25+
]
26+
27+
apple_support.run(
28+
actions = actions,
29+
apple_fragment = platform_prerequisites.apple_fragment,
30+
arguments = args,
31+
executable = xctoolrunner,
32+
inputs = [input_file],
33+
mnemonic = "CompileXCStrings",
34+
outputs = [output_dir],
35+
xcode_config = platform_prerequisites.xcode_version_config,
36+
)

apple/internal/resource_rules/apple_precompiled_resource_bundle.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def _apple_precompiled_resource_bundle_impl(ctx):
169169
"storyboards",
170170
"strings",
171171
"texture_atlases",
172+
"xcstrings",
172173
"xibs",
173174
],
174175
unowned_resources = unowned_resources,

apple/internal/resources.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def _bucketize_data(
250250
bucket_name = "framework"
251251
elif resource_short_path.endswith(".strings") or resource_short_path.endswith(".stringsdict"):
252252
bucket_name = "strings"
253+
elif resource_short_path.endswith(".xcstrings"):
254+
bucket_name = "xcstrings"
253255
elif resource_short_path.endswith(".storyboard"):
254256
bucket_name = "storyboards"
255257
resource_swift_module = swift_module

doc/providers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ Provider that propagates buckets of resources that are differentiated by type.
500500
| <a id="AppleResourceInfo-strings"></a>strings | Localization strings files. |
501501
| <a id="AppleResourceInfo-texture_atlases"></a>texture_atlases | Texture atlas files. |
502502
| <a id="AppleResourceInfo-unprocessed"></a>unprocessed | Generic resources not mapped to the other types. |
503+
| <a id="AppleResourceInfo-xcstrings"></a>xcstrings | String catalog files. |
503504
| <a id="AppleResourceInfo-xibs"></a>xibs | XIB Interface files. |
504505
| <a id="AppleResourceInfo-owners"></a>owners | `depset` of (resource, owner) pairs. |
505506
| <a id="AppleResourceInfo-processed_origins"></a>processed_origins | `depset` of (processed resource, resource list) pairs. |

0 commit comments

Comments
 (0)