realm / jazzy

Soulful docs for Swift & Objective-C
https://realm.io
MIT License
7.35k stars 413 forks source link

[iOS Xcode] Unable to generate documentation for module header files (.h) defined in bridging header for ObjectiveC and swift mixed project. #1349

Closed GeethaTesting closed 1 year ago

GeethaTesting commented 1 year ago

Using below commands to generate the documentation for ObjectiveC and Swift mixed project.

sourcekitten doc -- -workspace Infinite.xcworkspace -scheme Infinite > swiftDoc.json This command is generating swiftDoc.json successfully.

sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c -isysroot $(xcrun --show-sdk-path --sdk iphonesimulator) -I $(pwd) -fmodules > objcDoc.json This command is unable to generate objcDoc.json file. It is giving the below error.

Error - /Users/XXX/Downloads/Modular/Infinite/Infinite/Infinite.h:20:9: fatal error: 'Infinite/PropertyAnimatorViewController.h' file not found /Users/XXX/Downloads/Modular/Infinite/Infinite/Infinite.h:20:9: error: 'Infinite/PropertyAnimatorViewController.h' file not found

import <Infinite/PropertyAnimatorViewController.h>

    ^
:0: error: failed to import bridging header '/Users/XXX/Downloads/Modular/Infinite/Infinite/Infinite.h' Sample Project attached. [Modular.zip](https://github.com/realm/jazzy/files/11359870/Modular.zip) Screenshot 2023-04-30 at 12 06 45 AM Kindly help us in resolving this issue, its little urgent.
johnfairh commented 1 year ago

It looks like you need some more build flags to tell Clang where the headers are -- try reading around these notes.

GeethaTesting commented 1 year ago

@johnfairh - Thanks for your quick response, I followed the link and tried the steps as stated. when i run below clang command, it executed successfully

>>clang -c -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) Infinite/Infinite/Infinite.h -fmodules

After that i ran below Jazzy command, it executed successfully but not generated any documentation.

jazzy --objc --umbrella-header Infinite/Infinite/Infinite.h --framework-root $(pwd)                   
0% documentation coverage with 2 undocumented symbols
included 2 symbols
building site
building search index
jam out ♪♫ to your fresh new docs in `docs`

I also tried SourceKitten command to generate the ObjectiveC json file but no luck.

sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c  -I $(pwd) Infinite/Infinite/Infinite.h -fmodules > objcDoc.json
zsh: trace trap  sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c

Could you please help us in generating the documentation for attached codebase. Modular.zip

johnfairh commented 1 year ago

Here's what happens when I run the clang command you say works for you:

; clang -c -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) Infinite/Infinite/Infinite.h -fmodules
Infinite/Infinite/Infinite.h:19:9: fatal error: 'Infinite/NSString+DateFormatter.h' file not found
#import <Infinite/NSString+DateFormatter.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

...and I can see that the NSString+DateFormatter.h file's path is:

; find . -name NSString+DateFormatter.h 
./Infinite/Infinite/PublicAPI/NSString+DateFormatter.h

So this is exactly the problem that the link I posted above describes -- you need to decide how you want to solve it. Then when you have the clang command working correctly (ie. no error messages) you can pass the same flags to sourcekitten to generate the objcDoc.json.

GeethaTesting commented 1 year ago

Hello @johnfairh, I tried to add symbolic link in the below attached project and executed clang command. Command executed successfully.

clang -c -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) Infinite/Infinite/Infinite.h -fmodules

As suggested above I tried same command with sourcekitten and im getting below error. Attached screenshot for reference.

clang -c -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) Infinite/Infinite/Infinite.h -fmodules
geethadevi@INCHEL-GXTG90HJ-7903 Modular % sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) Infinite/Infinite/Infinite.h -fmodules
zsh: trace trap  sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c
Screenshot 2023-05-07 at 9 27 25 PM

Modular.zip

johnfairh commented 1 year ago

I think just a slight copy+paste mistake, the umbrella header file is appearing twice in the sourcekitten command which clang is not going to like. The command should be something like:

sourcekitten doc --objc $(pwd)/Infinite/Infinite/Infinite.h -- -x objective-c -isysroot $(xcrun --show-sdk-path) -I $(pwd) -fmodules

And check your very first comment - if your project is for iOS then you'll need to put back the --sdk iphonesimulator.

GeethaTesting commented 1 year ago

@johnfairh Thanks a lot for your support. It's working fine and able to generate documentation successfully.