Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support product module name #1

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions apple/internal/aspects/resource_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def _apple_resource_aspect_impl(target, ctx):
process_args["bundle_id"] = ctx.rule.attr.bundle_id or None
bundle_name = "{}.bundle".format(ctx.rule.attr.bundle_name or ctx.label.name)

# Passing product_module_name to swift_module `bucketize_args`
# so `resources.bucketize_data` function can couple xib with custom `product_module_name`
bucketize_args["swift_module"] = ctx.rule.attr.product_module_name or None

# Collect all resource files related to this target.
if collect_infoplists_args:
infoplists = resources.collect(
Expand Down
13 changes: 13 additions & 0 deletions apple/internal/partials/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def _resources_partial_impl(
locales_included = sets.make(["Base"])
locales_dropped = sets.make()

product_module_names = []
product_module_name_index = 0

if hasattr(final_provider,'xibs'):
for bundle, _, _ in final_provider.xibs:
product_module_name = bundle or bundle_name
product_module_names.append(product_module_name.replace("Resources.bundle",""))

def _deduplicated_field_handler(field, deduplicated):
processing_func, requires_swift_module = provider_field_to_action[field]
for parent_dir, swift_module, files in deduplicated:
Expand Down Expand Up @@ -259,6 +267,11 @@ def _resources_partial_impl(
# requires it.
if requires_swift_module:
processing_args["swift_module"] = swift_module
# if custom product_module_name from apple_bundle resource is empty
elif field == "xibs" and swift_module == None:
module_name = product_module_names[product_module_name_index]
processing_args["swift_module"] = module_name
product_module_name_index = product_module_name_index + 1

result = processing_func(**processing_args)
bundle_files.extend(result.files)
Expand Down
6 changes: 6 additions & 0 deletions apple/internal/resource_rules/apple_resource_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ from defined in the `infoplists` paramter.
The desired name of the bundle (without the `.bundle` extension). If this attribute is not set,
then the `name` of the target will be used instead.
""",
),
"product_module_name": attr.string(
doc = """
This Product Module Name Attr is created to facilitate the legacy product_module_name on our Codebase.
if left empty, will fetch use bundle_name without `Resources.bundle`.
for example FooResources, then it will be `Foo`""",
),
"infoplists": attr.label_list(
allow_empty = True,
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _bucketize(
**buckets
)

def _bucketize_typed_data(*, bucket_type, owner = None, parent_dir_param = None, resources):
def _bucketize_typed_data(*, bucket_type, owner = None, parent_dir_param = None, resources, swift_module = None):
"""Collects and bucketizes a specific type of resource.

Adds the given resources directly into a tuple under the field named in bucket_type. This avoids
Expand Down