MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
528 stars 86 forks source link

Bug: same indexstore is imported two times with different targetPathOverride #3059

Open LLlkaiwen opened 4 months ago

LLlkaiwen commented 4 months ago

Description

I find two different units in Datastore for one source file after Indexing ends.

image

The two units are both imported from bazel generated indexstore because Xcode does not index the file 'ContentView.swift' I think the reason may be that one indexstore is recorded two times with diffrent targetPathOverride in bi.filelist.

image

Reproduction steps

we can reproduce the behavior in examples/rules_ios.

  1. bazel run //:xcodeproj-incremental
  2. open rules_ios.xcodeproj
  3. wait for indexing finish
  4. check if there are two units for ContentView.swift in Index.noindex/DataStore/v5/units

Expected behavior

one indexstore should not be imported with different targetPathOverride

rules_xcodeproj version

2.5.2

Xcode version

15.0

Bazel version

7.1.1

rules_apple version

No response

rules_swift version

No response

Additional information

No response

brentleyjones commented 4 months ago

one indexstore should not be imported with different targetPathOverride

But that's the point of targetPathOverride. It allows both the merged target and the library target to have indexing information. Though it should only import twice if the library and the merged target both exist in Xcode, which can happen if the library can merge successfully into one target but not another.

LLlkaiwen commented 4 months ago

As I know, the targetPathOverride is only used to remap the path of Object files. Also I find that the imported index will works if only the source file path is remapped correctly. So, maybe we can import all indexstores with empty targetPathOverride only once.

brentleyjones commented 4 months ago

The object path needs to match the the one the target would create, otherwise Xcode doesn't see unit file and recreates it (because it uses the same object path and gets the same expected hash).

brentleyjones commented 3 months ago

I see now how this will import the same indexstore twice even if the merged library never appears bare in the project. Ideally it should only import an indexstore with multiple targetOverridePath if there is a target in the project for that targetOverridePath. This is slightly tricky because with target (un)focusing we may want to import and indexstore even though no target is generated.

LLlkaiwen commented 3 weeks ago

When generating the xcodeproj, we can get which xcode target everybazel target belongs to. And we can also get which bazel target ervey indexstore belong to. So, if we record the relation between xcode targetand bazel target when generating xcodeproj, we can use that information to find which xcode target every indexstore real belongs to when importing index