krzysztofzablocki / Sourcery

Meta-programming for Swift, stop writing boilerplate code.
http://merowing.info
MIT License
7.58k stars 605 forks source link

Pull in protocol info from other projects/targets, without generating for those projects/targets #1324

Open jamesormond opened 2 months ago

jamesormond commented 2 months ago

tl;dr

If my local Xcode project contains ProtocolA that confirms to ProtocolB in a different local Xcode project, how can I generate code for ProtocolA?

More Context

My Xcode project, "ProjectA", has two dependencies, both of which are other local Xcode projects that I created, "ProjectB" and "ProjectC". I have this situation in one of my Swift files within ProjectA:

// file within ProjectA

import ProjectB

// sourcery: AutoMockable
protocol ProtocolA: ProtocolB {
    // ProtocolB lives within ProjectB
}

I'm trying to generate mocks for ProtocolA within ProjectA, but I'm failing to include the data associated with ProtocolB. Here is what I'm hoping for, within ProjectA:

// autogenerated file within ProjectA

class ProtocolAMock: ProtocolA {

    // Protocol A related variables/functions
    ...
    ...

    // Protocol B related variables/functions
    ...
    ...

}

I've tried the following two configurations in my config.yml file:

sources:
- path/to/ProjectA/
- path/to/ProjectB/
- path/to/ProjectC/
...
projects:
- file: path/to/ProjectA/
  target:
    name: ProjectA
- file: path/to/ProjectB/
  target:
    name: ProjectB
- file: path/to/ProjectC/
  target:
    name: ProjectC
...

For both of these configurations, it correctly generates the expected results for the protocols defined with ProjectA. However, within ProjectA, it also generates the code for the protocols in ProjectB and ProjectC. Since I'm also running Sourcery separately for ProjectB and ProjectC, I am left with duplicated code across these projects.

Therefore, my question is: how can I configure Sourcery to say "scan projects B and C for data to help generate code in project A, but don't also generate everything for projects B and C"?

I'm imagining something like this (pseudocode):

sources_to_generate:
- path/to/ProjectA
dependencies_to_also_scan:
- path/to/ProjectB/
- path/to/ProjectC/
jamesormond commented 2 months ago

Hello! Just following up on this :)

art-divin commented 2 months ago

πŸ‘‹πŸ» Hello @jamesormond ,

thank you very much for creating issue! 🀝 I will do my best to try to resolve this. But please keep in mind this sounds like more of a full new feature.

Feel free to investigate and resolve this on your own, since Sourcery is open source and every contribution is very much appreciated by the community πŸ‘₯ I will provide guidance in case you would have questions.

jamesormond commented 1 month ago

Sweet, I'll try to implement this feature! Can you point me to where in the codebase you handle the config files, specifically where you handle tags like sources? Thanks!