Skip to content

Add xcodeproj_synchronized_folders aspect hint - #3378

Open
erneestoc wants to merge 3 commits into
MobileNativeFoundation:mainfrom
erneestoc:ec/sync-folders-hint
Open

erneestoc wants to merge 3 commits into
MobileNativeFoundation:mainfrom
erneestoc:ec/sync-folders-hint

Conversation

@erneestoc

Copy link
Copy Markdown
Contributor

Last of three PRs adding Xcode 16 synchronized folders, split out of #3373. Based on #3377; only the last commit is new.

Adds the xcodeproj_synchronized_folders aspect hint:

xcodeproj_synchronized_folders(
    name = "sources_folder",
    folders = ["Sources"],  # relative to the hinted target's package
)

swift_library(
    name = "Characters",
    srcs = glob(["Sources/**/*.swift"]),
    aspect_hints = [":sources_folder"],
)

The target's srcs and non_arc_srcs under those folders are replaced by the folder in Xcode, so files added in Xcode or on disk show up without regenerating the project. Bazel still builds from srcs.

Tested with //test/internal/xcodeproj_synchronized_folders and on a sample app: the project builds and tests in Xcode, a new file appears in the target without regenerating, and indexing and jump to definition work.

Xcode rewrites project.pbxproj the first time a synchronized folder's contents change, unless the file already matches its format; #3374 and #3375 make it match.

Adds an optional `--synchronized-folders-file` to `files_and_groups`.
Each folder in it is created as a `PBXFileSystemSynchronizedRootGroup`
(Xcode 16's buildable folders) in place of a `PBXFileReference`, and file
paths inside it are left out of the tree, since Xcode lists the folder's
contents itself.

The group's identifier only depends on its path
(`Identifiers.FilesAndGroups.synchronizedRootGroup`), so that targets
created by other generators can reference it.

Nothing passes the flag yet, so generated projects don't change.

Signed-off-by: Ernesto Cambuston <e.cambuston@gmail.com>
Targets take a list of synchronized folders after `non_arc_srcs`, and
reference each one's `PBXFileSystemSynchronizedRootGroup` in
`fileSystemSynchronizedGroups`. For now, the list is always empty.

`pbxproj_prefix` gets an optional `--uses-synchronized-folders`, which
sets `objectVersion` to 70, what Xcode writes for projects with
synchronized folders. Without it, the object version doesn't change.

Signed-off-by: Ernesto Cambuston <e.cambuston@gmail.com>
`xcodeproj_synchronized_folders(folders = [...])`, added to a target's
`aspect_hints`, makes the given folders (relative to the target's
package) Xcode 16 synchronized folders: the target's `srcs` and
`non_arc_srcs` in them are replaced by the folder, so files added to it
in Xcode or on disk appear without regenerating the project. Sources
still come from the target's `srcs` (e.g. a `glob`) when building with
Bazel.

The folders are passed to `files_and_groups` and `pbxnativetargets`,
and projects with any use object version 70.

Signed-off-by: Ernesto Cambuston <e.cambuston@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant