• Stars
    star
    123
  • Rank 280,971 (Top 6 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library to read from Swift / clang source code indexes

swift-index-store

swift-index-store is collection of libraries and tools for programmatically reading the source code index produced by swiftc and clang.

Example Usage

The IndexStore library is the primary entrypoint. For example if you want to print all the classes defined in a specific file:

let storePath = // path/to/DerivedData/index/store
let sourceFile = // path/to/interesting/source/file

// Load the index store produced by swiftc
let store = try IndexStore(path: storePath)
for unit in store.units {
    // Find the unit that corresponds to the source file we're interested in
    guard unit.mainFile == sourceFile, let recordName = unit.recordName else {
        continue
    }

    let recordReader = try RecordReader(indexStore: store, recordName: recordName)
    recordReader.forEach { symbolOccurrence in
        // Print class definitions in the source file
        if symbolOccurrence.roles.contains(.definition) && symbolOccurrence.symbol.kind == .class {
            print(symbolOccurrence.symbol.name)
        }
    }
}

For more examples see:

  • unnecessary-testable which discovers uses of @testable that aren't required based on the API being called by the importing file.
  • tycat which print the subtypes or supertypes of a given type.
  • indexutil-annotate which outputs the index information overlaid on the given source file for debugging unexpected index data.

Setup

Swift Package Manager:

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/lyft/swift-index-store", from: "1.0.0"),
    ],
    targets: [
        .executableTarget(name: "<command-line-tool>", dependencies: [
            .product(name: "IndexStore", package: "swift-index-store"),
        ]),
    ]
)

Bazel:

Add the following to your WORKSPACE file:

SWIFT_INDEX_STORE_VERSION = "1.1.0"

http_archive(
    name = "IndexStore",
    sha256 = "b9c7dbcf100783c55d2c24e491feab943a489b485b016016dcd3f3d568836b3b",
    strip_prefix = "swift-index-store-%s" % SWIFT_INDEX_STORE_VERSION,
    url = "https://github.com/lyft/swift-index-store/archive/refs/tags/%s.tar.gz" % SWIFT_INDEX_STORE_VERSION,
)

load(
    "@IndexStore//:repositories.bzl",
    "swift_index_store_dependencies",
)

swift_index_store_dependencies()

then you can consume the target like so:

deps = [
    "@IndexStore",
]

Xcode:

  1. Add the swift-index-store as a Package Dependency to your project (via File ▸ Add Packages…).
  2. Added the “IndexStore” library to your target's Frameworks and Libraries.
  3. Add $(TOOLCHAIN_DIR)/usr/lib to your target's Runpath Search Paths (LD_RUNPATH_SEARCH_PATHS) build setting.
  4. Add $(TOOLCHAIN_DIR)/usr/lib to your target's Library Search Paths (LIBRARY_SEARCH_PATHS) build setting.

How it works

During compilation, both swiftc and clang can generate a detailed source code index by providing the -index-store-path flag. The data model of the index is public, just not well known or well documented.

IndexStore is a Swift wrapper over the first party libIndexStore C library which is part of LLVM. Xcode and Swift for Linux contain libIndexStore, but its header is found separately in apple/llvm-project's indexstore.h.

For more details on the index store's data model, see:

  1. Adding Index-While-Building and Refactoring to Clang: https://www.youtube.com/watch?v=jGJhnIT-D2M
  2. High level design: https://docs.google.com/document/d/1cH2sTpgSnJZCkZtJl1aY-rzy4uGPcrI-6RrUpdATO2Q/

How does this differ from indexstore-db

The goal of this library is to provide a thin Swift layer on top of the C library for one shot tools that manage the structure of the index data themselves. indexstore-db provides more comprehensive support for querying index data as it changes across multiple builds.

More Repositories

1

cartography

Cartography is a Python tool that consolidates infrastructure assets and the relationships between them in an intuitive graph view powered by a Neo4j database.
Python
2,856
star
2

scissors

✂ Android image cropping library
Java
1,841
star
3

confidant

Confidant: your secret keeper. https://lyft.github.io/confidant
Python
1,781
star
4

clutch

Extensible platform for infrastructure management
Go
1,610
star
5

react-javascript-to-typescript-transform

Convert React JavaScript code to TypeScript with proper typing
TypeScript
1,574
star
6

mapper

A JSON deserialization library for Swift
Swift
1,174
star
7

scoop

🍦 micro framework for building view based modular Android applications.
Java
1,036
star
8

Hammer

iOS touch synthesis library
Swift
642
star
9

protoc-gen-star

protoc plugin library for efficient proto-based code generation
Go
563
star
10

xiblint

A tool for linting storyboard and xib files
Python
522
star
11

flinkk8soperator

Kubernetes operator that provides control plane for managing Apache Flink applications
Go
508
star
12

domic

Reactive Virtual DOM for Android.
Kotlin
482
star
13

metadataproxy

A proxy for AWS's metadata service that gives out scoped IAM credentials from STS
Python
450
star
14

cni-ipvlan-vpc-k8s

AWS VPC Kubernetes CNI driver using IPvlan
Go
357
star
15

nuscenes-devkit

Devkit for the public 2019 Lyft Level 5 AV Dataset (fork of https://github.com/nutonomy/nuscenes-devkit)
Jupyter Notebook
352
star
16

presto-gateway

A load balancer / proxy / gateway for prestodb
JavaScript
337
star
17

toasted-marshmallow

S'More speed for Marshmallow
Python
297
star
18

Kronos-Android

An Open Source Kotlin SNTP library
Kotlin
239
star
19

coloralgorithm

Javacript function to produce color sets
JavaScript
225
star
20

awspricing

Python library for AWS pricing.
Python
201
star
21

discovery

This service provides a REST interface for querying for the list of hosts that belong to all microservices.
Python
185
star
22

linty_fresh

✨ Surface lint errors during code review
Python
183
star
23

universal-async-component

React Universal Async Component that works with server side rendering
TypeScript
180
star
24

python-blessclient

Python client for fetching BLESS certificates
Python
112
star
25

goruntime

Go client for Runtime application level feature flags and configuration
Go
84
star
26

omnibot

One slackbot to rule them all
Python
80
star
27

lyft-android-sdk

Public Lyft SDK for Android
Java
72
star
28

high-entropy-string

A library for classifying strings as potential secrets.
Python
60
star
29

gostats

Go client for Stats
Go
56
star
30

pynamodb-attributes

Common attributes for PynamoDB
Python
52
star
31

bandit-high-entropy-string

A high entropy string plugin for OpenStack's bandit project
Python
48
star
32

Lyft-iOS-sdk

Public Lyft SDK for iOS
Swift
43
star
33

python-kmsauth

A python library for reusing KMS for your own authentication and authorization
Python
38
star
34

opsreview

Compile a report of recent PagerDuty alerts for a single escalation policy.
Python
29
star
35

atlantis

Terraform automation for GitHub PRs (private fork of runatlantis/atlantis)
Go
18
star
36

lyft-node-sdk

Node SDK for the Lyft Public API
JavaScript
16
star
37

fake_sqs

An implementation of a local SQS service.
Ruby
15
star
38

lyft.github.io

This is code for oss.lyft.com website.
TypeScript
14
star
39

dockernetes

Run kubernetes inside a docker container.
Dockerfile
12
star
40

python-confidant-client

Client library and CLI for Confidant
Python
11
star
41

kustomizer

A container for running k8s kustomize
Shell
11
star
42

collectd-statsd

collectd plugin to write to statsd
Python
10
star
43

lyft-web-button

Build an actionable, Lyft-branded button for your website
JavaScript
9
star
44

dynamodb-hive-serde

Hive Deserializer for DynamoDB backup data format
Java
8
star
45

syx

Python 2 and 3 compatibility library from Lyft.
Python
7
star
46

lyft-node-samples

Sample applications using Node.js for the Lyft Public API
JavaScript
7
star
47

android-puzzlers

Android puzzles for Lyft Talks and more.
Java
6
star
48

lyft-go-sdk

Go SDK for the Lyft Public API
Go
6
star
49

lyft-django-sample

An API integration example using Django and social-auth.
Python
5
star
50

python-omnibot-receiver

Library for use by services that receive messages from omnibot.
Python
4
star
51

osscla

Open Source Contributor License Agreement service
Python
4
star
52

code-of-conduct

Code of Conduct for Lyft's open source projects
3
star
53

CLA

Contributor License Agreement (CLA) for Lyft's open source projects
3
star
54

awseipext

AWS Lambda that extends the EC2 Elastic IP API
Python
3
star
55

heroku-buildpack-php

Shell
2
star
56

lyft-go-samples

Sample applications in Go for the Lyft Public API
Go
1
star
57

flask-pystatsd

flask extension to simplify the use of the pystatsd library
Python
1
star
58

eventbot

A slackbot to help organize events
Python
1
star