Skip to content

Commit

Permalink
Added swift_module param in partials to use it in xibs, storyboards a…
Browse files Browse the repository at this point in the history
…nd datamodels compilation (#2335)

**What has changed❓** 
In this PR I added `swift_module` as new param to partials, so it could
be used to compile xibs, storyboards, datamodels, etc.

**Why this is needed❓**
I faced with a problem when tried to build 2 different targets with same
`module_name` and when using `precompiled_apple_resource_bundle` rule.
[rules_apple](https://github.com/bazelbuild/rules_apple) fail because of
conflicting actions when creating `Info.plist-root-control` file under
same path: `/Path/ModuleName-intermediates/Info.plist-root.control`
After this change will be merged, I'm going to create second PR to
remove `fake_rule_label` [from
precompiled_apple_resource_bundle](https://github.com/bazel-ios/rules_ios/blob/789a8625a44d62f51fb733d98470d7fea9428358/rules/precompiled_apple_resource_bundle.bzl#L53)
and plist files will be stored at:
`/Path/TargetName-intermediates/Info.plist-root.control` but the
resources are going to be compiled with proper `module_name`.

**Other notes 📓** 
Right now
[fake_rule_label](https://github.com/bazel-ios/rules_ios/blob/789a8625a44d62f51fb733d98470d7fea9428358/rules/precompiled_apple_resource_bundle.bzl#L53)
is used there as `module_name`. I think this was a workaround and it
would be good to remove it finally 🙏

---------

Co-authored-by: Timur Mustafaev <timur.mustafaev@revolut.com>
  • Loading branch information
tymurmustafaiev and Timur Mustafaev authored Jan 2, 2024
1 parent 3fdba5a commit d260bcb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apple/internal/partials/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def _resources_partial_impl(
resource_deps,
rule_descriptor,
rule_label,
swift_module,
top_level_infoplists,
top_level_resources,
targets_to_avoid,
Expand All @@ -203,6 +204,7 @@ def _resources_partial_impl(
providers.append(resources.bucketize(
owner = str(rule_label),
resources = top_level_resources,
swift_module = swift_module,
))

if top_level_infoplists:
Expand Down Expand Up @@ -263,7 +265,7 @@ def _resources_partial_impl(

def _deduplicated_field_handler(field, deduplicated):
processing_func, requires_swift_module = provider_field_to_action[field]
for parent_dir, swift_module, files in deduplicated:
for parent_dir, module_name, files in deduplicated:
if locales_requested:
locale = bundle_paths.locale_for_path(parent_dir)
if sets.contains(locales_requested, locale):
Expand Down Expand Up @@ -292,7 +294,7 @@ def _resources_partial_impl(
# Only pass the Swift module name if the type of resource to process
# requires it.
if requires_swift_module:
processing_args["swift_module"] = swift_module
processing_args["swift_module"] = swift_module or module_name

result = processing_func(**processing_args)
if hasattr(result, "files"):
Expand Down Expand Up @@ -389,6 +391,7 @@ def resources_partial(
resource_deps,
rule_descriptor,
rule_label,
swift_module = None,
targets_to_avoid = [],
top_level_infoplists = [],
top_level_resources = {},
Expand Down Expand Up @@ -427,6 +430,7 @@ def resources_partial(
resource_deps: A list of dependencies that the resource aspect has been applied to.
rule_descriptor: A rule descriptor for platform and product types from the rule context.
rule_label: The label of the target being analyzed.
swift_module: Module name to be used for xibs, storyboards and datamodels compilation.
targets_to_avoid: List of targets containing resources that should be deduplicated from the
target being processed.
top_level_infoplists: A list of collected resources found from Info.plist attributes.
Expand Down Expand Up @@ -458,6 +462,7 @@ def resources_partial(
resource_deps = resource_deps,
rule_descriptor = rule_descriptor,
rule_label = rule_label,
swift_module = swift_module,
targets_to_avoid = targets_to_avoid,
top_level_infoplists = top_level_infoplists,
top_level_resources = top_level_resources,
Expand Down

0 comments on commit d260bcb

Please sign in to comment.