Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LLlkaiwen opened this issue Jul 25, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@LLlkaiwen
Copy link

LLlkaiwen commented Jul 25, 2024

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

@LLlkaiwen LLlkaiwen added the bug Something isn't working label Jul 25, 2024
@brentleyjones
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

LLlkaiwen commented Nov 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants