Skip to content

Commit

Permalink
Merge branch 'main' into user/corentin/main-thread-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
cerisier authored Oct 28, 2024
2 parents e5020bf + 9ed62ea commit 1353bbd
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 69 deletions.
21 changes: 21 additions & 0 deletions test/internal/pbxproj_partials/write_files_and_groups_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def _write_files_and_groups_test_impl(ctx):
)
for (path, owner) in ctx.attr.generated_files.items()
]
generated_file_paths = [
struct(
path = path,
owner = mock_actions.mock_label(owner),
)
for (path, owner) in ctx.attr.generated_file_paths.items()
]
generated_folders = [
struct(
path = path,
Expand All @@ -97,6 +104,7 @@ def _write_files_and_groups_test_impl(ctx):
files = depset(files),
file_paths = depset(ctx.attr.file_paths),
folders = depset(ctx.attr.folders),
generated_file_paths = depset(generated_file_paths),
generated_folders = depset(generated_folders),
generator_name = "a_generator_name",
install_path = ctx.attr.install_path,
Expand Down Expand Up @@ -197,6 +205,7 @@ write_files_and_groups_test = unittest.make(
"file_paths": attr.string_list(mandatory = True),
"files": attr.string_list(mandatory = True),
"folders": attr.string_list(mandatory = True),
"generated_file_paths": attr.string_dict(mandatory = True),
"generated_files": attr.string_dict(mandatory = True),
"generated_folders": attr.string_dict(mandatory = True),
"install_path": attr.string(mandatory = True),
Expand Down Expand Up @@ -231,6 +240,7 @@ def write_files_and_groups_test_suite(name):
files = [],
file_paths = [],
folders = [],
generated_file_paths = {},
generated_files = {},
generated_folders = {},
install_path,
Expand All @@ -253,6 +263,7 @@ def write_files_and_groups_test_suite(name):
files = files,
file_paths = file_paths,
folders = folders,
generated_file_paths = generated_file_paths,
generated_files = generated_files,
generated_folders = generated_folders,
install_path = install_path,
Expand Down Expand Up @@ -358,6 +369,10 @@ def write_files_and_groups_test_suite(name):
"a/path/to/a/folder",
"another/path/to/another/folder",
],
generated_file_paths = {
"bazel-out/ios-sim-config/bin/a/path/to/a/generated/file_as_file_path": "//a/path/to/a/generated",
"bazel-out/ios-sim-config/bin/another/path/to/another/generated/file_as_file_path": "//another/path/to/another/generated",
},
generated_files = {
"bazel-out/ios-sim-config/bin/a/path/to/a/generated/file": "//a/path/to/a/generated",
"bazel-out/ios-sim-config/bin/another/path/to/another/generated/file": "//another/path/to/another/generated",
Expand Down Expand Up @@ -437,6 +452,12 @@ ios-sim-config
file
another/path/to/another/generated
ios-sim-config
file_as_file_path
a/path/to/a/generated
ios-sim-config
file_as_file_path
another/path/to/another/generated
ios-sim-config
""",
_GENERATED_FOLDER_PATHS_FILE: """\
folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import PBXProj
import ToolCommon

struct GeneratedPath {
struct GeneratedPath: Hashable {
let config: String
let package: BazelPath
let path: BazelPath
Expand Down Expand Up @@ -65,6 +65,11 @@ extension Generator.ReadGeneratedFilePathsFile {
))
}

return generatedPaths

// The file can have at most 1 duplicate for each entry because of
// preprocessed resource files being represented as file paths, while
// they can also be an input to another action (e.g. codegen). Because
// of this we use a `Set` to deduplicate the paths.
return Array(Set(generatedPaths))
}
}
6 changes: 6 additions & 0 deletions xcodeproj/internal/files/incremental_input_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ def _collect_incremental_input_files(
if label not in bundle_labels
],
)
extra_generated_file_paths = memory_efficient_depset(
resources_result.generated_folder_resources,
)
extra_generated_folders = memory_efficient_depset(
resources_result.generated_folder_resources,
transitive = [
Expand All @@ -505,6 +508,7 @@ def _collect_incremental_input_files(
)
else:
extra_folders = EMPTY_DEPSET
extra_generated_file_paths = EMPTY_DEPSET
extra_generated_folders = EMPTY_DEPSET
resource_bundle_labels = memory_efficient_depset(
transitive = [
Expand Down Expand Up @@ -552,6 +556,7 @@ def _collect_incremental_input_files(
transitive = transitive_extra_files,
),
extra_folders = extra_folders,
extra_generated_file_paths = extra_generated_file_paths,
extra_generated_folders = extra_generated_folders,
infoplist = infoplist,
non_arc_srcs = memory_efficient_depset(non_arc_srcs),
Expand Down Expand Up @@ -660,6 +665,7 @@ def _collect_mixed_language_input_files(
extra_file_paths = mergeable_info.extra_file_paths,
extra_files = mergeable_info.extra_files,
extra_folders = EMPTY_DEPSET,
extra_generated_file_paths = EMPTY_DEPSET,
extra_generated_folders = EMPTY_DEPSET,
infoplist = None,
non_arc_srcs = mergeable_info.non_arc_srcs,
Expand Down
84 changes: 30 additions & 54 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 @@ -39,6 +38,7 @@ def _create_bundle(name = None):
name = name,
resources = [],
resource_file_paths = [],
generated_resource_file_paths = [],
folder_resources = [],
generated_folder_resources = [],
dependency_paths = [],
Expand Down Expand Up @@ -73,19 +73,14 @@ def _handle_processed_resource(
processed_origins,
)

file_paths = []
owner = file.owner
for short_path in origin_short_paths:
file_path = _handle_processed_resource_origin(
_handle_processed_resource_origin(
bundle = bundle,
short_path = short_path,
focused_resource_short_paths = focused_resource_short_paths,
owner = owner,
)
if file_path:
file_paths.append(file_path)

return file_paths

def _handle_processed_resource_origin(
*,
Expand All @@ -94,18 +89,20 @@ def _handle_processed_resource_origin(
focused_resource_short_paths,
owner):
if short_path not in focused_resource_short_paths:
return None
return

if short_path.startswith("../"):
file_path = "external" + short_path[2:]
else:
file_path = short_path

is_generated = file_path.startswith("bazel-out/")

# If a file is a child of a folder-type file, the parent folder-type file
# should be added to the bundle instead of the child file
folder_type_prefix = _path_folder_type_prefix(file_path)
if folder_type_prefix:
if file_path.startswith("bazel-out/"):
if is_generated:
bundle.generated_folder_resources.append(
struct(
owner = owner,
Expand All @@ -114,9 +111,15 @@ def _handle_processed_resource_origin(
)
else:
bundle.folder_resources.append(folder_type_prefix)
return None

return file_path
elif is_generated:
bundle.generated_resource_file_paths.append(
struct(
owner = owner,
path = file_path,
),
)
else:
bundle.resource_file_paths.append(file_path)

def _handle_unprocessed_resource(
*,
Expand Down Expand Up @@ -173,15 +176,14 @@ def _add_processed_resources_to_bundle(
focused_resource_short_paths,
processed_origins):
for file in files.to_list():
file_paths = _handle_processed_resource(
_handle_processed_resource(
bundle = bundle,
bundle_metadata = bundle_metadata,
bundle_path = bundle_path,
file = file,
focused_resource_short_paths = focused_resource_short_paths,
processed_origins = processed_origins,
)
bundle.resource_file_paths.extend(file_paths)

def _add_unprocessed_resources_to_bundle(
*,
Expand All @@ -207,51 +209,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 +237,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 +353,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 Expand Up @@ -439,6 +403,12 @@ def _collect_incremental_resources(
* `resources`: A `list` of two element `tuple`s. The first
element is the label of the target that owns the resource. The
second element is a `File` for a resource.
* `resource_file_paths`: A `list` of two element `tuple`s. The first
element is the label of the target that owns the resource. The
second element is a file path string of a non-generated resource.
* `generated_resource_file_paths`: A `list` of two element `tuple`s.
The first element is the label of the target that owns the resource.
The second element is a file path string of a generated resource.
* `xccurrentversions`: A `list` of `.xccurrentversion` `File`s.
"""
root_bundle = _create_bundle()
Expand Down Expand Up @@ -522,6 +492,8 @@ def _collect_incremental_resources(
for child_bundle_path in parent_bundle_paths:
bundle = resource_bundle_targets[child_bundle_path]
if (not bundle.resources and
not bundle.resource_file_paths and
not bundle.generated_resource_file_paths and
not bundle.folder_resources and
not bundle.generated_folder_resources and
not bundle.dependency_paths):
Expand Down Expand Up @@ -554,6 +526,9 @@ def _collect_incremental_resources(
resource_file_paths = memory_efficient_depset(
bundle.resource_file_paths,
),
generated_resource_file_paths = memory_efficient_depset(
bundle.generated_resource_file_paths,
),
folder_resources = memory_efficient_depset(
bundle.folder_resources,
),
Expand All @@ -567,6 +542,7 @@ def _collect_incremental_resources(
bundles = frozen_bundles,
resources = root_bundle.resources,
resource_file_paths = root_bundle.resource_file_paths,
generated_resource_file_paths = root_bundle.generated_resource_file_paths,
folder_resources = root_bundle.folder_resources,
generated_folder_resources = root_bundle.generated_folder_resources,
xccurrentversions = xccurrentversions,
Expand Down
10 changes: 6 additions & 4 deletions xcodeproj/internal/incremental_xcode_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def _from_resource_bundle(bundle):
compile_stub_needed = False,
inputs = struct(
entitlements = EMPTY_DEPSET,
extra_files = bundle.resources,
extra_file_paths = bundle.resource_file_paths,
extra_files = bundle.resources,
extra_folders = bundle.folder_resources,
extra_generated_file_paths = bundle.generated_resource_file_paths,
extra_generated_folders = bundle.generated_folder_resources,
infoplist = None,
non_arc_srcs = EMPTY_DEPSET,
Expand Down Expand Up @@ -172,16 +173,17 @@ def _make_incremental_xcode_target(

def _merge_xcode_inputs(*, dest_inputs, mergeable_info):
return struct(
extra_files = memory_efficient_depset(
transitive = [dest_inputs.extra_files, mergeable_info.extra_files],
),
extra_file_paths = memory_efficient_depset(
transitive = [
dest_inputs.extra_file_paths,
mergeable_info.extra_file_paths,
],
),
extra_files = memory_efficient_depset(
transitive = [dest_inputs.extra_files, mergeable_info.extra_files],
),
extra_folders = dest_inputs.extra_folders,
extra_generated_file_paths = dest_inputs.extra_generated_file_paths,
extra_generated_folders = dest_inputs.extra_generated_folders,
infoplist = dest_inputs.infoplist,
non_arc_srcs = mergeable_info.non_arc_srcs,
Expand Down
Loading

0 comments on commit 1353bbd

Please sign in to comment.