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

Cannot find ObjC headers from subfolders #518

Closed
benrudhart opened this issue Apr 7, 2016 · 18 comments
Closed

Cannot find ObjC headers from subfolders #518

benrudhart opened this issue Apr 7, 2016 · 18 comments
Assignees

Comments

@benrudhart
Copy link

I'm having issues with jazzy finding source files.

  • In my objC project I'm using subfolders to organize files.
  • I have an umbrella header containing imports:
    • when importing a file via #import "<Filename>.h"
      • compiler builds
      • jazzy cannot find the filename (fatal error: '<Filename>.h' file not found)
    • when importing a file via #import <Subfolder/Filename.h>
      • compiler doesn't build
      • jazzy finds the file but cannot find the imports included in that header file (maybe bc. they also are in another subfolder of the project)

Any ideas how to fix that issue? I'd also be interested in an example - would greatly appreciate if anybody could provide a link to a repo using objC that organizes files in subfolders and got jazzy working.

@jpsim jpsim added the question label Apr 7, 2016
@jpsim
Copy link
Collaborator

jpsim commented Apr 7, 2016

Realm's public headers are all in one folder, so I can't point you to that. It's possible PSPDFKit has public headers in subfolders, so maybe @esad can help you if that's the case?

In general, it'd be easier for me to help you if you could share a sample project that exhibited the same issue.

@benrudhart
Copy link
Author

@jpsim I created an example project that already includes a .jazzy.yaml
https://github.com/benrudhart/JazzyObjCSubfolders
Would be great if you could have a look.

@benrudhart
Copy link
Author

@esad or @jpsim did you get a chance to have a look at the example? would appreciate any kind of help!

@jpsim
Copy link
Collaborator

jpsim commented Apr 14, 2016

I haven't had the chance to look at it yet. Hopefully soon!

@jpmhouston
Copy link

jpmhouston commented Apr 18, 2016

This error occurs within a call into clang from SourceKitten. For this project JazzyObjCSubfolders the parameters to sourcekitten are:

"doc", "--objc", "/Users/blah/JazzyObjCSubfolders/ObjectiveCJazzy/BRTObjectiveCJazzy.h",
"--", "-x", "objective-c", "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk",
"-I", "/Users/blah/JazzyObjCSubfolders/BRTObjectiveCJazzy"

Debugging sourcekitten with those args, you can see it calling clang_createTranslationUnitFromSourceFile with those argument strings "-x", "objective-c", ... and that outputting the "file not found" message.

I would have thought that adding more -I arguments for each subdirectory of BRTObjectiveCJazzy were what's needed, like:

 "-I", "/Users/blah/JazzyObjCSubfolders/BRTObjectiveCJazzy",
 "-I", "/Users/blah/JazzyObjCSubfolders/BRTObjectiveCJazzy/Subfolder1"
 "-I", "/Users/blah/JazzyObjCSubfolders/BRTObjectiveCJazzy/Subfolder2"

but I tried adding those arguments to sourcekitten and it still didn't work. I'm guessing the solution is something along those lines though, getting jazzy to specify all the recursive paths to sourcekitten explicitly.

@benrudhart
Copy link
Author

@jpmhouston thank you for having a look. Hope I'll find some time to dive deeper into this issue.
In the meantime I appreciate any help/ ideas by others 😀

@colincornaby
Copy link

I'm having the same issue. I have multiple folders for my headers, and Jazzy can't find them. I'll poke around a bit and see if I can find a solution, but I'm not seeing anything promising in the command line options.

@jpmhouston
Copy link

jpmhouston commented Apr 20, 2016

Note, to anyone else investigating this, I had troubles finding a good way to debug ruby in order to break in its execution at the right place, so I just modified jazzy's gem to print the arguments to SourceKitten.

In the file /usr/local/lib/ruby/gems/2.3.0/gems/jazzy-0.6.0/lib/jazzy/sourcekitten.rb within the run_sourcekitten(arguments) function I added a line:

puts "sourcekitten args: #{arguments}"

Launching sourcekitten with those same arguments causes the "file not found" message. Maybe someone can find the right additional arguments to get sourcekitten to work, and then jazzy needs to be made to construct those same arguments.

@nsomar
Copy link

nsomar commented Apr 22, 2016

Running into this same issue, my project has many sub folders too.

@jpmhouston
Copy link

jpmhouston commented Apr 29, 2016

It looks like the JazzyObjCSubfolders project's .jazzy.yaml file should have had ObjectiveCJazzy for framework_root instead of BRTObjectiveCJazzy (in addition to the other compatibility fixes i had to make: objc_mode: to objc: and version: to module_version:).

With this correct directory name, my experiment calling sourcekitten with it and the added subdirectories arguments succeeded.

A change to jazzy's sourcekitten.rb to add those additional -I arguments for each subdirectory of framework_root seems to work for both JazzyObjCSubfolders and my own project:

--- a/lib/jazzy/sourcekitten.rb
+++ b/lib/jazzy/sourcekitten.rb
@@ -122,8 +122,14 @@ module Jazzy
           arguments += ['--objc', options.umbrella_header.to_s, '--', '-x',
                         'objective-c', '-isysroot',
                         `xcrun --show-sdk-path --sdk #{options.sdk}`.chomp,
                         '-I', options.framework_root.to_s]
+          # add additional -I arguments for each subdirectory of framework_root
+          Pathname.new(options.framework_root.to_s).children.collect do |child|
+            if child.directory?
+              arguments += ['-I', child.to_s]
+            end
+          end
         end
       elsif !options.module_name.empty?
         arguments += ['--module-name', options.module_name, '--']
       else

I don't know if this should always be done or controlled by a command line/config file option though. Also, there could be a better way to find subdirectories instead of visiting every file. I'll leave it to someone else to figure those out & make this fix for real.

@colincornaby
Copy link

colincornaby commented Jun 17, 2016

I'm still having issues. My code layout looks like (and I can put aside time to make a sample project).

Project
   Project.xcodeproj
   Project
       ProjectUmbrella.h (imports ModuleA.h and ModuleB.h)
   Module
       ModuleA.h
   Module
       ModuleB.h

In the final framework output these headers are all public, and they're all in the public headers, so the actual imports in the umbrella look like #import <Project/ModuleA.h>

That's where Jazzy has issues for me wherever I set the root (I've tried both the "Project" folders.) It immediately stops with:
fatal error: 'Project/ModuleA.h' file not found

@colincornaby
Copy link

I've added a Github project for my issue:
https://github.com/colincornaby/JazzyMultiFolderFrameworkIssue

Should get something like this for output:

Using config file /Users/ccornaby/Desktop/JazzyTest/.jazzy.yaml
/Users/ccornaby/Desktop/JazzyTest/JazzyTest/JazzyTest.h:19:9: fatal error: 'JazzyTest/ModuleA.h' file not found
building site
jam out ♪♫ to your fresh new docs in `docs`

@gretzki
Copy link
Contributor

gretzki commented Jun 28, 2016

I ran into the same issue and have fixed this issue (according to @jpmhouston's idea) in the following PR #603
Works for me now, so check it out.

Cheers,
Chris

@benrudhart
Copy link
Author

@gretzki sound's great - have to check that later. I think you're speaking of PR #603

@gretzki
Copy link
Contributor

gretzki commented Jun 28, 2016

Yeah, you're right. Fixed my comment.

@mhuusko5
Copy link

mhuusko5 commented Sep 1, 2016

This just started happening for me for some reason. On 0.7.0.

@andyb1979
Copy link

andyb1979 commented Sep 24, 2016

Still getting this issue in Jazzy v0.7.2

Project structure is

  • MyProjectFramework
    • MyProject.xcodeproj
    • MyProject
    •   Umbrellaheader.h
      
    •   ASubDir  
      
      •      AHeader.h
        
    •   AnotherSubDir
      
      •      AnotherHeader.h
        

I run the following command line from folder MyProjectFramework:

jazzy -m 'MyProject' -a 'MyProject' --objc --umbrella-header 'MyProject/UmbrellaHeader.h' --module-version 1.2.0 -c --sdk iphonesimulator --clean --framework-root .

This results in the error

..MyProjectFramework/Myproject/UmbrellaHeader.h:18:9: fatal error: 'MyProject/AHeader.h' file not found

ainopara pushed a commit to ainopara/jazzy that referenced this issue Nov 3, 2016
Adding all subdirectories of specified "framework_root" option as argument to sourcekitten. This enables references inside the umbrella header to other source files that are within subdirectories of the "framework_root".
For details see realm#518
@pigeon-archive pigeon-archive self-assigned this Nov 23, 2016
@pigeon-archive
Copy link
Contributor

pigeon-archive commented Nov 23, 2016

Any updates on this issue? #603 needs to be reviewed.

jpsim pushed a commit that referenced this issue Mar 9, 2017
Adding all subdirectories of specified "framework_root" option as argument to sourcekitten. This enables references inside the umbrella header to other source files that are within subdirectories of the "framework_root".
For details see #518
@jpsim jpsim closed this as completed Mar 9, 2017
zsstrehli pushed a commit to zsstrehli/jazzy that referenced this issue Jun 2, 2017
Adding all subdirectories of specified "framework_root" option as argument to sourcekitten. This enables references inside the umbrella header to other source files that are within subdirectories of the "framework_root".
For details see realm#518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants