Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcodeproj")
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-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>)
<a href="#xcodeproj-import_index_build_indexstores">import_index_build_indexstores</a>, <a href="#xcodeproj-include_package_generated_files_group">include_package_generated_files_group</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 @@ -111,6 +111,7 @@ xcodeproj(
| <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-include_package_generated_files_group"></a>include_package_generated_files_group | Optional. Whether the project will create a `Bazel Generated Files` child group for packages with generated files.<br><br>This is useful for finding generated files more easily in the project navigator by creating a child group in the path tree for each generated files' package.<br><br>This only applies when using `generation_mode = "incremental"`. | `False` |
| <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
1 change: 1 addition & 0 deletions examples/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ string_flag(
extra_files = EXTRA_FILES,
fail_for_invalid_extra_files_targets = FAIL_FOR_INVALID_EXTRA_FILES_TARGETS,
generation_mode = generation_mode,
include_package_generated_files_group = True,
ios_simulator_cpus = simulator_cpu,
pre_build = PRE_BUILD,
project_name = "Integration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _write_files_and_groups_test_impl(ctx):

# Act

mock_files = [mock_actions.mock_file(f) for f in ctx.attr.files]

(
pbxproject_known_regions,
files_and_groups,
Expand All @@ -63,9 +65,10 @@ def _write_files_and_groups_test_impl(ctx):
compile_stub_needed = ctx.attr.compile_stub_needed,
execution_root_file = ctx.attr.execution_root_file,
generator_name = "a_generator_name",
files = depset(ctx.attr.files),
files = depset(mock_files),
file_paths = depset(ctx.attr.file_paths),
folders = depset(ctx.attr.folders),
include_package_generated_files_group = False,
install_path = ctx.attr.install_path,
project_options = ctx.attr.project_options,
selected_model_versions_file = ctx.attr.selected_model_versions_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ extension ElementCreator {
for node: PathTreeNode,
parentBazelPath: BazelPath,
specialRootGroupType: SpecialRootGroupType?,
createGroupChild: CreateGroupChild
createGroupChild: CreateGroupChild,
createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild.ElementAndChildren {
return callable(
/*node:*/ node,
/*parentBazelPath:*/ parentBazelPath,
/*specialRootGroupType:*/ specialRootGroupType,
/*createGroupChild:*/ createGroupChild,
/*createGroupChildElements:*/ createGroupChildElements,
/*createGroupElement:*/ createGroupElement
/*createGroupElement:*/ createGroupElement,
/*createSpecialGroupElement:*/ createSpecialGroupElement
)
}
}
Expand All @@ -50,7 +52,8 @@ extension ElementCreator.CreateGroup {
_ specialRootGroupType: SpecialRootGroupType?,
_ createGroupChild: ElementCreator.CreateGroupChild,
_ createGroupChildElements: ElementCreator.CreateGroupChildElements,
_ createGroupElement: ElementCreator.CreateGroupElement
_ createGroupElement: ElementCreator.CreateGroupElement,
_ createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild.ElementAndChildren

static func defaultCallable(
Expand All @@ -59,33 +62,54 @@ extension ElementCreator.CreateGroup {
specialRootGroupType: SpecialRootGroupType?,
createGroupChild: ElementCreator.CreateGroupChild,
createGroupChildElements: ElementCreator.CreateGroupChildElements,
createGroupElement: ElementCreator.CreateGroupElement
createGroupElement: ElementCreator.CreateGroupElement,
createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild.ElementAndChildren {
let bazelPath = parentBazelPath + node
let isBazelGenerated = node.name.hasPrefix("bazel-out")
let bazelPath: BazelPath
if isBazelGenerated {
bazelPath = BazelPath(node.name)
} else {
bazelPath = parentBazelPath + node
}
let name = node.name

let groupChildren = node.children.map { node in
return createGroupChild(
for: node,
parentBazelPath: bazelPath,
specialRootGroupType: specialRootGroupType
specialRootGroupType: specialRootGroupType,
createSpecialGroupElement: createSpecialGroupElement
)
}

let children = createGroupChildElements(
parentBazelPath: bazelPath,
groupChildren: groupChildren
)

let (
group,
resolvedRepository
) = createGroupElement(
name: name,
bazelPath: bazelPath,
specialRootGroupType: specialRootGroupType,
childIdentifiers: children.elements.map(\.object.identifier)
)

let group: Element
var resolvedRepository: ResolvedRepository? = nil
if isBazelGenerated {
group = createSpecialGroupElement(
specialRootGroupType: .bazelGenerated,
childIdentifiers: children.elements.map(\.object.identifier),
useRootStableIdentifiers: false,
bazelPath: bazelPath
)
} else {
(
group,
resolvedRepository
) = createGroupElement(
name: name,
bazelPath: bazelPath,
specialRootGroupType: specialRootGroupType,
childIdentifiers: children.elements.map(\.object.identifier)
)
}



return GroupChild.ElementAndChildren(
bazelPath: bazelPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extension ElementCreator {
func callAsFunction(
for node: PathTreeNode,
parentBazelPath: BazelPath,
specialRootGroupType: SpecialRootGroupType?
specialRootGroupType: SpecialRootGroupType?,
createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild {
return callable(
/*node:*/ node,
Expand All @@ -39,7 +40,8 @@ extension ElementCreator {
/*createGroup:*/ createGroup,
/*createGroupChild:*/ self,
/*createLocalizedFiles:*/ createLocalizedFiles,
/*createVersionGroup:*/ createVersionGroup
/*createVersionGroup:*/ createVersionGroup,
/*createSpecialGroupElement:*/ createSpecialGroupElement
)
}
}
Expand All @@ -56,7 +58,8 @@ extension ElementCreator.CreateGroupChild {
_ createGroup: ElementCreator.CreateGroup,
_ createGroupChild: ElementCreator.CreateGroupChild,
_ createLocalizedFiles: ElementCreator.CreateLocalizedFiles,
_ createVersionGroup: ElementCreator.CreateVersionGroup
_ createVersionGroup: ElementCreator.CreateVersionGroup,
_ createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild

static func defaultCallable(
Expand All @@ -67,7 +70,8 @@ extension ElementCreator.CreateGroupChild {
createGroup: ElementCreator.CreateGroup,
createGroupChild: ElementCreator.CreateGroupChild,
createLocalizedFiles: ElementCreator.CreateLocalizedFiles,
createVersionGroup: ElementCreator.CreateVersionGroup
createVersionGroup: ElementCreator.CreateVersionGroup,
createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChild {
guard !node.children.isEmpty else {
// File
Expand Down Expand Up @@ -108,7 +112,8 @@ extension ElementCreator.CreateGroupChild {
for: node,
parentBazelPath: parentBazelPath,
specialRootGroupType: specialRootGroupType,
createGroupChild: createGroupChild
createGroupChild: createGroupChild,
createSpecialGroupElement: createSpecialGroupElement
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ extension ElementCreator.CreateGroupElement {
} else {
nameAttribute = ""
}

// The tabs for indenting are intentional
let content = #"""
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension ElementCreator {
private let createGroupChildElements: CreateGroupChildElements
private let createInternalGroup: CreateInternalGroup
private let createSpecialRootGroup: CreateSpecialRootGroup
private let createSpecialGroupElement: CreateSpecialRootGroupElement

private let callable: Callable

Expand All @@ -23,6 +24,7 @@ extension ElementCreator {
createGroupChildElements: CreateGroupChildElements,
createInternalGroup: CreateInternalGroup,
createSpecialRootGroup: CreateSpecialRootGroup,
createSpecialGroupElement: CreateSpecialRootGroupElement,
callable: @escaping Callable
) {
self.includeCompileStub = includeCompileStub
Expand All @@ -32,6 +34,7 @@ extension ElementCreator {
self.createGroupChildElements = createGroupChildElements
self.createInternalGroup = createInternalGroup
self.createSpecialRootGroup = createSpecialRootGroup
self.createSpecialGroupElement = createSpecialGroupElement

self.callable = callable
}
Expand All @@ -47,7 +50,8 @@ extension ElementCreator {
/*createGroupChild:*/ createGroupChild,
/*createGroupChildElements:*/ createGroupChildElements,
/*createInternalGroup:*/ createInternalGroup,
/*createSpecialRootGroup:*/ createSpecialRootGroup
/*createSpecialRootGroup:*/ createSpecialRootGroup,
/*createSpecialGroupElement:*/ createSpecialGroupElement
)
}
}
Expand All @@ -64,7 +68,8 @@ extension ElementCreator.CreateRootElements {
_ createGroupChild: ElementCreator.CreateGroupChild,
_ createGroupChildElements: ElementCreator.CreateGroupChildElements,
_ createInternalGroup: ElementCreator.CreateInternalGroup,
_ createSpecialRootGroup: ElementCreator.CreateSpecialRootGroup
_ createSpecialRootGroup: ElementCreator.CreateSpecialRootGroup,
_ createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChildElements

static func defaultCallable(
Expand All @@ -75,7 +80,8 @@ extension ElementCreator.CreateRootElements {
createGroupChild: ElementCreator.CreateGroupChild,
createGroupChildElements: ElementCreator.CreateGroupChildElements,
createInternalGroup: ElementCreator.CreateInternalGroup,
createSpecialRootGroup: ElementCreator.CreateSpecialRootGroup
createSpecialRootGroup: ElementCreator.CreateSpecialRootGroup,
createSpecialGroupElement: ElementCreator.CreateSpecialRootGroupElement
) -> GroupChildElements {
let bazelPath = BazelPath("")

Expand Down Expand Up @@ -117,7 +123,8 @@ extension ElementCreator.CreateRootElements {
createGroupChild(
for: node,
parentBazelPath: bazelPath,
specialRootGroupType: nil
specialRootGroupType: nil,
createSpecialGroupElement: createSpecialGroupElement
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ extension ElementCreator.CreateSpecialRootGroup {
return createGroupChild(
for: node,
parentBazelPath: bazelPath,
specialRootGroupType: specialRootGroupType
specialRootGroupType: specialRootGroupType,
createSpecialGroupElement: createSpecialRootGroupElement
)
}

Expand All @@ -76,7 +77,9 @@ extension ElementCreator.CreateSpecialRootGroup {

let group = createSpecialRootGroupElement(
specialRootGroupType: specialRootGroupType,
childIdentifiers: children.elements.map(\.object.identifier)
childIdentifiers: children.elements.map(\.object.identifier),
useRootStableIdentifiers: true,
bazelPath: bazelPath
)

return GroupChild.ElementAndChildren(
Expand Down
Loading