Skip to content

Commit 3f53b4d

Browse files
Add xcodeproj.import_index_build_indexstores (#3034)
Allows disabling importing of Index Build generated indexstores, which we started doing in aa25576. Signed-off-by: Brentley Jones <github@brentleyjones.com>
1 parent 00bf884 commit 3f53b4d

File tree

18 files changed

+79
-7
lines changed

18 files changed

+79
-7
lines changed

docs/bazel.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcodeproj")
6060
<pre>
6161
xcodeproj(<a href="#xcodeproj-name">name</a>, <a href="#xcodeproj-adjust_schemes_for_swiftui_previews">adjust_schemes_for_swiftui_previews</a>, <a href="#xcodeproj-associated_extra_files">associated_extra_files</a>, <a href="#xcodeproj-bazel_path">bazel_path</a>, <a href="#xcodeproj-bazel_env">bazel_env</a>,
6262
<a href="#xcodeproj-build_mode">build_mode</a>, <a href="#xcodeproj-config">config</a>, <a href="#xcodeproj-default_xcode_configuration">default_xcode_configuration</a>, <a href="#xcodeproj-extra_files">extra_files</a>,
63-
<a href="#xcodeproj-fail_for_invalid_extra_files_targets">fail_for_invalid_extra_files_targets</a>, <a href="#xcodeproj-focused_targets">focused_targets</a>, <a href="#xcodeproj-generation_mode">generation_mode</a>, <a href="#xcodeproj-install_directory">install_directory</a>,
64-
<a href="#xcodeproj-ios_device_cpus">ios_device_cpus</a>, <a href="#xcodeproj-ios_simulator_cpus">ios_simulator_cpus</a>, <a href="#xcodeproj-minimum_xcode_version">minimum_xcode_version</a>, <a href="#xcodeproj-post_build">post_build</a>, <a href="#xcodeproj-pre_build">pre_build</a>,
65-
<a href="#xcodeproj-project_name">project_name</a>, <a href="#xcodeproj-project_options">project_options</a>, <a href="#xcodeproj-scheme_autogeneration_mode">scheme_autogeneration_mode</a>, <a href="#xcodeproj-scheme_autogeneration_config">scheme_autogeneration_config</a>,
66-
<a href="#xcodeproj-schemes">schemes</a>, <a href="#xcodeproj-target_name_mode">target_name_mode</a>, <a href="#xcodeproj-top_level_targets">top_level_targets</a>, <a href="#xcodeproj-tvos_device_cpus">tvos_device_cpus</a>, <a href="#xcodeproj-tvos_simulator_cpus">tvos_simulator_cpus</a>,
67-
<a href="#xcodeproj-unfocused_targets">unfocused_targets</a>, <a href="#xcodeproj-visionos_device_cpus">visionos_device_cpus</a>, <a href="#xcodeproj-visionos_simulator_cpus">visionos_simulator_cpus</a>, <a href="#xcodeproj-watchos_device_cpus">watchos_device_cpus</a>,
68-
<a href="#xcodeproj-watchos_simulator_cpus">watchos_simulator_cpus</a>, <a href="#xcodeproj-xcode_configurations">xcode_configurations</a>, <a href="#xcodeproj-xcschemes">xcschemes</a>, <a href="#xcodeproj-kwargs">kwargs</a>)
63+
<a href="#xcodeproj-fail_for_invalid_extra_files_targets">fail_for_invalid_extra_files_targets</a>, <a href="#xcodeproj-focused_targets">focused_targets</a>, <a href="#xcodeproj-generation_mode">generation_mode</a>,
64+
<a href="#xcodeproj-import_index_build_indexstores">import_index_build_indexstores</a>, <a href="#xcodeproj-install_directory">install_directory</a>, <a href="#xcodeproj-ios_device_cpus">ios_device_cpus</a>, <a href="#xcodeproj-ios_simulator_cpus">ios_simulator_cpus</a>,
65+
<a href="#xcodeproj-minimum_xcode_version">minimum_xcode_version</a>, <a href="#xcodeproj-post_build">post_build</a>, <a href="#xcodeproj-pre_build">pre_build</a>, <a href="#xcodeproj-project_name">project_name</a>, <a href="#xcodeproj-project_options">project_options</a>,
66+
<a href="#xcodeproj-scheme_autogeneration_mode">scheme_autogeneration_mode</a>, <a href="#xcodeproj-scheme_autogeneration_config">scheme_autogeneration_config</a>, <a href="#xcodeproj-schemes">schemes</a>, <a href="#xcodeproj-target_name_mode">target_name_mode</a>,
67+
<a href="#xcodeproj-top_level_targets">top_level_targets</a>, <a href="#xcodeproj-tvos_device_cpus">tvos_device_cpus</a>, <a href="#xcodeproj-tvos_simulator_cpus">tvos_simulator_cpus</a>, <a href="#xcodeproj-unfocused_targets">unfocused_targets</a>,
68+
<a href="#xcodeproj-visionos_device_cpus">visionos_device_cpus</a>, <a href="#xcodeproj-visionos_simulator_cpus">visionos_simulator_cpus</a>, <a href="#xcodeproj-watchos_device_cpus">watchos_device_cpus</a>, <a href="#xcodeproj-watchos_simulator_cpus">watchos_simulator_cpus</a>,
69+
<a href="#xcodeproj-xcode_configurations">xcode_configurations</a>, <a href="#xcodeproj-xcschemes">xcschemes</a>, <a href="#xcodeproj-kwargs">kwargs</a>)
6970
</pre>
7071

7172
Creates an `.xcodeproj` file in the workspace when run.
@@ -108,6 +109,7 @@ xcodeproj(
108109
| <a id="xcodeproj-fail_for_invalid_extra_files_targets"></a>fail_for_invalid_extra_files_targets | Optional. Determines wether, when processing targets, invalid extra files without labels will fail or just emit a warning. | `True` |
109110
| <a id="xcodeproj-focused_targets"></a>focused_targets | Optional. A `list` of target labels as `string` values.<br><br>If specified, only these targets will be included in the generated project; all other targets will be excluded, as if they were listed explicitly in the `unfocused_targets` argument. The labels must match transitive dependencies of the targets specified in the `top_level_targets` argument. | `[]` |
110111
| <a id="xcodeproj-generation_mode"></a>generation_mode | Optional. Determines how the project is generated.<br><br><ul> <li> `incremental`: The project is generated in pieces by multiple Bazel actions and then combined together. This allows for incremental generation where some of those pieces can be reused in subsequent project generations.<br><br> The way information is collected and processed has also changed compared to legacy generation mode. This has resulted in some bug fixes and improvements that don't exist in legacy generation mode.<br><br> **Note:** Only `build_mode = "bazel"` is supported in this mode.<br><br> **Note:** The [`xcschemes`](#xcodeproj-xcschemes) attribute is used instead of [`schemes`](#xcodeproj-schemes) in this mode. </li> <li> `legacy`: The project is generated by a monolith Bazel action.<br><br> This mode is deprecated and will be removed in a future version of **rules_xcodeproj**. </li> </ul> | `"incremental"` |
112+
| <a id="xcodeproj-import_index_build_indexstores"></a>import_index_build_indexstores | Optional. Whether to import the index stores generated by Index Build.<br><br>This is useful if you want to use the index stores generated by Index Build to speed up Xcode's indexing process. You may not want this enabled if the additional work (mainly disk IO) of importing the index stores is not worth it for your project.<br><br>This only applies when using `generation_mode = "incremental"`. | `True` |
111113
| <a id="xcodeproj-install_directory"></a>install_directory | Optional. The directory where the generated project will be written to.<br><br>The path is relative to the workspace root.<br><br>Defaults to the directory that the `xcodeproj` target is declared in (e.g. if the `xcodeproj` target is declared in `//foo/bar:BUILD` then the default value is `"foo/bar"`). Use `""` to have the project generated in the workspace root. | `None` |
112114
| <a id="xcodeproj-ios_device_cpus"></a>ios_device_cpus | Optional. The value to use for `--ios_multi_cpus` when building the transitive dependencies of the targets specified in the `top_level_targets` argument with the `"device"` `target_environment`.<br><br>**Warning:** Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the `top_level_targets` argument with the `"device"` `target_environment`, even if they aren't iOS targets. | `"arm64"` |
113115
| <a id="xcodeproj-ios_simulator_cpus"></a>ios_simulator_cpus | Optional. The value to use for `--ios_multi_cpus` when building the transitive dependencies of the targets specified in the `top_level_targets` argument with the `"simulator"` `target_environment`.<br><br>If no value is specified, it defaults to the simulator cpu that goes with `--host_cpu` (i.e. `sim_arm64` on Apple Silicon and `x86_64` on Intel).<br><br>**Warning:** Changing this value will affect the Starlark transition hash of all transitive dependencies of the targets specified in the `top_level_targets` argument with the `"simulator"` `target_environment`, even if they aren't iOS targets. | `None` |

examples/integration/test/fixtures/bwb.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rules_ios/test/fixtures/bwb.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def _write_pbxproj_prefix_test_impl(ctx):
5050
default_xcode_configuration = ctx.attr.default_xcode_configuration,
5151
execution_root_file = ctx.attr.execution_root_file,
5252
generator_name = "a_generator_name",
53+
import_index_build_indexstores = (
54+
ctx.attr.import_index_build_indexstores
55+
),
5356
index_import = ctx.attr.index_import,
5457
install_path = "a/project.xcodeproj",
5558
minimum_xcode_version = ctx.attr.minimum_xcode_version,
@@ -140,6 +143,7 @@ write_pbxproj_prefix_test = unittest.make(
140143
"config": attr.string(mandatory = True),
141144
"default_xcode_configuration": attr.string(mandatory = True),
142145
"execution_root_file": attr.string(mandatory = True),
146+
"import_index_build_indexstores": attr.bool(mandatory = True),
143147
"index_import": attr.string(mandatory = True),
144148
"minimum_xcode_version": attr.string(mandatory = True),
145149
"platforms": attr.string_list(mandatory = True),
@@ -175,6 +179,7 @@ def write_pbxproj_prefix_test_suite(name):
175179
config,
176180
default_xcode_configuration,
177181
execution_root_file,
182+
import_index_build_indexstores,
178183
index_import,
179184
minimum_xcode_version,
180185
platforms,
@@ -198,6 +203,7 @@ def write_pbxproj_prefix_test_suite(name):
198203
config = config,
199204
default_xcode_configuration = default_xcode_configuration,
200205
execution_root_file = execution_root_file,
206+
import_index_build_indexstores = import_index_build_indexstores,
201207
index_import = index_import,
202208
minimum_xcode_version = minimum_xcode_version,
203209
platforms = platforms,
@@ -226,6 +232,7 @@ def write_pbxproj_prefix_test_suite(name):
226232
config = "rules_xcodeproj",
227233
default_xcode_configuration = "Debug",
228234
execution_root_file = "an/execution/root/file",
235+
import_index_build_indexstores = True,
229236
index_import = "some/path/to/index_import",
230237
minimum_xcode_version = "14.2.1",
231238
platforms = [
@@ -261,6 +268,8 @@ def write_pbxproj_prefix_test_suite(name):
261268
"some/path/to/resolved_repositories_file",
262269
# minimumXcodeVersion
263270
"14.2.1",
271+
# importIndexBuildIndexstores
272+
"1",
264273
# defaultXcodeConfiguration
265274
"Debug",
266275
# developmentRegion
@@ -286,6 +295,7 @@ def write_pbxproj_prefix_test_suite(name):
286295
config = "custom_rxcp_config",
287296
default_xcode_configuration = "Release",
288297
execution_root_file = "an/execution/root/file",
298+
import_index_build_indexstores = False,
289299
index_import = "some/path/to/index_import",
290300
platforms = [
291301
"MACOS",
@@ -324,6 +334,8 @@ def write_pbxproj_prefix_test_suite(name):
324334
"some/path/to/resolved_repositories_file",
325335
# minimumXcodeVersion
326336
"14.2.1",
337+
# importIndexBuildIndexstores
338+
"0",
327339
# defaultXcodeConfiguration
328340
"Release",
329341
# developmentRegion

tools/generators/legacy/src/Generator/CreateProject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ $(SYMROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
9696
"ENABLE_STRICT_OBJC_MSGSEND": true,
9797
"ENABLE_USER_SCRIPT_SANDBOXING": false,
9898
"GCC_OPTIMIZATION_LEVEL": "0",
99+
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
99100
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
100101
"INDEX_FORCE_SCRIPT_EXECUTION": true,
101102
"INDEX_IMPORT": indexImport,

tools/generators/legacy/test/CreateProjectTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ $(INDEXING_DEPLOYMENT_LOCATION__$(INDEX_ENABLE_BUILD_ARENA)),
6464
"ENABLE_STRICT_OBJC_MSGSEND": true,
6565
"ENABLE_USER_SCRIPT_SANDBOXING": false,
6666
"GCC_OPTIMIZATION_LEVEL": "0",
67+
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
6768
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
6869
"INDEX_FORCE_SCRIPT_EXECUTION": true,
6970
"INDEX_IMPORT": "/tmp/index-import",
@@ -220,6 +221,7 @@ $(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)
220221
"LD": "$(BAZEL_INTEGRATION_DIR)/ld.sh",
221222
"LDPLUSPLUS": "$(BAZEL_INTEGRATION_DIR)/ld.sh",
222223
"LIBTOOL": "$(BAZEL_INTEGRATION_DIR)/libtool.sh",
224+
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
223225
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
224226
"INDEX_FORCE_SCRIPT_EXECUTION": true,
225227
"INDEX_IMPORT": "/tmp/index-import",

tools/generators/pbxproj_prefix/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ Here is an example output:
214214
ENABLE_STRICT_OBJC_MSGSEND = YES;
215215
ENABLE_USER_SCRIPT_SANDBOXING = NO;
216216
GCC_OPTIMIZATION_LEVEL = 0;
217+
IMPORT_INDEX_BUILD_INDEXSTORES = YES;
217218
INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)";
218219
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import";
219220
INDEXING_PROJECT_DIR__ = "$(INDEXING_PROJECT_DIR__NO)";
@@ -276,6 +277,7 @@ Here is an example output:
276277
ENABLE_STRICT_OBJC_MSGSEND = YES;
277278
ENABLE_USER_SCRIPT_SANDBOXING = NO;
278279
GCC_OPTIMIZATION_LEVEL = 0;
280+
IMPORT_INDEX_BUILD_INDEXSTORES = YES;
279281
INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)";
280282
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import";
281283
INDEXING_PROJECT_DIR__ = "$(INDEXING_PROJECT_DIR__NO)";

tools/generators/pbxproj_prefix/src/Generator/Arguments.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Minimum Xcode version that the generated project supports.
4747
""")
4848
var minimumXcodeVersion: SemanticVersion
4949

50+
@Argument(
51+
help: "Whether to import index build indexstores.",
52+
transform: { $0 == "1" }
53+
)
54+
var importIndexBuildIndexstores: Bool
55+
5056
@Argument(help: "Name of the default Xcode configuration.")
5157
var defaultXcodeConfiguration: String
5258

tools/generators/pbxproj_prefix/src/Generator/Environment.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension Generator {
3131

3232
let pbxProjectBuildSettings: (
3333
_ config: String,
34+
_ importIndexBuildIndexstores: Bool,
3435
_ indexImport: String,
3536
_ indexingProjectDir: String,
3637
_ projectDir: String,

tools/generators/pbxproj_prefix/src/Generator/Generator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct Generator {
4949
let pbxProjectPrefixPartial = environment.pbxProjectPrefixPartial(
5050
/*buildSettings:*/ environment.pbxProjectBuildSettings(
5151
/*config:*/ arguments.config,
52+
/*importIndexBuildIndexstores:*/ arguments
53+
.importIndexBuildIndexstores,
5254
/*indexImport:*/ arguments.indexImport,
5355
/*indexingProjectDir:*/ environment.indexingProjectDir(
5456
/*projectDir:*/ projectDir

0 commit comments

Comments
 (0)