rules_xcodeproj icon indicating copy to clipboard operation
rules_xcodeproj copied to clipboard

Bug: Resource groups appear in a project with a target focusing

Open CognitiveDisson opened this issue 3 years ago • 3 comments

Describe the bug

In BwB mode, resource group files are included in the project even if the target is unfocused. There is no way to unfocus them.

Example

We have a swift library:

swift_library(
  name = "SomeSwiftLibrary",
  data = ["//Some:SomeSwiftLibrary_Resources"]
)

and a resource group:

apple_resource_group(
  name = "SomeSwiftLibrary_Resources",
  resources = [
    "/Some:Resources/asset.xcassets/Contents.json",
    "/Some:Resources/asset.xcassets/Contents.json",
    "/Some:Resources/asset.xcassets/image.imageset/image.png",
    "/Some:Resources/asset.xcassets/image.imageset/[email protected]", 
    "//Some:Resources/asset.xcassets/image.imageset/[email protected]"
  ],
)

Even if we add //Some:SomeSwiftLibrary_Resources and //Some:SomeSwiftLibrary to unfocused_targets, the asset.xcassets will still be present in the project.

xcodeproj(
    name = "xcodeproj",
    project_name = "Project",
    build_mode = "bazel",
    top_level_targets = ["//iOSApp"],
    focused_targets = [...], // do not contain `SomeSwiftLibrary`
    unfocused_targets = ["/Some:SomeSwiftLibrary", "//Some:SomeSwiftLibrary_Resources"],
)

Expected behavior

If a target is not focused, all of its resource files should not appear in the project.

CognitiveDisson avatar Feb 03 '23 17:02 CognitiveDisson

Seems we will need to associate owner to resources and extra_files in internal/resources.bzl, instead of just the file_paths. Then when we process those in xcodeproj_rule.bzl, at least for top-level bundles that aren't resource bundles, we can filter those files to only ones in focused_labels.

brentleyjones avatar Feb 03 '23 17:02 brentleyjones

I've tried to put the resources into the unfocused_targets declaration, but it didn't work too. The focus mode is amazing and this project is what makes Bazel productive for our project. Please let me know if I can help with something, this bugfix is very important to us. Again, thank you for this project!

narlei avatar Mar 23 '23 19:03 narlei

Hi @narlei. My above comment still holds for how I would go about trying to fix this, if you want to take a stab at it. Though it should be noted, right now you can unfocus resource bundles, just not resource groups.

brentleyjones avatar Mar 23 '23 19:03 brentleyjones