Skip to content

Commit

Permalink
Represent structured resources as files instead of folders in Xcode
Browse files Browse the repository at this point in the history
The current way matches how Xcode bundles structured resources, and we did it this way for BwX mode. But representing these resources as folders has a few downsides:

1. More files can appear in Xcode than are actually referenced as inputs, because Bazel works on the level of files, not directories
2. The work to translate the files to folder paths isn’t free
3. The translation of files to folder paths broke with rules_apple’s recent runfiles support

In a future change I’ll remove all of the code around `.isFolder`, since folder-type files can go down the `file_path` path.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones committed Oct 28, 2024
1 parent f20bd24 commit 4f5c797
Showing 1 changed file with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions xcodeproj/internal/files/incremental_resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ load("@build_bazel_rules_apple//apple:resources.bzl", "resources_common")
load("//xcodeproj/internal:configuration.bzl", "calculate_configuration")
load("//xcodeproj/internal:memory_efficiency.bzl", "memory_efficient_depset")
load("//xcodeproj/internal:target_id.bzl", "get_id")
load(":files.bzl", "join_paths_ignoring_empty")

# Utility

Expand Down Expand Up @@ -207,51 +206,18 @@ def _add_structured_resources_to_bundle(
bundle,
*,
files,
focused_resource_short_paths,
nested_path):
if nested_path:
inner_dir = nested_path.split("/")[0]
else:
inner_dir = None

focused_resource_short_paths):
for file in files.to_list():
if file.short_path not in focused_resource_short_paths:
continue

if not inner_dir:
bundle.resources.append(file)
continue

# Special case for localized
if inner_dir.endswith(".lproj"):
bundle.resources.append(file)
continue

if file.is_directory:
dir = file.path
else:
dir = file.dirname

if not dir.endswith(nested_path):
continue

folder_path = paths.join(dir[:-(1 + len(nested_path))], inner_dir)
if file.is_source:
bundle.folder_resources.append(folder_path)
else:
bundle.generated_folder_resources.append(
struct(
owner = file.owner,
path = folder_path,
),
)
bundle.resources.append(file)

def _add_structured_resources(
*,
bundle_path,
files,
focused_resource_short_paths,
nested_path,
resource_bundle_targets,
root_bundle):
bundle = resource_bundle_targets.get(bundle_path)
Expand All @@ -268,14 +234,12 @@ def _add_structured_resources(
bundle,
files = files,
focused_resource_short_paths = focused_resource_short_paths,
nested_path = nested_path,
)
else:
_add_structured_resources_to_bundle(
root_bundle,
files = files,
focused_resource_short_paths = focused_resource_short_paths,
nested_path = join_paths_ignoring_empty(bundle_path, nested_path),
)

def _handle_processable_resources(
Expand Down Expand Up @@ -386,18 +350,15 @@ def _handle_unprocessed_resources(
continue

bundle_path = None
nested_path = parent_dir
for parent_bundle_path in parent_bundle_paths:
if parent_dir.startswith(parent_bundle_path):
bundle_path = parent_bundle_path
nested_path = parent_dir[len(bundle_path) + 1:]
break

_add_structured_resources(
bundle_path = bundle_path,
files = files,
focused_resource_short_paths = focused_resource_short_paths,
nested_path = nested_path,
resource_bundle_targets = resource_bundle_targets,
root_bundle = root_bundle,
)
Expand Down

0 comments on commit 4f5c797

Please sign in to comment.