diff --git a/CHANGELOG.md b/CHANGELOG.md index 6296667e9..6befc29ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,7 @@ END_UNRELEASED_TEMPLATE ### New -* TBD +* Added `--@rules_xcodeproj//xcodeproj:separate_index_build_output_base` flag to configure the generator to use a separate output base for index builds: [#3243](https://github.com/MobileNativeFoundation/rules_xcodeproj/pull/3243) ### Adjusted diff --git a/docs/usage.md b/docs/usage.md index d27db700a..12bd3c5f2 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -12,6 +12,7 @@ - [Workspace `xcodeproj.bazelrc`](#workspace-xcodeprojbazelrc) - [Workspace `.bazelrc`](#workspace-bazelrc) - [Project `xcodeproj_extra_flags.bazelrc`](#project-xcodeproj_extra_flagsbazelrc) + - [Separate the index build output base](#separate-the-index-build-output-base) - [Command-line API](#command-line-api) - [Commands](#commands) - [`build`](#build) @@ -187,6 +188,15 @@ a project `xcodeproj_extra_flags.bazelrc` file, which is loaded after the workspace `.bazelrc` file. This ensures that they override any flags set earlier, mimicking the behavior of command-line set flags taking precedence. +## Separate the index build output base + +By default, rules_xcodeproj configures Xcode to use a combined output base For +both normal builds and index builds. This is done to save disk space and improve +cache hit rates, since both types of builds can share outputs. However, if you +find that index builds are interfering with normal builds, you can disable +this behavior during project generation by setting +`--@rules_xcodeproj//xcodeproj:separate_index_build_output_base` in your bazelrc. + # Command-line API rules_xcodeproj builds targets in its own diff --git a/test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl b/test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl index c9470c595..6e82d8e99 100644 --- a/test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl +++ b/test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl @@ -62,6 +62,7 @@ def _write_pbxproj_prefix_test_impl(ctx): pre_build_script = ctx.attr.pre_build_script, project_options = ctx.attr.project_options, resolved_repositories_file = ctx.attr.resolved_repositories_file, + separate_index_build_output_base = ctx.attr.separate_index_build_output_base, target_ids_list = ctx.attr.target_ids_list, tool = None, workspace_directory = ctx.attr.workspace_directory, @@ -153,6 +154,7 @@ write_pbxproj_prefix_test = unittest.make( "pre_build_script": attr.string(), "project_options": attr.string_dict(mandatory = True), "resolved_repositories_file": attr.string(mandatory = True), + "separate_index_build_output_base": attr.bool(mandatory = True), "target_ids_list": attr.string(mandatory = True), "workspace_directory": attr.string(mandatory = True), "xcode_configurations": attr.string_list(mandatory = True), @@ -190,6 +192,7 @@ def write_pbxproj_prefix_test_suite(name): pre_build_script = None, project_options, resolved_repositories_file, + separate_index_build_output_base = False, target_ids_list, workspace_directory, xcode_configurations, @@ -215,6 +218,7 @@ def write_pbxproj_prefix_test_suite(name): pre_build_script = pre_build_script, project_options = project_options, resolved_repositories_file = resolved_repositories_file, + separate_index_build_output_base = separate_index_build_output_base, target_ids_list = target_ids_list, workspace_directory = workspace_directory, xcode_configurations = xcode_configurations, @@ -271,6 +275,8 @@ def write_pbxproj_prefix_test_suite(name): "some/path/to/legacy/index_import", # indexImport "some/path/to/index_import", + # separateIndexBuildOutputBase + "0", # resolvedRepositoriesFile "some/path/to/resolved_repositories_file", # minimumXcodeVersion @@ -316,6 +322,7 @@ def write_pbxproj_prefix_test_suite(name): "organization_name": "MobileNativeFoundation 2", }, minimum_xcode_version = "14.2.1", + separate_index_build_output_base = True, resolved_repositories_file = "some/path/to/resolved_repositories_file", target_ids_list = "a/path/to/target_ids_list", workspace_directory = "/Users/TimApple/StarBoard", @@ -340,6 +347,8 @@ def write_pbxproj_prefix_test_suite(name): "some/path/to/legacy/index_import", # indexImport "some/path/to/index_import", + # separateIndexBuildOutputBase + "1", # resolvedRepositoriesFile "some/path/to/resolved_repositories_file", # minimumXcodeVersion diff --git a/test/internal/pbxproj_partials/write_target_build_settings_tests.bzl b/test/internal/pbxproj_partials/write_target_build_settings_tests.bzl index 8dd7b7baa..405a31b3c 100644 --- a/test/internal/pbxproj_partials/write_target_build_settings_tests.bzl +++ b/test/internal/pbxproj_partials/write_target_build_settings_tests.bzl @@ -96,6 +96,7 @@ def _write_target_build_settings_test_impl(ctx): previews_include_path = ctx.attr.previews_include_path, provisioning_profile_is_xcode_managed = ctx.attr.provisioning_profile_is_xcode_managed, provisioning_profile_name = ctx.attr.provisioning_profile_name, + separate_index_build_output_base = ctx.attr.separate_index_build_output_base, swift_args = swift_args, swift_debug_settings_to_merge = swift_debug_settings_to_merge, team_id = ctx.attr.team_id, @@ -185,6 +186,7 @@ write_target_build_settings_test = unittest.make( "previews_include_path": attr.string(mandatory = True), "provisioning_profile_is_xcode_managed": attr.bool(mandatory = True), "provisioning_profile_name": attr.string(), + "separate_index_build_output_base": attr.bool(mandatory = True), "swift_debug_settings_to_merge": attr.string_list(mandatory = True), "swift_args": attr.string_list(mandatory = True), "team_id": attr.string(), @@ -229,6 +231,7 @@ def write_target_build_settings_test_suite(name): previews_include_path = "", provisioning_profile_is_xcode_managed = False, provisioning_profile_name = None, + separate_index_build_output_base = False, swift_args, swift_debug_settings_to_merge = [], team_id = None, @@ -261,6 +264,7 @@ def write_target_build_settings_test_suite(name): previews_include_path = previews_include_path, provisioning_profile_is_xcode_managed = provisioning_profile_is_xcode_managed, provisioning_profile_name = provisioning_profile_name, + separate_index_build_output_base = separate_index_build_output_base, swift_args = swift_args, swift_debug_settings_to_merge = swift_debug_settings_to_merge, team_id = team_id, @@ -338,6 +342,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -386,6 +392,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -432,6 +440,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -478,6 +488,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -531,6 +543,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -584,6 +598,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -636,6 +652,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -692,6 +710,8 @@ def write_target_build_settings_test_suite(name): "", # previewsIncludePath "", + # separateIndexBuildOutputBase + "0", ], ) @@ -717,6 +737,7 @@ def write_target_build_settings_test_suite(name): "external/repo/1.framework", ], previews_include_path = "bazel-out/swiftmodule/parent", + separate_index_build_output_base = True, swift_args = [], swift_debug_settings_to_merge = [ "transitive_debug_settings/3", @@ -771,6 +792,8 @@ def write_target_build_settings_test_suite(name): """, # previewsIncludePath "bazel-out/swiftmodule/parent", + # separateIndexBuildOutputBase + "1", ], ) diff --git a/tools/generators/pbxnativetargets/README.md b/tools/generators/pbxnativetargets/README.md index f026e20c6..856635b9a 100644 --- a/tools/generators/pbxnativetargets/README.md +++ b/tools/generators/pbxnativetargets/README.md @@ -124,7 +124,7 @@ Here is an example output: LINK_PARAMS_FILE = "$(BAZEL_OUT)/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj-params/pbxtargetdependencies_tests.25.link.params"; MACOSX_DEPLOYMENT_TARGET = 13.0; OTHER_LDFLAGS = "@$(DERIVED_FILE_DIR)/link.params"; - OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) $(PREVIEWS_SWIFT_INCLUDE__$(ENABLE_PREVIEWS)) -DDEBUG -Onone -enable-testing -F$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks -I$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/usr/lib -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/generators/lib/PBXProj -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/generators/pbxtargetdependencies -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_swift_custom_dump -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin -static -Xcc -O0 -Xcc -DDEBUG=1 -Xcc -fstack-protector -Xcc -fstack-protector-all"; + OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -Xcc -ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml -vfsoverlay $(OBJROOT)/bazel-out-overlay.yaml $(PREVIEWS_SWIFT_INCLUDE__$(ENABLE_PREVIEWS)) -DDEBUG -Onone -enable-testing -F$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks -I$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/usr/lib -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/generators/lib/PBXProj -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/generators/pbxtargetdependencies -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_swift_custom_dump -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin -static -Xcc -O0 -Xcc -DDEBUG=1 -Xcc -fstack-protector -Xcc -fstack-protector-all"; PREVIEWS_SWIFT_INCLUDE__ = ""; PREVIEWS_SWIFT_INCLUDE__NO = ""; PREVIEWS_SWIFT_INCLUDE__YES = "-I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin/tools/generators/pbxtargetdependencies"; @@ -153,7 +153,7 @@ Here is an example output: LINK_PARAMS_FILE = "$(BAZEL_OUT)/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj-params/pbxtargetdependencies_tests.54.link.params"; MACOSX_DEPLOYMENT_TARGET = 13.0; OTHER_LDFLAGS = "@$(DERIVED_FILE_DIR)/link.params"; - OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) $(PREVIEWS_SWIFT_INCLUDE__$(ENABLE_PREVIEWS)) -DNDEBUG -O -F$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks -I$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/usr/lib -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/generators/lib/PBXProj -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/generators/pbxtargetdependencies -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_swift_custom_dump -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra"; + OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -Xcc -ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml -vfsoverlay $(OBJROOT)/bazel-out-overlay.yaml $(PREVIEWS_SWIFT_INCLUDE__$(ENABLE_PREVIEWS)) -DNDEBUG -O -F$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks -I$(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/usr/lib -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/generators/lib/PBXProj -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/generators/pbxtargetdependencies -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay -I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/external/_main~dev_non_module_deps~com_github_pointfreeco_swift_custom_dump -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra"; PREVIEWS_SWIFT_INCLUDE__ = ""; PREVIEWS_SWIFT_INCLUDE__NO = ""; PREVIEWS_SWIFT_INCLUDE__YES = "-I$(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin/tools/generators/pbxtargetdependencies"; @@ -230,7 +230,7 @@ Here is an example output: BAZEL_TARGET_ID = "@@_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay//:XCTestDynamicOverlay macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee"; COMPILE_TARGET_NAME = XCTestDynamicOverlay; MACOSX_DEPLOYMENT_TARGET = 13.0; - OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -DDEBUG -Onone -enable-testing -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin -static -Xcc -O0 -Xcc -DDEBUG=1 -Xcc -fstack-protector -Xcc -fstack-protector-all"; + OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -Xcc -ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml -vfsoverlay $(OBJROOT)/bazel-out-overlay.yaml -DDEBUG -Onone -enable-testing -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-dbg-ST-95054d4cebee/bin -static -Xcc -O0 -Xcc -DDEBUG=1 -Xcc -fstack-protector -Xcc -fstack-protector-all"; PRODUCT_MODULE_NAME = XCTestDynamicOverlay; PRODUCT_NAME = XCTestDynamicOverlay; SDKROOT = macosx; @@ -250,7 +250,7 @@ Here is an example output: BAZEL_TARGET_ID = "@@_main~dev_non_module_deps~com_github_pointfreeco_xctest_dynamic_overlay//:XCTestDynamicOverlay macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9"; COMPILE_TARGET_NAME = XCTestDynamicOverlay; MACOSX_DEPLOYMENT_TARGET = 13.0; - OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -DNDEBUG -O -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra"; + OTHER_SWIFT_FLAGS = "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -Xcc -ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml -vfsoverlay $(OBJROOT)/bazel-out-overlay.yaml -DNDEBUG -O -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min13.0-applebin_macos-darwin_arm64-opt-ST-1f5196d1a0d9/bin -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra"; PRODUCT_MODULE_NAME = XCTestDynamicOverlay; PRODUCT_NAME = XCTestDynamicOverlay; SDKROOT = macosx; diff --git a/tools/generators/pbxproj_prefix/README.md b/tools/generators/pbxproj_prefix/README.md index 95408d5c2..4c2d08f8e 100644 --- a/tools/generators/pbxproj_prefix/README.md +++ b/tools/generators/pbxproj_prefix/README.md @@ -16,6 +16,7 @@ The generator accepts the following command-line arguments (see - Positional `execution-root-file` - Positional `target-ids-file` - Positional `index-import` +- Positional `separate-index-build-output-base` - Positional `resolved-repositories-file` - Positional `minimum-xcode-version` - Positional `default-xcode-configuration` @@ -37,6 +38,7 @@ $ pbxproj_prefix \ bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_execution_root_file \ bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_target_ids \ bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import \ + 1 \ bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_pbxproj_partials/resolved_repositories \ 14.0 \ Release \ @@ -217,6 +219,9 @@ Here is an example output: IMPORT_INDEX_BUILD_INDEXSTORES = YES; INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)"; INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_legacy"; + INDEXING_PROJECT_DIR__ = "$(INDEXING_PROJECT_DIR__NO)"; + INDEXING_PROJECT_DIR__NO = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main"; + INDEXING_PROJECT_DIR__YES = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/indexbuild_output_base/execroot/_main"; INDEX_FORCE_SCRIPT_EXECUTION = YES; INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin"; INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj"; @@ -227,7 +232,7 @@ Here is an example output: LD_RUNPATH_SEARCH_PATHS = ""; LIBTOOL = "$(BAZEL_INTEGRATION_DIR)/libtool"; ONLY_ACTIVE_ARCH = YES; - PROJECT_DIR = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main"; + PROJECT_DIR = "$(INDEXING_PROJECT_DIR__$(INDEX_ENABLE_BUILD_ARENA))"; RESOLVED_REPOSITORIES = "\"\" \"/tmp/workspace\""; RULES_XCODEPROJ_BUILD_MODE = bazel; SRCROOT = /tmp/workspace; @@ -277,6 +282,9 @@ Here is an example output: IMPORT_INDEX_BUILD_INDEXSTORES = YES; INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)"; INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import"; + INDEXING_PROJECT_DIR__ = "$(INDEXING_PROJECT_DIR__NO)"; + INDEXING_PROJECT_DIR__NO = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main"; + INDEXING_PROJECT_DIR__YES = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/indexbuild_output_base/execroot/_main"; INDEX_FORCE_SCRIPT_EXECUTION = YES; INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin"; INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj"; @@ -288,7 +296,7 @@ Here is an example output: LEGACY_INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_legacy"; LIBTOOL = "$(BAZEL_INTEGRATION_DIR)/libtool"; ONLY_ACTIVE_ARCH = YES; - PROJECT_DIR = "/tmp/workspace/bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main"; + PROJECT_DIR = "$(INDEXING_PROJECT_DIR__$(INDEX_ENABLE_BUILD_ARENA))"; RESOLVED_REPOSITORIES = "\"\" \"/tmp/workspace\""; RULES_XCODEPROJ_BUILD_MODE = bazel; SRCROOT = /tmp/workspace; diff --git a/tools/generators/pbxproj_prefix/src/Generator/Arguments.swift b/tools/generators/pbxproj_prefix/src/Generator/Arguments.swift index d8d252feb..f164c830f 100644 --- a/tools/generators/pbxproj_prefix/src/Generator/Arguments.swift +++ b/tools/generators/pbxproj_prefix/src/Generator/Arguments.swift @@ -36,6 +36,12 @@ Path to a file that contains the absolute path to the Bazel execution root. @Argument(help: "Path to the index_import executable.") var indexImport: String + @Argument( + help: "Whether to use a separate output base for index builds from other builds.", + transform: { $0 == "1" } + ) + var separateIndexBuildOutputBase: Bool + @Argument( help: """ Path to a file that contains a string for the `RESOLVED_REPOSITORIES` build \ diff --git a/tools/generators/pbxproj_prefix/src/Generator/Environment.swift b/tools/generators/pbxproj_prefix/src/Generator/Environment.swift index 15d675f12..32bc984f0 100644 --- a/tools/generators/pbxproj_prefix/src/Generator/Environment.swift +++ b/tools/generators/pbxproj_prefix/src/Generator/Environment.swift @@ -35,6 +35,7 @@ extension Generator { _ legacyIndexImport: String, _ indexImport: String, _ indexingProjectDir: String, + _ separateIndexBuildOutputBase: Bool, _ projectDir: String, _ resolvedRepositories: String, _ workspace: String, diff --git a/tools/generators/pbxproj_prefix/src/Generator/Generator.swift b/tools/generators/pbxproj_prefix/src/Generator/Generator.swift index 3417eb169..9754d5cf4 100644 --- a/tools/generators/pbxproj_prefix/src/Generator/Generator.swift +++ b/tools/generators/pbxproj_prefix/src/Generator/Generator.swift @@ -56,6 +56,7 @@ struct Generator { /*indexingProjectDir:*/ environment.indexingProjectDir( /*projectDir:*/ projectDir ), + /*separateIndexBuildOutputBase:*/ arguments.separateIndexBuildOutputBase, /*projectDir:*/ projectDir, /*resolvedRepositories:*/ try environment.readResolvedRepositoriesFile( diff --git a/tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift b/tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift index cb4feff0f..f655e92f9 100644 --- a/tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift +++ b/tools/generators/pbxproj_prefix/src/Generator/PBXProjectBuildSettings.swift @@ -25,12 +25,13 @@ extension Generator { legacyIndexImport: String, indexImport: String, indexingProjectDir: String, + separateIndexBuildOutputBase: Bool, projectDir: String, resolvedRepositories: String, workspace: String, createBuildSettingsAttribute: CreateBuildSettingsAttribute ) -> String { - return createBuildSettingsAttribute(buildSettings: [ + var buildSettings: [BuildSetting] = [ .init(key: "ALWAYS_SEARCH_USER_PATHS", value: "NO"), .init( key: "ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOLS", @@ -104,6 +105,18 @@ extension Generator { key: "IMPORT_INDEX_BUILD_INDEXSTORES", value: importIndexBuildIndexstores ? "YES" : "NO" ), + .init( + key: "INDEXING_PROJECT_DIR__", + value: #""$(INDEXING_PROJECT_DIR__NO)""# + ), + .init( + key: "INDEXING_PROJECT_DIR__NO", + value: projectDir.pbxProjEscaped + ), + .init( + key: "INDEXING_PROJECT_DIR__YES", + value: indexingProjectDir.pbxProjEscaped + ), .init( key: "INDEX_DATA_STORE_DIR", value: #""$(INDEX_DATA_STORE_DIR)""# @@ -133,10 +146,6 @@ extension Generator { .pbxProjEscaped ), .init(key: "ONLY_ACTIVE_ARCH", value: "YES"), - .init( - key: "PROJECT_DIR", - value: projectDir.pbxProjEscaped - ), .init( key: "RESOLVED_REPOSITORIES", value: resolvedRepositories.pbxProjEscaped @@ -165,6 +174,39 @@ extension Generator { key: "_BAZEL_OUTPUT_BASE", value: #""$(PROJECT_DIR)/../..""# ), - ]) + ] + if separateIndexBuildOutputBase { + buildSettings.append(contentsOf: [ + .init( + key: "BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE", + value: "YES" + ), + .init( + key: "INDEXING_PROJECT_DIR__", + value: #""$(INDEXING_PROJECT_DIR__NO)""# + ), + .init( + key: "INDEXING_PROJECT_DIR__NO", + value: projectDir.pbxProjEscaped + ), + .init( + key: "INDEXING_PROJECT_DIR__YES", + value: indexingProjectDir.pbxProjEscaped + ), + .init( + key: "PROJECT_DIR", + value: + #""$(INDEXING_PROJECT_DIR__$(INDEX_ENABLE_BUILD_ARENA))""# + ), + ]) + } else { + buildSettings.append( + .init( + key: "PROJECT_DIR", + value: projectDir.pbxProjEscaped + ) + ) + } + return createBuildSettingsAttribute(buildSettings: buildSettings) } } diff --git a/tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift b/tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift index 5f8ab08b0..2df0ff2a5 100644 --- a/tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift +++ b/tools/generators/pbxproj_prefix/test/PBXProjectBuildSettingsTests.swift @@ -88,6 +88,104 @@ class PBXProjectBuildSettingsTests: XCTestCase { legacyIndexImport: legacyIndexImport, indexImport: indexImport, indexingProjectDir: indexingProjectDir, + separateIndexBuildOutputBase: false, + projectDir: projectDir, + resolvedRepositories: resolvedRepositories, + workspace: workspace, + createBuildSettingsAttribute: CreateBuildSettingsAttribute() + ) + + // Assert + + XCTAssertNoDifference(buildSettings, expectedBuildSettings) + } + + func testSeparateIndexOutputBase() { + // Arrange + + let config = "rxcp_custom_config" + let importIndexBuildIndexstores = false + let legacyIndexImport = "external/legacy-index-import" + let indexImport = "external/index-import" + let indexingProjectDir = "/some/indexing/project dir" + let projectDir = "/some/project dir" + let resolvedRepositories = #""" "/tmp/workspace""# + let workspace = "/Users/TimApple/Star Board" + + // The tabs for indenting are intentional + let expectedBuildSettings = #""" +{ + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOLS = NO; + BAZEL_CONFIG = rxcp_custom_config; + BAZEL_EXTERNAL = "$(BAZEL_OUTPUT_BASE)/external"; + BAZEL_INTEGRATION_DIR = "$(INTERNAL_DIR)/bazel"; + BAZEL_LLDB_INIT = "$(HOME)/.lldbinit-rules_xcodeproj"; + BAZEL_OUT = "$(PROJECT_DIR)/bazel-out"; + BAZEL_OUTPUT_BASE = "$(_BAZEL_OUTPUT_BASE:standardizepath)"; + BAZEL_WORKSPACE_ROOT = "$(SRCROOT)"; + BUILD_DIR = "$(SYMROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"; + BUILD_MARKER_FILE = "$(OBJROOT)/build_marker"; + BUILD_WORKSPACE_DIRECTORY = "$(SRCROOT)"; + CC = "$(BAZEL_INTEGRATION_DIR)/clang.sh"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_MODULES_AUTOLINK = NO; + CODE_SIGNING_ALLOWED = NO; + CODE_SIGN_STYLE = Manual; + CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)"; + COPY_PHASE_STRIP = NO; + CXX = "$(BAZEL_INTEGRATION_DIR)/clang.sh"; + DEBUG_INFORMATION_FORMAT = dwarf; + DSTROOT = "$(PROJECT_TEMP_DIR)"; + ENABLE_DEBUG_DYLIB = NO; + ENABLE_DEFAULT_SEARCH_PATHS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_OPTIMIZATION_LEVEL = 0; + IMPORT_INDEX_BUILD_INDEXSTORES = NO; + INDEXING_PROJECT_DIR__ = "$(INDEXING_PROJECT_DIR__NO)"; + INDEXING_PROJECT_DIR__NO = "/some/project dir"; + INDEXING_PROJECT_DIR__YES = "/some/indexing/project dir"; + INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)"; + INDEX_FORCE_SCRIPT_EXECUTION = YES; + INDEX_IMPORT = "$(BAZEL_EXTERNAL)/index-import"; + INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin"; + INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj"; + LD = "$(BAZEL_INTEGRATION_DIR)/ld"; + LDPLUSPLUS = "$(BAZEL_INTEGRATION_DIR)/ld"; + LD_DYLIB_INSTALL_NAME = ""; + LD_OBJC_ABI_VERSION = ""; + LD_RUNPATH_SEARCH_PATHS = ""; + LEGACY_INDEX_IMPORT = "$(BAZEL_EXTERNAL)/legacy-index-import"; + LIBTOOL = "$(BAZEL_INTEGRATION_DIR)/libtool"; + ONLY_ACTIVE_ARCH = YES; + PROJECT_DIR = "$(INDEXING_PROJECT_DIR__$(INDEX_ENABLE_BUILD_ARENA))"; + RESOLVED_REPOSITORIES = "\"\" \"/tmp/workspace\""; + RULES_XCODEPROJ_BUILD_MODE = bazel; + SRCROOT = "/Users/TimApple/Star Board"; + SUPPORTS_MACCATALYST = NO; + SWIFT_EXEC = "$(BAZEL_INTEGRATION_DIR)/swiftc"; + SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_USE_INTEGRATED_DRIVER = NO; + SWIFT_VERSION = 5.0; + TAPI_EXEC = /usr/bin/true; + TARGET_TEMP_DIR = "$(PROJECT_TEMP_DIR)/$(BAZEL_PACKAGE_BIN_DIR)/$(COMPILE_TARGET_NAME)"; + USE_HEADERMAP = NO; + VALIDATE_WORKSPACE = NO; + _BAZEL_OUTPUT_BASE = "$(PROJECT_DIR)/../.."; + } +"""# + + // Act + + let buildSettings = Generator.pbxProjectBuildSettings( + config: config, + importIndexBuildIndexstores: importIndexBuildIndexstores, + legacyIndexImport: legacyIndexImport, + indexImport: indexImport, + indexingProjectDir: indexingProjectDir, + separateIndexBuildOutputBase: true, projectDir: projectDir, resolvedRepositories: resolvedRepositories, workspace: workspace, diff --git a/tools/generators/target_build_settings/README.md b/tools/generators/target_build_settings/README.md index f75999995..f567730c8 100644 --- a/tools/generators/target_build_settings/README.md +++ b/tools/generators/target_build_settings/README.md @@ -27,6 +27,7 @@ The generator accepts the following command-line arguments: - Positional `package-bin-dir` - Positional `preview-framework-paths` - Positional `previews-include-path` +- Positional `separate-index-build-output-base` - The command-line arguments for a Bazel `SwiftCompile` action - `---` to signify the end of the Swift arguments @@ -60,6 +61,7 @@ $ target_build_settings \ bazel-out/watchos-arm64_32-min7.0-applebin_watchos-watchos_arm64_32-opt-ST-c58d72818890/bin/Lib \ '' \ '' \ + 0 \ -target \ arm64_32-apple-watchos7.0 \ -sdk \ @@ -168,7 +170,7 @@ Here is an example output: ### `target_build_settings` ``` -OTHER_SWIFT_FLAGS "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -DNDEBUG -O -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_kylef_pathkit -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjson -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_tadija_aexml -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_tuist_xcodeproj -Xcc -I -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/Sources/JJLISO8601DateFormatter/include -Xcc -I -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/Sources/JJLISO8601DateFormatter/include -Xcc -I -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/Sources/ZippyJSONCFamily/include -Xcc -I -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/Sources/ZippyJSONCFamily/include -Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter -Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin -Xcc -fmodule-map-file=$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/JJLISO8601DateFormatter.swift.modulemap -Xcc -fmodule-map-file=$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/ZippyJSONCFamily.swift.modulemap -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra" +OTHER_SWIFT_FLAGS "-Xcc -working-directory -Xcc $(PROJECT_DIR) -working-directory $(PROJECT_DIR) -Xcc -ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml -vfsoverlay $(OBJROOT)/bazel-out-overlay.yaml -DNDEBUG -O -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_apple_swift_argument_parser -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/tools/lib/ToolCommon -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_apple_swift_collections -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_kylef_pathkit -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjson -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_tadija_aexml -I$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_tuist_xcodeproj -Xcc -I -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/Sources/JJLISO8601DateFormatter/include -Xcc -I -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/Sources/JJLISO8601DateFormatter/include -Xcc -I -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/Sources/ZippyJSONCFamily/include -Xcc -I -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/Sources/ZippyJSONCFamily/include -Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter -Xcc -iquote -Xcc $(BAZEL_EXTERNAL)/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily -Xcc -iquote -Xcc $(PROJECT_DIR) -Xcc -iquote -Xcc $(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin -Xcc -fmodule-map-file=$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_jjliso8601dateformatter/JJLISO8601DateFormatter.swift.modulemap -Xcc -fmodule-map-file=$(BAZEL_OUT)/macos-arm64-min12.0-applebin_macos-darwin_arm64-opt-ST-89c7f8a7bb2e/bin/external/_main~non_module_deps~com_github_michaeleisel_zippyjsoncfamily/ZippyJSONCFamily.swift.modulemap -static -Xcc -Os -Xcc -DNDEBUG=1 -Xcc -Wno-unused-variable -Xcc -Winit-self -Xcc -Wno-extra" SWIFT_COMPILATION_MODE wholemodule ``` diff --git a/tools/generators/target_build_settings/src/Generator/ProcessArgs.swift b/tools/generators/target_build_settings/src/Generator/ProcessArgs.swift index 989527c47..200bba7da 100644 --- a/tools/generators/target_build_settings/src/Generator/ProcessArgs.swift +++ b/tools/generators/target_build_settings/src/Generator/ProcessArgs.swift @@ -105,6 +105,10 @@ extension Generator.ProcessArgs { try rawArguments.consumeArg("previews-framework-paths") let previewsIncludePath = try rawArguments.consumeArg("previews-include-path") + let separateIndexBuildOutputBase = try rawArguments.consumeArg( + "separate-index-build-output-base", + as: Bool.self + ) let argsStream = argsStream(from: rawArguments) @@ -121,6 +125,7 @@ extension Generator.ProcessArgs { includeSelfSwiftDebugSettings: includeSelfSwiftDebugSettings, previewsFrameworkPaths: previewsFrameworkPaths, previewsIncludePath: previewsIncludePath, + separateIndexBuildOutputBase: separateIndexBuildOutputBase, transitiveSwiftDebugSettingPaths: transitiveSwiftDebugSettingPaths ) @@ -130,12 +135,14 @@ extension Generator.ProcessArgs { let cHasDebugInfo = try await processCArgs( argsStream: argsStream, - buildSettings: &buildSettings + buildSettings: &buildSettings, + separateIndexBuildOutputBase: separateIndexBuildOutputBase ) let cxxHasDebugInfo = try await processCxxArgs( argsStream: argsStream, - buildSettings: &buildSettings + buildSettings: &buildSettings, + separateIndexBuildOutputBase: separateIndexBuildOutputBase ) if generatesDsyms || swiftHasDebugInfo || cHasDebugInfo || diff --git a/tools/generators/target_build_settings/src/Generator/ProcessCArgs.swift b/tools/generators/target_build_settings/src/Generator/ProcessCArgs.swift index c402af9fb..424703b56 100644 --- a/tools/generators/target_build_settings/src/Generator/ProcessCArgs.swift +++ b/tools/generators/target_build_settings/src/Generator/ProcessCArgs.swift @@ -25,12 +25,14 @@ extension Generator { /// Processes all the C/Objective-C arguments. func callAsFunction( argsStream: AsyncThrowingStream, - buildSettings: inout [(key: String, value: String)] + buildSettings: inout [(key: String, value: String)], + separateIndexBuildOutputBase: Bool ) async throws -> Bool { try await callable( /*argsStream:*/ argsStream, /*buildSettings:*/ &buildSettings, /*processCcArgs:*/ processCcArgs, + /*separateIndexBuildOutputBase:*/ separateIndexBuildOutputBase, /*write:*/ write ) } @@ -44,6 +46,7 @@ extension Generator.ProcessCArgs { _ argsStream: AsyncThrowingStream, _ buildSettings: inout [(key: String, value: String)], _ processCcArgs: Generator.ProcessCcArgs, + _ separateIndexBuildOutputBase: Bool, _ write: Write ) async throws -> Bool @@ -51,6 +54,7 @@ extension Generator.ProcessCArgs { argsStream: AsyncThrowingStream, buildSettings: inout [(key: String, value: String)], processCcArgs: Generator.ProcessCcArgs, + separateIndexBuildOutputBase: Bool, write: Write ) async throws -> Bool { var iterator = argsStream.makeAsyncIterator() @@ -67,7 +71,8 @@ extension Generator.ProcessCArgs { _ = try await iterator.next() let (args, hasDebugInfo, fortifySourceLevel) = try await processCcArgs( - argsStream: argsStream + argsStream: argsStream, + separateIndexBuildOutputBase: separateIndexBuildOutputBase ) let content = args.map { $0 + "\n" }.joined() diff --git a/tools/generators/target_build_settings/src/Generator/ProcessCcArgs.swift b/tools/generators/target_build_settings/src/Generator/ProcessCcArgs.swift index f58c79231..3fc2d10ee 100644 --- a/tools/generators/target_build_settings/src/Generator/ProcessCcArgs.swift +++ b/tools/generators/target_build_settings/src/Generator/ProcessCcArgs.swift @@ -18,7 +18,8 @@ extension Generator { /// Processes all of the common flags for C or C++ arguments. func callAsFunction( - argsStream: AsyncThrowingStream + argsStream: AsyncThrowingStream, + separateIndexBuildOutputBase: Bool ) async throws -> ( args: [String], hasDebugInfo: Bool, @@ -26,7 +27,8 @@ extension Generator { ) { try await callable( /*argsStream:*/ argsStream, - /*processCcArg:*/ processCcArg + /*processCcArg:*/ processCcArg, + /*separateIndexBuildOutputBase:*/ separateIndexBuildOutputBase ) } } @@ -37,7 +39,8 @@ extension Generator { extension Generator.ProcessCcArgs { typealias Callable = ( _ argsStream: AsyncThrowingStream, - _ processCcArg: Generator.ProcessCcArg + _ processCcArg: Generator.ProcessCcArg, + _ separateIndexBuildOutputBase: Bool ) async throws -> ( args: [String], hasDebugInfo: Bool, @@ -46,7 +49,8 @@ extension Generator.ProcessCcArgs { static func defaultCallable( argsStream: AsyncThrowingStream, - processCcArg: Generator.ProcessCcArg + processCcArg: Generator.ProcessCcArg, + separateIndexBuildOutputBase: Bool ) async throws -> ( args: [String], hasDebugInfo: Bool, @@ -59,6 +63,12 @@ extension Generator.ProcessCcArgs { "-working-directory", "$(PROJECT_DIR)", ] + if separateIndexBuildOutputBase { + args.append(contentsOf: [ + "-ivfsoverlay", + "$(OBJROOT)/bazel-out-overlay.yaml", + ]) + } var hasDebugInfo = false var fortifySourceLevel = 0 diff --git a/tools/generators/target_build_settings/src/Generator/ProcessCxxArgs.swift b/tools/generators/target_build_settings/src/Generator/ProcessCxxArgs.swift index 2a6c04d2c..0a733b283 100644 --- a/tools/generators/target_build_settings/src/Generator/ProcessCxxArgs.swift +++ b/tools/generators/target_build_settings/src/Generator/ProcessCxxArgs.swift @@ -25,12 +25,14 @@ extension Generator { /// Processes all the C++/Objective-C++ arguments. func callAsFunction( argsStream: AsyncThrowingStream, - buildSettings: inout [(key: String, value: String)] + buildSettings: inout [(key: String, value: String)], + separateIndexBuildOutputBase: Bool ) async throws -> Bool { try await callable( /*argsStream:*/ argsStream, /*buildSettings:*/ &buildSettings, /*processCcArgs:*/ processCcArgs, + /*separateIndexBuildOutputBase:*/ separateIndexBuildOutputBase, /*write:*/ write ) } @@ -44,6 +46,7 @@ extension Generator.ProcessCxxArgs { _ argsStream: AsyncThrowingStream, _ buildSettings: inout [(key: String, value: String)], _ processCcArgs: Generator.ProcessCcArgs, + _ separateIndexBuildOutputBase: Bool, _ write: Write ) async throws -> Bool @@ -51,6 +54,7 @@ extension Generator.ProcessCxxArgs { argsStream: AsyncThrowingStream, buildSettings: inout [(key: String, value: String)], processCcArgs: Generator.ProcessCcArgs, + separateIndexBuildOutputBase: Bool, write: Write ) async throws -> Bool { var iterator = argsStream.makeAsyncIterator() @@ -67,7 +71,8 @@ extension Generator.ProcessCxxArgs { _ = try await iterator.next() let (args, hasDebugInfo, fortifySourceLevel) = try await processCcArgs( - argsStream: argsStream + argsStream: argsStream, + separateIndexBuildOutputBase: separateIndexBuildOutputBase ) let content = args.map { $0 + "\n" }.joined() diff --git a/tools/generators/target_build_settings/src/Generator/ProcessSwiftArgs.swift b/tools/generators/target_build_settings/src/Generator/ProcessSwiftArgs.swift index 9d79cd0ca..75b5ff526 100644 --- a/tools/generators/target_build_settings/src/Generator/ProcessSwiftArgs.swift +++ b/tools/generators/target_build_settings/src/Generator/ProcessSwiftArgs.swift @@ -38,6 +38,7 @@ extension Generator { includeSelfSwiftDebugSettings: Bool, previewsFrameworkPaths: String, previewsIncludePath: String, + separateIndexBuildOutputBase: Bool, transitiveSwiftDebugSettingPaths: [URL] ) async throws -> ( hasDebugInfo: Bool, @@ -58,7 +59,8 @@ extension Generator { parseTransitiveSwiftDebugSettings, /*processSwiftArg:*/ processSwiftArg, /*processSwiftClangArg:*/ processSwiftClangArg, - /*processSwiftFrontendArg:*/ processSwiftFrontendArg + /*processSwiftFrontendArg:*/ processSwiftFrontendArg, + /*separateIndexBuildOutputBase:*/ separateIndexBuildOutputBase ) } } @@ -78,7 +80,8 @@ extension Generator.ProcessSwiftArgs { Generator.ParseTransitiveSwiftDebugSettings, _ processSwiftArg: Generator.ProcessSwiftArg, _ processSwiftClangArg: Generator.ProcessSwiftClangArg, - _ processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg + _ processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg, + _ separateIndexBuildOutputBase: Bool ) async throws -> ( hasDebugInfo: Bool, clangArgs: [String], @@ -97,7 +100,8 @@ extension Generator.ProcessSwiftArgs { Generator.ParseTransitiveSwiftDebugSettings, processSwiftArg: Generator.ProcessSwiftArg, processSwiftClangArg: Generator.ProcessSwiftClangArg, - processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg + processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg, + separateIndexBuildOutputBase: Bool ) async throws -> ( hasDebugInfo: Bool, clangArgs: [String], @@ -122,7 +126,8 @@ extension Generator.ProcessSwiftArgs { parseTransitiveSwiftDebugSettings, processSwiftArg: processSwiftArg, processSwiftClangArg: processSwiftClangArg, - processSwiftFrontendArg: processSwiftFrontendArg + processSwiftFrontendArg: processSwiftFrontendArg, + separateIndexBuildOutputBase: separateIndexBuildOutputBase ) if includeTransitiveSwiftDebugSettings { @@ -149,7 +154,8 @@ extension Generator.ProcessSwiftArgs { Generator.ParseTransitiveSwiftDebugSettings, processSwiftArg: Generator.ProcessSwiftArg, processSwiftClangArg: Generator.ProcessSwiftClangArg, - processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg + processSwiftFrontendArg: Generator.ProcessSwiftFrontendArg, + separateIndexBuildOutputBase: Bool ) async throws -> ( hasDebugInfo: Bool, clangArgs: [String], @@ -182,6 +188,15 @@ extension Generator.ProcessSwiftArgs { "-working-directory", "$(PROJECT_DIR)", ] + if separateIndexBuildOutputBase { + args.append(contentsOf: [ + "-Xcc", + "-ivfsoverlay$(OBJROOT)/bazel-out-overlay.yaml", + "-vfsoverlay", + "$(OBJROOT)/bazel-out-overlay.yaml", + ]) + } + var clangArgs: [String] = [] var frameworkIncludes: OrderedSet = [] var onceClangArgs: Set = [] diff --git a/xcodeproj/BUILD b/xcodeproj/BUILD index 0f96c397c..14a1aacaa 100644 --- a/xcodeproj/BUILD +++ b/xcodeproj/BUILD @@ -45,6 +45,12 @@ string_flag( visibility = ["//visibility:public"], ) +bool_flag( + name = "separate_index_build_output_base", + build_setting_default = False, + visibility = ["//visibility:public"], +) + package_group( name = "generated", includes = ["@rules_xcodeproj_generated//:package_group"], diff --git a/xcodeproj/internal/bazel_integration_files/create_lldbinit.sh b/xcodeproj/internal/bazel_integration_files/create_lldbinit.sh index 3e05aea6a..18694f57a 100755 --- a/xcodeproj/internal/bazel_integration_files/create_lldbinit.sh +++ b/xcodeproj/internal/bazel_integration_files/create_lldbinit.sh @@ -29,6 +29,24 @@ echo "settings append target.source-map ./external/ \"$BAZEL_EXTERNAL\"" # `external` when set from swiftsourcefile echo "settings append target.source-map ./external/ \"$build_external\"" +if [[ "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" == "YES" ]]; then + readonly output_base="${execution_root%/*/*}" + + readonly workspace_name="${execution_root##*/}" + readonly index_execution_root="${output_base%/*}/indexbuild_output_base/execroot/$workspace_name" + + readonly index_bazel_out="$index_execution_root/bazel-out" + readonly index_external="$index_execution_root/external" + + mkdir -p "$index_bazel_out" + mkdir -p "$index_external" + + # `bazel-out` when set from indexing opened file + echo "settings append target.source-map ./bazel-out/ \"$index_bazel_out\"" + # `external` when set from indexing opened file + echo "settings append target.source-map ./external/ \"$index_external\"" +fi + # Project files and locally resolved external repositories # # lldb seems to match breakpoints based on the second argument, using a simple diff --git a/xcodeproj/internal/bazel_integration_files/generate_index_build_bazel_dependencies.sh b/xcodeproj/internal/bazel_integration_files/generate_index_build_bazel_dependencies.sh index 87af01b5e..4c67d3d4e 100755 --- a/xcodeproj/internal/bazel_integration_files/generate_index_build_bazel_dependencies.sh +++ b/xcodeproj/internal/bazel_integration_files/generate_index_build_bazel_dependencies.sh @@ -63,7 +63,13 @@ source "$BAZEL_INTEGRATION_DIR/bazel_build.sh" # Import indexes if [ -n "${indexstores_filelists:-}" ]; then - "$BAZEL_INTEGRATION_DIR/import_indexstores" \ - "$PROJECT_DIR" \ - "${indexstores_filelists[@]/#/$BAZEL_OUT/}" + if [[ "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" == "YES" ]]; then + "$BAZEL_INTEGRATION_DIR/import_indexstores" \ + "$INDEXING_PROJECT_DIR__NO" \ + "${indexstores_filelists[@]/#/$output_path/}" + else + "$BAZEL_INTEGRATION_DIR/import_indexstores" \ + "$PROJECT_DIR" \ + "${indexstores_filelists[@]/#/$BAZEL_OUT/}" + fi fi diff --git a/xcodeproj/internal/pbxproj_partials.bzl b/xcodeproj/internal/pbxproj_partials.bzl index 5f6f5c7b4..cffc846ef 100644 --- a/xcodeproj/internal/pbxproj_partials.bzl +++ b/xcodeproj/internal/pbxproj_partials.bzl @@ -671,6 +671,7 @@ def _write_pbxproj_prefix( pre_build_script, project_options, resolved_repositories_file, + separate_index_build_output_base, target_ids_list, tool, workspace_directory, @@ -702,6 +703,8 @@ def _write_pbxproj_prefix( project_options: A `dict` as returned by `project_options`. resolved_repositories_file: A `File` containing containing a string for the `RESOLVED_REPOSITORIES` build setting. + separate_index_build_output_base: Whether or not to use a separate + output base for index builds. target_ids_list: A `File` containing a list of target IDs. tool: The executable that will generate the `PBXProj` partial. workspace_directory: The absolute path to the Bazel workspace @@ -743,6 +746,9 @@ def _write_pbxproj_prefix( # indexImport args.add(index_import) + # separateIndexBuildOutputBase + args.add(TRUE_ARG if separate_index_build_output_base else FALSE_ARG) + # resolvedRepositoriesFile args.add(resolved_repositories_file) @@ -1101,6 +1107,7 @@ def _write_target_build_settings( previews_include_path = EMPTY_STRING, provisioning_profile_is_xcode_managed = False, provisioning_profile_name = None, + separate_index_build_output_base, swift_args, swift_debug_settings_to_merge = EMPTY_DEPSET, team_id = None, @@ -1138,6 +1145,8 @@ def _write_target_build_settings( provisioning profile is managed by Xcode. provisioning_profile_name: The name of the provisioning profile to use for code signing. + separate_index_build_output_base: Whether or not to use a separate + output base for index builds. swift_args: A `list` of `Args` for the `SwiftCompile` action for this target. swift_debug_settings_to_merge: A `depset` of `Files` containing @@ -1247,6 +1256,9 @@ def _write_target_build_settings( # previewsIncludePath args.add(previews_include_path) + # separateIndexBuildOutputBase + args.add(TRUE_ARG if separate_index_build_output_base else FALSE_ARG) + c_output_args = actions.args() # C argsSeparator diff --git a/xcodeproj/internal/processed_targets/library_targets.bzl b/xcodeproj/internal/processed_targets/library_targets.bzl index fe523bb9b..f2e417fc0 100644 --- a/xcodeproj/internal/processed_targets/library_targets.bzl +++ b/xcodeproj/internal/processed_targets/library_targets.bzl @@ -135,6 +135,9 @@ def _process_library_target( generate_build_settings = generate_target, generate_swift_debug_settings = bool(args.swift), name = label.name, + separate_index_build_output_base = ( + ctx.attr._separate_index_build_output_base[BuildSettingInfo].value + ), swift_args = args.swift, tool = ctx.executable._target_build_settings_generator, ) diff --git a/xcodeproj/internal/processed_targets/mixed_language_library_targets.bzl b/xcodeproj/internal/processed_targets/mixed_language_library_targets.bzl index cf7094f8a..474353d27 100644 --- a/xcodeproj/internal/processed_targets/mixed_language_library_targets.bzl +++ b/xcodeproj/internal/processed_targets/mixed_language_library_targets.bzl @@ -156,6 +156,9 @@ def _process_mixed_language_library_target( generate_swift_debug_settings = False, include_self_swift_debug_settings = False, name = label.name, + separate_index_build_output_base = ( + ctx.attr._separate_index_build_output_base[BuildSettingInfo].value + ), swift_args = args.swift, tool = ctx.executable._target_build_settings_generator, ) diff --git a/xcodeproj/internal/processed_targets/top_level_targets.bzl b/xcodeproj/internal/processed_targets/top_level_targets.bzl index b29b903ad..4a53d50ff 100644 --- a/xcodeproj/internal/processed_targets/top_level_targets.bzl +++ b/xcodeproj/internal/processed_targets/top_level_targets.bzl @@ -478,6 +478,9 @@ def _process_focused_top_level_target( provisioning_profile_props.is_xcode_managed ), provisioning_profile_name = provisioning_profile_props.name, + separate_index_build_output_base = ( + ctx.attr._separate_index_build_output_base[BuildSettingInfo].value + ), swift_args = args.swift, swift_debug_settings_to_merge = swift_debug_settings_to_merge, team_id = provisioning_profile_props.team_id, @@ -785,6 +788,9 @@ def _process_unfocused_top_level_target( generate_build_settings = False, generate_swift_debug_settings = True, name = label.name, + separate_index_build_output_base = ( + ctx.attr._separate_index_build_output_base[BuildSettingInfo].value + ), swift_args = args.swift, swift_debug_settings_to_merge = swift_debug_settings_to_merge, tool = ctx.executable._target_build_settings_generator, diff --git a/xcodeproj/internal/templates/bazel_build.sh b/xcodeproj/internal/templates/bazel_build.sh index 5e81446fa..b8cc91ec1 100755 --- a/xcodeproj/internal/templates/bazel_build.sh +++ b/xcodeproj/internal/templates/bazel_build.sh @@ -27,7 +27,29 @@ readonly output_groups_flag # In `runner.sh` the generator has the build output base set inside of the outer # bazel's output path (`bazel-out/`). So here we need to make our output base # changes relative to that changed path. -readonly output_base="$BAZEL_OUTPUT_BASE" +readonly build_output_base="$BAZEL_OUTPUT_BASE" + +if [[ + "$ACTION" == "indexbuild" && + "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" == "YES" +]]; then + # We use a different output base for Index Build to prevent normal builds and + # indexing waiting on bazel locks from the other. We nest it inside of the + # normal output base directory so that it's not cleaned up when running + # `bazel clean`, but is when running `bazel clean --expunge`. This matches + # Xcode behavior of not cleaning the Index Build outputs by default. + readonly output_base="${build_output_base%/*}/indexbuild_output_base" + readonly workspace_name="${PROJECT_DIR##*/}" + readonly output_path="$output_base/execroot/$workspace_name/bazel-out" + + # Use current path for "bazel-out/" and "external/" + # This fixes Index Build to use its version of generated and external files + readonly vfs_overlay_roots="{\"external-contents\": \"$output_path\",\"name\": \"$BAZEL_OUT\",\"type\": \"directory-remap\"},{\"external-contents\": \"$output_base/external\",\"name\": \"$BAZEL_EXTERNAL\",\"type\": \"directory-remap\"}" +else + readonly output_base="$build_output_base" + readonly output_path="$BAZEL_OUT" + readonly vfs_overlay_roots="" +fi # Set `bazel_cmd` for calling `bazel` @@ -71,7 +93,10 @@ bazel_cmd=( --output_base "$output_base" ) -if [ "$ACTION" == "indexbuild" ]; then +if [[ + "$ACTION" == "indexbuild" && + "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" != "YES" +]]; then # Allow normal builds to cancel Index Builds bazel_cmd+=("--preemptible") fi @@ -94,6 +119,14 @@ readonly base_pre_config_flags=( "--bes_upload_mode=NOWAIT_FOR_UPLOAD_COMPLETE" ) + +if [[ "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" == "YES" ]]; then + # Create VFS overlay + cat > "$OBJROOT/bazel-out-overlay.yaml" <&2 - exit 1 + >&2 + exit 1 fi fi diff --git a/xcodeproj/internal/templates/generate_bazel_dependencies.sh b/xcodeproj/internal/templates/generate_bazel_dependencies.sh index 150ff1379..23e1a62a9 100755 --- a/xcodeproj/internal/templates/generate_bazel_dependencies.sh +++ b/xcodeproj/internal/templates/generate_bazel_dependencies.sh @@ -192,8 +192,15 @@ done # Import indexes if [ -n "${indexstores_filelists:-}" ]; then - "$BAZEL_INTEGRATION_DIR/import_indexstores" \ - "$PROJECT_DIR" \ - "${indexstores_filelists[@]/#/$BAZEL_OUT/}" \ - >"$log_dir/import_indexstores.async.log" 2>&1 & + if [[ "${BAZEL_SEPARATE_INDEXBUILD_OUTPUT_BASE:-}" == "YES" ]]; then + "$BAZEL_INTEGRATION_DIR/import_indexstores" \ + "$INDEXING_PROJECT_DIR__NO" \ + "${indexstores_filelists[@]/#/$output_path/}" \ + >"$log_dir/import_indexstores.async.log" 2>&1 & + else + "$BAZEL_INTEGRATION_DIR/import_indexstores" \ + "$PROJECT_DIR" \ + "${indexstores_filelists[@]/#/$BAZEL_OUT/}" \ + >"$log_dir/import_indexstores.async.log" 2>&1 & + fi fi diff --git a/xcodeproj/internal/templates/generator.BUILD.bazel b/xcodeproj/internal/templates/generator.BUILD.bazel index 36a29e843..300098e35 100644 --- a/xcodeproj/internal/templates/generator.BUILD.bazel +++ b/xcodeproj/internal/templates/generator.BUILD.bazel @@ -31,6 +31,7 @@ xcodeproj( runner_label = "%runner_label%", scheme_autogeneration_mode = "%scheme_autogeneration_mode%", scheme_autogeneration_config = %scheme_autogeneration_config%, + separate_index_build_output_base = %separate_index_build_output_base%, tags = %tags%, target_name_mode = "%target_name_mode%", top_level_device_targets = %top_level_device_targets%, diff --git a/xcodeproj/internal/templates/installer.sh b/xcodeproj/internal/templates/installer.sh index 3508dc21f..ae7f3cced 100644 --- a/xcodeproj/internal/templates/installer.sh +++ b/xcodeproj/internal/templates/installer.sh @@ -18,6 +18,8 @@ fail() { # Process Args +separate_indexbuild_output_base=0 + while (("$#")); do case "${1}" in "--bazel_path") @@ -40,6 +42,10 @@ while (("$#")); do extra_flags_bazelrc="${2}" shift 2 ;; + "--separate_indexbuild_output_base") + separate_indexbuild_output_base=1 + shift 1 + ;; *) fail "Unrecognized argument: ${1}" ;; @@ -194,11 +200,24 @@ if [[ $is_macos -eq 1 ]]; then plutil -replace IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded -bool false "$workspace_settings" fi +if [[ $separate_indexbuild_output_base -eq 1 ]]; then + # Create Index Build execution root (`$INDEXING_PROJECT_DIR__YES`) + readonly workspace_name="${execution_root##*/}" + readonly output_base="${execution_root%/*/*}" + readonly indexbuild_exec_root="$output_base/rules_xcodeproj.noindex/indexbuild_output_base/execroot/$workspace_name" + + mkdir -p "$indexbuild_exec_root" +fi + # Create folder structure in bazel-out to work around Xcode red generated files if [[ -s "$src_generated_directories_filelist" ]]; then cd "$BUILD_WORKSPACE_DIRECTORY" - readonly nested_execution_root="${execution_root%/*/*}/rules_xcodeproj.noindex/build_output_base/execroot/${execution_root##*/}" + if [[ $separate_indexbuild_output_base -eq 1 ]]; then + readonly nested_execution_root="$output_base/rules_xcodeproj.noindex/build_output_base/execroot/$workspace_name" + else + readonly nested_execution_root="${execution_root%/*/*}/rules_xcodeproj.noindex/build_output_base/execroot/${execution_root##*/}" + fi # Create directory structure in bazel-out cd "$nested_execution_root" diff --git a/xcodeproj/internal/templates/runner.sh b/xcodeproj/internal/templates/runner.sh index b8e42974b..15b7800c1 100644 --- a/xcodeproj/internal/templates/runner.sh +++ b/xcodeproj/internal/templates/runner.sh @@ -32,6 +32,7 @@ installer_flags=( config="build" original_arg_count=$# download_intermediates=0 +separate_indexbuild_output_base=0 verbose=0 while (("$#")); do case "$1" in @@ -51,6 +52,10 @@ while (("$#")); do download_intermediates=1 shift 1 ;; + --separate_indexbuild_output_base) + separate_indexbuild_output_base=1 + shift 1 + ;; -v|--verbose) verbose=1 shift 1 @@ -73,6 +78,10 @@ if [[ $original_arg_count -gt 0 ]]; then fi fi +if [[ $separate_indexbuild_output_base -eq 1 ]]; then + installer_flags+=(--separate_indexbuild_output_base) +fi + cd "$BUILD_WORKSPACE_DIRECTORY" # Resolve path to bazel before changing the env variable. This allows bazelisk @@ -235,9 +244,18 @@ if [[ $original_arg_count -eq 0 ]]; then "%generator_label%" \ -- "${installer_flags[@]}" else - if [[ $config == "build" || $config == "indexbuild" ]]; then + if [[ + $config == "build" || + ($config == "indexbuild" && $separate_indexbuild_output_base -ne 1) + ]]; then readonly bazel_config="_%config%_build" readonly output_base_name="build_output_base" + elif [[ + $config == "indexbuild" && + $separate_indexbuild_output_base -eq 1 + ]]; then + readonly bazel_config="%config%_$config" + readonly output_base_name="indexbuild_output_base" else readonly bazel_config="%config%_$config" readonly output_base_name="build_output_base" diff --git a/xcodeproj/internal/xcodeproj_aspect.bzl b/xcodeproj/internal/xcodeproj_aspect.bzl index a857aa73a..d3b767e9a 100644 --- a/xcodeproj/internal/xcodeproj_aspect.bzl +++ b/xcodeproj/internal/xcodeproj_aspect.bzl @@ -88,6 +88,10 @@ def _xcodeproj_aspect_attrs( ), executable = True, ), + "_separate_index_build_output_base": attr.label( + default = Label("//xcodeproj:separate_index_build_output_base"), + providers = [BuildSettingInfo], + ), "_target_build_settings_generator": attr.label( cfg = "exec", default = Label( diff --git a/xcodeproj/internal/xcodeproj_rule.bzl b/xcodeproj/internal/xcodeproj_rule.bzl index 7b5f5018d..bbe87196f 100644 --- a/xcodeproj/internal/xcodeproj_rule.bzl +++ b/xcodeproj/internal/xcodeproj_rule.bzl @@ -344,6 +344,7 @@ def _write_project_contents( project_options, resource_bundle_xcode_targets, selected_model_versions_generator, + separate_index_build_output_base, target_name_mode, unique_directories, unowned_extra_files, @@ -462,6 +463,7 @@ def _write_project_contents( pre_build_script = pre_build_script, project_options = project_options, resolved_repositories_file = resolved_repositories_file, + separate_index_build_output_base = separate_index_build_output_base, target_ids_list = target_ids_list, tool = pbxproj_prefix_generator, xcode_configurations = xcode_configurations, @@ -631,6 +633,7 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \ legacy_index_import = ctx.executable._legacy_index_import index_import = ctx.executable._index_import install_path = ctx.attr.install_path + separate_index_build_output_base = ctx.attr.separate_index_build_output_base name = ctx.attr.name workspace_directory = ctx.attr.workspace_directory @@ -698,6 +701,7 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \ selected_model_versions_generator = ( ctx.executable._selected_model_versions_generator ), + separate_index_build_output_base = separate_index_build_output_base, target_name_mode = ctx.attr.target_name_mode, unique_directories = ctx.executable._unique_directories, unowned_extra_files = ctx.files.unowned_extra_files, @@ -817,6 +821,7 @@ def _xcodeproj_attrs( "runner_label": attr.string(mandatory = True), "scheme_autogeneration_config": attr.string_list_dict(mandatory = True), "scheme_autogeneration_mode": attr.string(mandatory = True), + "separate_index_build_output_base": attr.bool(mandatory = True), "target_name_mode": attr.string(mandatory = True), "top_level_device_targets": attr.label_list( cfg = target_transitions.device, diff --git a/xcodeproj/internal/xcodeproj_runner.bzl b/xcodeproj/internal/xcodeproj_runner.bzl index 2e92a4c88..f4e500cda 100644 --- a/xcodeproj/internal/xcodeproj_runner.bzl +++ b/xcodeproj/internal/xcodeproj_runner.bzl @@ -219,6 +219,7 @@ def _write_generator_build_file( "%runner_label%": runner_label, "%scheme_autogeneration_config%": str(attr.scheme_autogeneration_config), "%scheme_autogeneration_mode%": attr.scheme_autogeneration_mode, + "%separate_index_build_output_base%": str(attr._separate_index_build_output_base[BuildSettingInfo].value), "%tags%": tags, "%target_name_mode%": attr.target_name_mode, "%testonly%": str(attr.testonly), @@ -526,6 +527,10 @@ xcodeproj_runner = rule( allow_single_file = True, default = Label("//xcodeproj/internal/templates:runner.sh"), ), + "_separate_index_build_output_base": attr.label( + default = Label("//xcodeproj:separate_index_build_output_base"), + providers = [BuildSettingInfo], + ), }, executable = True, )