Identifying compiler arguments for SourceKit's 'indexsource' request type

Originator:port001
Number:rdar://41200666 Date Originated:
Status: Resolved:
Product: Product Version:
Classification: Reproducible:
 
SourceKit's 'indexsource' request type requires swiftc compiler arguments in order to compile the given source file on demand (I assume). However, the exact arguments required are numerous, not documented and highly specific to the requested source file.

Advanced users of 'indexsource' do not typically attempt to construct this set of arguments manually, and instead 'spy' on Xcode in order to determine the necessary arguments. Both SourceKitten[1] and Periphery[2] rely upon parsing the output from xcodebuild to identify the appropriate swiftc call, parse the argument set, and then remove specific arguments that 'indexsource' does not appear to accept[3].

This approach is problematic for a number of reasons:
* Building a project simply to obtain the swiftc arguments is extremely inefficient. With regard to Periphery, the xcodebuild step accounts for over 95% of total runtime.
* xcodebuild must also perform a 'clean' build, since the output log will not include swiftc calls for targets which do not need to be rebuilt.
* The format of the arguments as they're used in a swiftc call can be tricky to parse.
* Using xcodebuild is a "hack", the log output may change without notice in future Xcode releases.
* Obtaining swiftc arguments for XCTest target requires extra logic, in that xcodebuild's 'build-for-testing' action must be used instead of 'build'.

In order to provide a faster and more stable experience to our users, we would like the ability to request build plans without the need to perform an actual build. An ideal solution might look something like this:

* For a given workspace/project, scheme and target, output an easily parsable build plan.
* XCTest targets should be supported just as normal build targets.
* Optionally, an additional flag would restrict the argument set to those that are compatible with 'indexsource' so that they may be used verbatim.

This generic approach would also aid other use-cases which do not intended to use the arguments with SourceKit.

1. https://github.com/jpsim/SourceKitten
2. https://peripheryapp.com
3. This is not necessarily an exhaustive list, they're just the ones identified during the development of Periphery:
  * "-Xfrontend"
  * "-output-file-map"
  * "-parseable-output"
  * "-serialize-diagnostics"
  * "-incremental"
  * "-emit-dependencies"

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!