Skip to content

Commit

Permalink
Add xcodeproj.import_index_build_indexstores (#3034)
Browse files Browse the repository at this point in the history
Allows disabling importing of Index Build generated indexstores, which
we started doing in aa25576.

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones authored May 29, 2024
1 parent 00bf884 commit 3f53b4d
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 7 deletions.
14 changes: 8 additions & 6 deletions docs/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcodeproj")
<pre>
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>,
<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>,
<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>,
<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>,
<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>,
<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>,
<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>,
<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>)
<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-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>,
<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>,
<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>,
<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>,
<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>,
<a href="#xcodeproj-xcode_configurations">xcode_configurations</a>, <a href="#xcodeproj-xcschemes">xcschemes</a>, <a href="#xcodeproj-kwargs">kwargs</a>)
</pre>

Creates an `.xcodeproj` file in the workspace when run.
Expand Down Expand Up @@ -108,6 +109,7 @@ xcodeproj(
| <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` |
| <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. | `[]` |
| <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"` |
| <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` |
| <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` |
| <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"` |
| <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` |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/internal/pbxproj_partials/write_pbxproj_prefix_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def _write_pbxproj_prefix_test_impl(ctx):
default_xcode_configuration = ctx.attr.default_xcode_configuration,
execution_root_file = ctx.attr.execution_root_file,
generator_name = "a_generator_name",
import_index_build_indexstores = (
ctx.attr.import_index_build_indexstores
),
index_import = ctx.attr.index_import,
install_path = "a/project.xcodeproj",
minimum_xcode_version = ctx.attr.minimum_xcode_version,
Expand Down Expand Up @@ -140,6 +143,7 @@ write_pbxproj_prefix_test = unittest.make(
"config": attr.string(mandatory = True),
"default_xcode_configuration": attr.string(mandatory = True),
"execution_root_file": attr.string(mandatory = True),
"import_index_build_indexstores": attr.bool(mandatory = True),
"index_import": attr.string(mandatory = True),
"minimum_xcode_version": attr.string(mandatory = True),
"platforms": attr.string_list(mandatory = True),
Expand Down Expand Up @@ -175,6 +179,7 @@ def write_pbxproj_prefix_test_suite(name):
config,
default_xcode_configuration,
execution_root_file,
import_index_build_indexstores,
index_import,
minimum_xcode_version,
platforms,
Expand All @@ -198,6 +203,7 @@ def write_pbxproj_prefix_test_suite(name):
config = config,
default_xcode_configuration = default_xcode_configuration,
execution_root_file = execution_root_file,
import_index_build_indexstores = import_index_build_indexstores,
index_import = index_import,
minimum_xcode_version = minimum_xcode_version,
platforms = platforms,
Expand Down Expand Up @@ -226,6 +232,7 @@ def write_pbxproj_prefix_test_suite(name):
config = "rules_xcodeproj",
default_xcode_configuration = "Debug",
execution_root_file = "an/execution/root/file",
import_index_build_indexstores = True,
index_import = "some/path/to/index_import",
minimum_xcode_version = "14.2.1",
platforms = [
Expand Down Expand Up @@ -261,6 +268,8 @@ def write_pbxproj_prefix_test_suite(name):
"some/path/to/resolved_repositories_file",
# minimumXcodeVersion
"14.2.1",
# importIndexBuildIndexstores
"1",
# defaultXcodeConfiguration
"Debug",
# developmentRegion
Expand All @@ -286,6 +295,7 @@ def write_pbxproj_prefix_test_suite(name):
config = "custom_rxcp_config",
default_xcode_configuration = "Release",
execution_root_file = "an/execution/root/file",
import_index_build_indexstores = False,
index_import = "some/path/to/index_import",
platforms = [
"MACOS",
Expand Down Expand Up @@ -324,6 +334,8 @@ def write_pbxproj_prefix_test_suite(name):
"some/path/to/resolved_repositories_file",
# minimumXcodeVersion
"14.2.1",
# importIndexBuildIndexstores
"0",
# defaultXcodeConfiguration
"Release",
# developmentRegion
Expand Down
1 change: 1 addition & 0 deletions tools/generators/legacy/src/Generator/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ $(SYMROOT)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
"ENABLE_STRICT_OBJC_MSGSEND": true,
"ENABLE_USER_SCRIPT_SANDBOXING": false,
"GCC_OPTIMIZATION_LEVEL": "0",
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
"INDEX_FORCE_SCRIPT_EXECUTION": true,
"INDEX_IMPORT": indexImport,
Expand Down
2 changes: 2 additions & 0 deletions tools/generators/legacy/test/CreateProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $(INDEXING_DEPLOYMENT_LOCATION__$(INDEX_ENABLE_BUILD_ARENA)),
"ENABLE_STRICT_OBJC_MSGSEND": true,
"ENABLE_USER_SCRIPT_SANDBOXING": false,
"GCC_OPTIMIZATION_LEVEL": "0",
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
"INDEX_FORCE_SCRIPT_EXECUTION": true,
"INDEX_IMPORT": "/tmp/index-import",
Expand Down Expand Up @@ -220,6 +221,7 @@ $(BUILD_DIR)/$(BAZEL_PACKAGE_BIN_DIR)
"LD": "$(BAZEL_INTEGRATION_DIR)/ld.sh",
"LDPLUSPLUS": "$(BAZEL_INTEGRATION_DIR)/ld.sh",
"LIBTOOL": "$(BAZEL_INTEGRATION_DIR)/libtool.sh",
"IMPORT_INDEX_BUILD_INDEXSTORES": true,
"INDEX_DATA_STORE_DIR": "$(INDEX_DATA_STORE_DIR)",
"INDEX_FORCE_SCRIPT_EXECUTION": true,
"INDEX_IMPORT": "/tmp/index-import",
Expand Down
2 changes: 2 additions & 0 deletions tools/generators/pbxproj_prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ Here is an example output:
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_OPTIMIZATION_LEVEL = 0;
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)";
Expand Down Expand Up @@ -276,6 +277,7 @@ Here is an example output:
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GCC_OPTIMIZATION_LEVEL = 0;
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)";
Expand Down
6 changes: 6 additions & 0 deletions tools/generators/pbxproj_prefix/src/Generator/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Minimum Xcode version that the generated project supports.
""")
var minimumXcodeVersion: SemanticVersion

@Argument(
help: "Whether to import index build indexstores.",
transform: { $0 == "1" }
)
var importIndexBuildIndexstores: Bool

@Argument(help: "Name of the default Xcode configuration.")
var defaultXcodeConfiguration: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension Generator {

let pbxProjectBuildSettings: (
_ config: String,
_ importIndexBuildIndexstores: Bool,
_ indexImport: String,
_ indexingProjectDir: String,
_ projectDir: String,
Expand Down
2 changes: 2 additions & 0 deletions tools/generators/pbxproj_prefix/src/Generator/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct Generator {
let pbxProjectPrefixPartial = environment.pbxProjectPrefixPartial(
/*buildSettings:*/ environment.pbxProjectBuildSettings(
/*config:*/ arguments.config,
/*importIndexBuildIndexstores:*/ arguments
.importIndexBuildIndexstores,
/*indexImport:*/ arguments.indexImport,
/*indexingProjectDir:*/ environment.indexingProjectDir(
/*projectDir:*/ projectDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extension Generator {
///
/// - Parameters:
/// - config: The value to be used for the `BAZEL_CONFIG` build setting.
/// - importIndexBuildIndexstores: Whether to import index build
/// indexstores.
/// - indexImport: The Bazel execution root relative path to the
/// `index_import` executable.
/// - indexingProjectDir: The value returned from
Expand All @@ -17,6 +19,7 @@ extension Generator {
/// - workspace: The absolute path to the Bazel workspace.
static func pbxProjectBuildSettings(
config: String,
importIndexBuildIndexstores: Bool,
indexImport: String,
indexingProjectDir: String,
projectDir: String,
Expand Down Expand Up @@ -93,6 +96,10 @@ extension Generator {
key: "LIBTOOL",
value: #""$(BAZEL_INTEGRATION_DIR)/libtool.sh""#
),
.init(
key: "IMPORT_INDEX_BUILD_INDEXSTORES",
value: importIndexBuildIndexstores ? "YES" : "NO"
),
.init(
key: "INDEXING_PROJECT_DIR__",
value: #""$(INDEXING_PROJECT_DIR__NO)""#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PBXProjectBuildSettingsTests: XCTestCase {
// Arrange

let config = "rxcp_custom_config"
let importIndexBuildIndexstores = false
let indexImport = "external/index-import"
let indexingProjectDir = "/some/indexing/project dir"
let projectDir = "/some/project dir"
Expand Down Expand Up @@ -45,6 +46,7 @@ class PBXProjectBuildSettingsTests: XCTestCase {
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";
Expand Down Expand Up @@ -82,6 +84,7 @@ class PBXProjectBuildSettingsTests: XCTestCase {

let buildSettings = Generator.pbxProjectBuildSettings(
config: config,
importIndexBuildIndexstores: importIndexBuildIndexstores,
indexImport: indexImport,
indexingProjectDir: indexingProjectDir,
projectDir: projectDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ readonly output_groups=(
)

readonly targetid_regex='@{0,2}(.*)//(.*):(.*) ([^\ ]+)$'
if [[ "$BAZEL_TARGET_ID" =~ $targetid_regex ]]; then

indexstores_filelists=()
if [[ "$IMPORT_INDEX_BUILD_INDEXSTORES" == "YES" && \
"$BAZEL_TARGET_ID" =~ $targetid_regex ]]; then
repo="${BASH_REMATCH[1]}"
if [[ "$repo" == "@" ]]; then
repo=""
Expand Down
6 changes: 6 additions & 0 deletions xcodeproj/internal/pbxproj_partials.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def _write_pbxproj_prefix(
default_xcode_configuration,
execution_root_file,
generator_name,
import_index_build_indexstores,
index_import,
install_path,
minimum_xcode_version,
Expand All @@ -632,6 +633,8 @@ def _write_pbxproj_prefix(
execution_root_file: A `File` containing the absolute path to the Bazel
execution root.
generator_name: The name of the `xcodeproj` generator target.
import_index_build_indexstores: Whether to import index build
indexstores.
index_import: The executable `File` for the `index_import` tool.
install_path: The workspace relative path to where the final
`.xcodeproj` will be written.
Expand Down Expand Up @@ -687,6 +690,9 @@ def _write_pbxproj_prefix(
# minimumXcodeVersion
args.add(minimum_xcode_version)

# importIndexBuildIndexstores
args.add("1" if import_index_build_indexstores else "0")

# defaultXcodeConfiguration
args.add(default_xcode_configuration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ xcodeproj(
config = "%config%",
default_xcode_configuration = %default_xcode_configuration%,
generation_shard_count = %generation_shard_count%,
import_index_build_indexstores = %import_index_build_indexstores%,
install_path = "%install_path%",
ios_device_cpus = "%ios_device_cpus%",
ios_simulator_cpus = "%ios_simulator_cpus%",
Expand Down
Loading

0 comments on commit 3f53b4d

Please sign in to comment.