SourceKitten icon indicating copy to clipboard operation
SourceKitten copied to clipboard

Illegal instruction: 4 when referencing a header file by absolute path

Open esad opened this issue 8 years ago • 1 comments

I'm using SourceKitten 0.12.1 from jazzy master with Xcode 7.3.1.

Given the following file /tmp/foo.h:

#import <UIKit/UIKit.h>

@interface UISearchController (Baz)
@property NSString *foo;
@end

When I call sourcekitten with:

sourcekitten doc --objc /tmp/foo.h -- -x objective-c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk --verbose

it crashes with

Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/7.3.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/System/Library/Frameworks (framework directory)
End of search list.
sourcekit: [1:connection-event-handler:9731: 0.0000] Connection interrupt
sourcekit: [1:pingService:9731: 0.0009] pinging service
Illegal instruction: 4

cd-ing to /tmp and calling it with foo.h as argument doesn't crash (?).

esad avatar May 09 '16 15:05 esad

Digging further I think I found the cause of the problem. In

https://github.com/jpsim/SourceKitten/blob/42b70b0e281ac9d72e436b8b1a4ce9f268102f0d/Source/SourceKittenFramework/Xcode.swift#L169

sdk path is retrieved by calling xcrun --show-sdk-path ignoring xcodebuild option sdk passed to sourcekitten. On my Mac, this results in MacOSX sdk being used, probably causing SourceKit to crash.

Simple fix is to supply SDKROOT=iphonesimulator when invoking jazzy, which influences the sdk path returned by xcrun.

esad avatar May 27 '16 13:05 esad