Skip to content

A tool to inspect .swiftsourceinfo file and remap the absolute paths in it.

Notifications You must be signed in to change notification settings

qyang-nj/source-info-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

source-info-import

A tool to inspect .swiftsourceinfo file and remap the absolute paths in it.

Overview

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.

Usage

  • The tool can be used to remap absolute source paths. Inspired by index-import, it accepts an --remap option in the format of regex=replacement. Multiple --remap options 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 .swiftsourceinfo file. Simply provide the file path without the --remap option.
$ ./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)

Build Instructions

source-info-import depends on the libraries from Apple's LLVM fork.

  1. Follow the steps in Swift instructions to setup the environment and dependencies.

  2. 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
  1. Change the LLVM_BUILD_DIR in build.sh to the correct path, which should be like /path/to/swift-project/build/Ninja-ReleaseAssert/llvm-macosx-arm64"
  2. Run ./build.sh

File Format

The .swiftsourceinfo file, like .swiftmodule and .swiftdoc, is also in LLVM Bitstream format. This article provides a detailed description of the format.

About

A tool to inspect .swiftsourceinfo file and remap the absolute paths in it.

Resources

Stars

Watchers

Forks

Packages

No packages published