diff --git a/test/internal/pbxproj_partials/write_files_and_groups_tests.bzl b/test/internal/pbxproj_partials/write_files_and_groups_tests.bzl index 64e465750a..b6d8770c2d 100644 --- a/test/internal/pbxproj_partials/write_files_and_groups_tests.bzl +++ b/test/internal/pbxproj_partials/write_files_and_groups_tests.bzl @@ -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, @@ -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, @@ -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), @@ -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, @@ -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, @@ -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", @@ -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 diff --git a/xcodeproj/internal/files/incremental_input_files.bzl b/xcodeproj/internal/files/incremental_input_files.bzl index c716dc7606..2587df96a8 100644 --- a/xcodeproj/internal/files/incremental_input_files.bzl +++ b/xcodeproj/internal/files/incremental_input_files.bzl @@ -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 = [ @@ -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 = [ @@ -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), @@ -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, diff --git a/xcodeproj/internal/files/incremental_resources.bzl b/xcodeproj/internal/files/incremental_resources.bzl index a075455216..c9fb3907a0 100644 --- a/xcodeproj/internal/files/incremental_resources.bzl +++ b/xcodeproj/internal/files/incremental_resources.bzl @@ -39,6 +39,7 @@ def _create_bundle(name = None): name = name, resources = [], resource_file_paths = [], + generated_resource_file_paths = [], folder_resources = [], generated_folder_resources = [], dependency_paths = [], @@ -73,19 +74,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( *, @@ -94,18 +90,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, @@ -114,9 +112,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( *, @@ -173,7 +177,7 @@ 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, @@ -181,7 +185,6 @@ def _add_processed_resources_to_bundle( 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( *, @@ -439,6 +442,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() @@ -522,6 +531,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): @@ -554,6 +565,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, ), @@ -567,6 +581,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, diff --git a/xcodeproj/internal/incremental_xcode_targets.bzl b/xcodeproj/internal/incremental_xcode_targets.bzl index e508333f07..e0b437c247 100644 --- a/xcodeproj/internal/incremental_xcode_targets.bzl +++ b/xcodeproj/internal/incremental_xcode_targets.bzl @@ -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, @@ -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, diff --git a/xcodeproj/internal/pbxproj_partials.bzl b/xcodeproj/internal/pbxproj_partials.bzl index 34f3b4639f..97e5072128 100644 --- a/xcodeproj/internal/pbxproj_partials.bzl +++ b/xcodeproj/internal/pbxproj_partials.bzl @@ -60,14 +60,14 @@ def _generated_dirname(file): return file.dirname -def _always_generated_file_path(file): +def _xcfilelist_always_generated_file_path(file): return "$(BAZEL_OUT){}".format(file.path[9:]) -def _generated_file_path(file): +def _xcfilelist_generated_file_path(file): if file.is_source: return None - return _always_generated_file_path(file) + return _xcfilelist_always_generated_file_path(file) def _source_file(file): if not file.is_source: @@ -108,10 +108,10 @@ def _generated_file(file): return _generated_file_or_folder(file.path, file.owner) -def _generated_folder(generated_folder): +def _generated_file_path(generated_file_path): return _generated_file_or_folder( - generated_folder.path, - generated_folder.owner, + generated_file_path.path, + generated_file_path.owner, ) # Partials @@ -405,6 +405,7 @@ def _write_files_and_groups( files, file_paths, folders, + generated_file_paths, generated_folders, generator_name, install_path, @@ -429,6 +430,8 @@ def _write_files_and_groups( file paths. folders: A `depset` of paths to non-generated folders to include in the project. + generated_file_paths: A `depset` of file paths to generated files to + include in the project. generated_folders: A `depset` of paths to generated folders to include in the project. generator_name: The name of the `xcodeproj` generator target. @@ -517,6 +520,10 @@ def _write_files_and_groups( generated_file_paths_args.set_param_file_format("multiline") generated_file_paths_args.add_all(files, map_each = _generated_file) + generated_file_paths_args.add_all( + generated_file_paths, + map_each = _generated_file_path, + ) actions.write(generated_file_paths_file, generated_file_paths_args) @@ -533,7 +540,7 @@ def _write_files_and_groups( generated_folder_paths_args.add_all( generated_folders, - map_each = _generated_folder, + map_each = _generated_file_path, ) actions.write(generated_folder_paths_file, generated_folder_paths_args) @@ -677,12 +684,12 @@ def _write_generated_xcfilelist( # Info.plists are tracked as build files by Xcode, so top-level targets # will fail the first time they are built if we don't track them - args.add_all(infoplists, map_each = _always_generated_file_path) + args.add_all(infoplists, map_each = _xcfilelist_always_generated_file_path) # Source files are tracked as build files by Xcode, so building targets that # directly use generated source files will fail the first time they are # built if we don't track them - args.add_all(srcs, map_each = _generated_file_path) + args.add_all(srcs, map_each = _xcfilelist_generated_file_path) xcfilelist = actions.declare_file( "{}-generated.xcfilelist".format(generator_name), diff --git a/xcodeproj/internal/xcodeproj_incremental_rule.bzl b/xcodeproj/internal/xcodeproj_incremental_rule.bzl index f2560b8b9b..fc761d0fec 100644 --- a/xcodeproj/internal/xcodeproj_incremental_rule.bzl +++ b/xcodeproj/internal/xcodeproj_incremental_rule.bzl @@ -135,12 +135,16 @@ def _collect_files( transitive_file_paths = [] transitive_files = [unsupported_extra_files] transitive_folders = [] + transitive_generated_file_paths = [] transitive_generated_folders = [] transitive_srcs = [] for xcode_target in all_targets: transitive_file_paths.append(xcode_target.inputs.extra_file_paths) transitive_files.append(xcode_target.inputs.extra_files) transitive_folders.append(xcode_target.inputs.extra_folders) + transitive_generated_file_paths.append( + xcode_target.inputs.extra_generated_file_paths, + ) transitive_generated_folders.append( xcode_target.inputs.extra_generated_folders, ) @@ -169,6 +173,7 @@ def _collect_files( transitive = transitive_files, ) folders = depset(transitive = transitive_folders) + generated_file_paths = depset(transitive = transitive_generated_file_paths) generated_folders = depset(transitive = transitive_generated_folders) return ( @@ -176,6 +181,7 @@ def _collect_files( file_paths, files, folders, + generated_file_paths, generated_folders, infoplists, srcs, @@ -376,6 +382,7 @@ def _write_project_contents( file_paths, files, folders, + generated_file_paths, generated_folders, infoplists, srcs, @@ -436,6 +443,7 @@ def _write_project_contents( files = files, file_paths = file_paths, folders = folders, + generated_file_paths = generated_file_paths, generated_folders = generated_folders, generator_name = name, install_path = install_path,