A tool to inspect .swiftsourceinfo file and remap the absolute paths in it.
The .swiftsourceinfo file is generated by the Swift compiler during compilation, along with .swiftmodule and .swiftdoc. It is used for diagnosis and indexing. We have identified a case where jump-to-definition requires the .swiftsourceinfo file, and IndexStore alone does not suffice.
However, the .swiftsourceinfo file always embeds absolute paths, which can hinder local development experience if the file is downloaded from a remote cache. In such cases, it is necessary to remap the server paths to the local paths.
- The tool can be used to remap absolute source paths. Inspired by
index-import, it accepts an--remapoption in the format ofregex=replacement. Multiple--remapoptions can be accumulated.
$ ./source-info-import --remap="/Users/.*/MyProject=/new/path/MyProject" FooLibrary.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo new.swiftsourceinfo
/Users/xyz/MyProject/FooLibrary/Foo.swift -> /new/path/MyProject/FooLibrary/Foo.swift
/Users/xyz/MyProject/FooLibrary/Bar.swift -> /new/path/MyProject/FooLibrary/Bar.swift
- This tool can also be used to inspect the content of a
.swiftsourceinfofile. Simply provide the file path without the--remapoption.
$ ./source-info-import FooLibrary.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo
Source Files:
/Users/xyz/MyProject/FooLibrary/Foo.swift (2024-03-14 23:54:31.384273393, 417 bytes)
/Users/xyz/MyProject/FooLibrary/Bar.swift (2024-03-18 10:00:23.816131108, 122 bytes)
USRs:
s:10FooLibrary0A8ProtocolPA2A0A6StructVRszrlE3fooSSvpZ (Foo.swift:10:21)
s:10FooLibrary0A6StructV (Foo.swift:7:15)
s:10FooLibrary3BarC (Bar.swift:6:7)
s:e:s:10FooLibrary0A8ProtocolPA2A0A6StructVRszrlE3fooSSvpZ (Foo.swift:9:1)
source-info-import depends on the libraries from Apple's LLVM fork.
-
Follow the steps in Swift instructions to setup the environment and dependencies.
-
Build the LLVM libraries
# in `swift` directory
utils/build-script --release --skip-build
ninja -C ../build/Ninja-ReleaseAssert/llvm-macosx-arm64 llvm-libraries llvm-config- Change the
LLVM_BUILD_DIRinbuild.shto the correct path, which should be like/path/to/swift-project/build/Ninja-ReleaseAssert/llvm-macosx-arm64" - Run
./build.sh
The .swiftsourceinfo file, like .swiftmodule and .swiftdoc, is also in LLVM Bitstream format. This article provides a detailed description of the format.