Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Unable to convert files that reference classes defined in a private pod #115

Open
dylandrones opened this issue Mar 15, 2022 · 2 comments
Open
Labels
bug Something isn't working question Further information is requested

Comments

@dylandrones
Copy link

How can I convert swift files that have references to classes defined in a private pod repo, using Gryphon?

What happens:
I get the following error message when trying to build the Gryphon project from my Xcode workspace.
SourceKit failed to get an expression's type. Try running gryphon init again.

What I expected to see:
I expected the file to be able to converted. Gryphon succeeds in converting the entire file when it references CGPoint just fine.

Why I think the error is related to a private Cocoapod repo:
After some investigation, it appears this error happens when I try to build the Gryphon project with a variable declaration that is defined in a private pod. When I remove the declaration, the file is able to be converted.

In my private cocoapod Framework_A, I have the following defined:

public class MyPoint{
var x : Double?
var y : Double?

public init(withX xInit:Double, withY yInit:Double){
x = xInit
y = yInit
}

In my Xcode workspace (that has Gryphon initialized in it, and that has Framework_A installed via the PodFile), I call MyPoint and the error occurs.

The --verbose output points to the variable declaration as the error:

let loc = MyPoint(withX: 0.0, withY: 0.0)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Conclusion
Do I need to add my private pod repo as an input source somehow? Any information would be greatly appreciated.

Environment
Gryphon version 0.18.1, using the Swift 5.5 parser
Xcode: 13.2.1
MacOS: Monterey 12.1

@dylandrones dylandrones added the bug Something isn't working label Mar 15, 2022
@vinivendra
Copy link
Owner

Hey @dylandrones, yeah you guessed it. SourceKit needs to know every file necessary to compile your Swift code. If a declaration that you use is in another package (like a pod repo), SourceKit doesn't have enough type information and Gryphon can't go on with the compilation.

There are a few things you can try here:

  1. Create a stub MyPoint declaration to be used only with Gryphon translations, but that's ignored in your actual app. Since SourceKit only needs the code to compile correctly, the new declaration doesn't have to work - it just has to contain the type, methods, etc that you're using. Add the file to Gryphon's xcfilelist but don't add it to Xcode, and everything should be OK.
  2. Include your pod repo's files when calling Gryphon. You technically only need to include files that are enough for everything to compile correctly, but depending on your library, that could include all of its files.

That said, this error message could be a lot better than it is. Can you give me more information about it? Did it show up as an error on the line that references MyPoint?

@vinivendra vinivendra added the question Further information is requested label Apr 9, 2022
@dylandrones
Copy link
Author

Hello,

I would like to perform option 2, but not sure how to add the "pod repo's files when calling Gryphon".

Since there will be more the one file from the framework, can I add a reference to the framework folder?

Is there a tutorial somewhere on how to do that?

  • I tried adding "Input Files" in the Xcode build phrases Call Gryphon under the Gryphon target, with no success. I am unsure of other ways to add Input files to the Gryphon call.

BuildPhases_InputFiles


The error in more detail:

  1. After building the "gryphon target" I see this error:

InLineError

  1. In the Issue Navigator, I can select "show in log"

IssueNavigator

  1. And in the log, I can see this:

GryphonErrorLog

MyPoint is a class defined in a private pod repo called "MyFramework". The app builds in swift successfully.

@dylandrones dylandrones changed the title Unable to convert files that reference classes defined in I a private pod Unable to convert files that reference classes defined in a private pod Apr 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants