MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
526 stars 84 forks source link

Bug: focused_targets doesn't work properly in 1.3.1 or later #1912

Closed ra1028 closed 1 year ago

ra1028 commented 1 year ago

What happened?

This error was introduced after version 1.3.1 and doesn't occur in 1.3.0. All targets specified in the focused_targets are certainly transitive dependencies of the targets listed in top_level_targets, but project generation fails with the following error.

ERROR: /Users/xxx/.rules_xcodeproj/xcodeproj-sim_arm64-Dev-Debug/BUILD:6:10: in xcodeproj rule //.rules_xcodeproj/xcodeproj-sim_arm64-Dev-Debug:xcodeproj-sim_arm64-Dev-Debug:
Traceback (most recent call last):
    File "/Users/xxx/bazel-output-base/rules_xcodeproj/build_output_base/external/rules_xcodeproj/xcodeproj/internal/xcodeproj_rule.bzl", line 1458, column 25, in _xcodeproj_impl
        ) = _process_targets(
    File "/Users/xxxs/bazel-output-base/rules_xcodeproj/build_output_base/external/rules_xcodeproj/xcodeproj/internal/xcodeproj_rule.bzl", line 333, column 13, in _process_targets
        fail("""\
Error in fail: `focused_targets` contains target(s) that are not transitive dependencies of the targets listed in `top_level_targets`: ["//target:name"]

Are you using an `alias`? `focused_targets` requires labels of the actual targets.

Reproduction steps

Expected behavior

Successfully generate a focused project.

rules_xcodeproj version

1.3.2 or 1.3.1

Bazel version

6.0.0-pre.20220804.3

rules_apple version

d04edf4136b4818662d7126582ec257aee372339

rules_swift version

6153a848f747e90248a8673869c49631f1323ff3

Additional information

No response

brentleyjones commented 1 year ago

I wasn't able to quickly reproduce this. I'll keep trying. A reproduction project would help.

brentleyjones commented 1 year ago

The bazel version might be at play. There are some label string changes we are doing now. Can you upgrade to Bazel 6.0 and try again? Also, are you using bzlmod?

brentleyjones commented 1 year ago

I reproduced it with that old Bazel version. We don't technically support the rolling releases between LTS releases, but I'll see if I can fix this regardless.

brentleyjones commented 1 year ago

Looks like it's broken in Bazel 5 as well. Fix incoming.

ra1028 commented 1 year ago

Thanks!

ra1028 commented 1 year ago

@brentleyjones

I noticed that target focusing in rules_xcodeproj 1.3.3 behaves differently than in 1.3.0. My usage of target focusing is to filter out targets other than ios_framework in Xcode. It's a workaround to get SwiftUI previews working as described here. With 1.3.0, if Xcode contained only ios_framework, the corresponding files were listed in the Compile Sources of the corresponding Xcode target, but in 1.3.3, only _CompileStub_.m appears, and Xcode doesn't show source files in the file tree anymore.

brentleyjones commented 1 year ago

Interesting, can you open up a new issue, ideally with a small repro? I'll get this fixed.

brentleyjones commented 1 year ago

I believe this commit might be the break: https://github.com/MobileNativeFoundation/rules_xcodeproj/commit/ed31d6916858f3099ba1a95750f5309913370a8d

That change is wrong because we want to merge unfocused targets.

I believe we have logic as well to focus targets that we merge, which goes along with this.

cc: @mattrobmattrob

mattrobmattrob commented 1 year ago

I believe this commit might be the break: https://github.com/MobileNativeFoundation/rules_xcodeproj/commit/ed31d6916858f3099ba1a95750f5309913370a8d

Feel free to revert, @brentleyjones. I'm away from the computer for a couple of days.

brentleyjones commented 1 year ago

I will. And when you get back feel free to put another change in that does what you intended while still accounting for this case :+1:.

brentleyjones commented 1 year ago

@ra1028 Can you confirm that https://github.com/MobileNativeFoundation/rules_xcodeproj/pull/1923 fixes this for you?

ra1028 commented 1 year ago

@brentleyjones Thanks. I'll check it later on. Would you still like me to open up a new issue for it?

brentleyjones commented 1 year ago

No, that's fine.