SourcetrailDB
Описание
Library to export Sourcetrail compatible database files for writing custom indexers
Языки
- C++91,8%
- CMake7,9%
- SWIG0,3%
SourcetrailDB
Library to export Sourcetrail compatible database files for writing custom indexers
CI Pipelines
Introduction
The SourcetrailDB project provides write access to Sourcetrail database files. You can use the SourcetrailDB project to write an indexer for an arbitrary programming language (or other kind of data, e.g. see poetry indexer example) and export a Sourcetrail database file that can be viewed and navigated within Sourcetrail.

Projects Using SourcetrailDB
The following list of projects already use SourcetrailDB API to extend the language support of Sourcetrail.
- SourcetrailPythonIndexer is a Sourcetrail language extension that brings Python support to Sourcetrail. This project is in a stable state and it has a direct Sourcetrail integration via the Python Source Group.
- SourcetrailDotnetIndexer is a Sourcetrail language extension that allows to index all kinds of .NET assemblies, regardless of the language they are created from (e.g. C#, VB.NET, ...). Because it does not (need to) know the source code, it does not provide any code snippets for the indexed assemblies, but it already works well at generating graphs.
- SourcetrailPerlIndexer is a Sourcetrail language extension that brings Perl support to Sourcetrail. This project is still in a prototype state, but you can already run it on your Perl code via the Custom Source Group.
- stacktraceflow_sourcetrail combines the power of Valgrind and Sourcetrail to quickly produce interactive callgraph of software written in any language, as long as it's compiled to ELF/DWARF format (e.g. Rust and Go).
- SourcetrailTypescriptIndexer is a Typescript Indexer for Sourcetrail using the TypeScript compiler and node bindings contributed to SourcetrailDB (prototype stage).
- SourcetrailGolangIndexer is a Golang Indexer for Sourcetrail (prototype stage).
Adding new Language Support
When you plan on starting a Sourcetrail language package on your own, you can use whatever programming language you like for this task. The only requirement is: you need to make calls to SourectrailDB to enter the information your indexer records to the Sourcetrail database.
To get an overview on everything involved, please take a look at our Language Extension Guide.
Supported Language Bindings
Even though the core implementation is written in C++, this does not require you to write your indexer in C++ as well. Instead you can use a language binding (e.g. see SWIG). These language bindings are already available:
If the language of your choice is not covered by this list, feel free to open an issue or provide a pull request.
Versioning
The SourcetrailDB version format consists of three numbers in the format .
: interface version. This version increases on every change that breaks backwards compatibility.XX: Sourcetrail database version. This version needs to match the database version of the used Sourcetrail instance. You can find the database version of Sourcetrail in its About dialog.YY: patch number of the build. It will increase with every release that publishes bugfixes and features that don't break any compatibility.ZZ
You can find a complete list of available releases on the GitHub release page. If you are interested in the actual changes of every release, please take a look at the Changelog.
Contributing
If you like this project and want to get involved, there are lots of ways you can help:
- Spread the word. The more people want this project to grow, the greater the motivation for the developers to get things done.
- Write some code. Don't be shy here. You can implement whole new language bindings, add a features or fix some bugs, but you can also do some refactoring if you think that it benefits the readability or the maintainability of the code. Still, no matter if you just want to work on cosmetics or implement new features, it would be best if you create an issue here on the issue tracker before you actually start handing in pull requests, so that we can discuss those changes first and thus raise the probability that those changes will get pulled quickly.
To create a pull request, follow these steps:
- Fork the Repo on GitHub.
- Make your commits.
- If you added functionality or fixed a bug, please add a test.
- Add your name to the "Code Contributors" section in AUTHORS.txt file.
- Push to your fork and submit a pull request.
Building
Take a look at Appveyor (for Windows) or Travis (for Linux and macOs) CI scripts for reference.
SourcetrailDB Core
Before building the core project, please make sure that you also have checked out the tags of this repository (they are relevant for deriving version number information during the build).
Requirements:
- CMake >= 2.6
- C++-Compiler with C++11 support
To build the SourcetrailDB core library :
$ cd path/to/SourcetrailDB
$ mkdir build
$ cd build
$ cmake ..
$ make lib_core
To run the tests, just build and execute the test executable:
$ make test_core
$ ./core/test_core
Perl Bindings
Requirements:
-
Perl needs to be included and linked against when building the Perl bindings. CMake will auto-detect your Perl installation. If you want to build against a specific version of Perl, please define the
variable accordingly when running CMake. Make sure to link to the correct Perl version when building for different architectures (32bit/64bit).PERL_LIBRARY -
SWIG 3.0.12 is used to automatically generate Perl binding code. Make sure that SWIG is added to your path environment variable.
If you want to build the Perl bindings run:
$ cd path/to/SourcetrailDB
$ mkdir build
$ cd build
$ cmake -DBUILD_BINDINGS_PERL=ON ..
$ make sourcetraildb
Swig is configured to generate the Perl binding code as a pre-build event, so you don't need to bother with updating manually.
Python Bindings
Requirements:
-
Python needs to be included and linked against when building the Python bindings. CMake will auto-detect your Python installation. If you want to build against a specific version of Python, please define the
variable accordingly when running CMake. Make sure to link to the correct Python version when building for different architectures (32bit/64bit).PYTHON_LIBRARY -
SWIG 3.0.12 is used to automatically generate Python binding code. Make sure that SWIG is added to your path environment variable.
If you want to build the Python bindings run:
$ cd path/to/SourcetrailDB
$ mkdir build
$ cd build
$ cmake -DBUILD_BINDINGS_PYTHON=ON ..
$ make _sourcetraildb
Swig is configured to generate the Python binding code as a pre-build event, so you don't need to bother with updating manually.
Java Bindings
Requirements:
-
Java JDK needs to be included and linked against when building the Java bindings. CMake will auto-detect your Java installation.
-
SWIG 3.0.12 is used to automatically generate Java binding code. Make sure that SWIG is added to your path environment variable.
If you want to build the Java bindings run:
$ cd path/to/SourcetrailDB
$ mkdir build
$ cd build
$ cmake -DBUILD_BINDINGS_JAVA=ON ..
$ make
Swig is configured to generate the Java binding code as a pre-build event, so you don't need to bother with updating manually.
C# Bindings
Requirements:
- SWIG 3.0.12 is used to automatically generate C# binding code. Make sure that SWIG is added to your path environment variable.
If you want to build the C# bindings run:
$ cd path/to/SourcetrailDB
$ mkdir build
$ cd build
$ cmake -DBUILD_BINDINGS_CSHARP=ON ..
$ make
Examples
The examples help you to understand SourcetrailDB usage in practice. Please take a look at each examples README file for build and use instructions. Each example also provides a Sourcetrail project file showing you how to use a custom indexer directly from Sourcetrail (see Integrating with Sourcetrail).
SourcetrailDB API
SourcetrailDB tries to keep the API for writing to the Sourcetrail database as simple as possible. For the C++ core take a look at the list of methods of the SourcetrailDBWriter class for a complete overview of the provided write API. If you are using bindings for other languages, the code may look different but the set of provided functionality should stay the same.
Opening or Creating a Database
Recording a Symbol

Recording Additional Symbol Information

Recording Nested Symbol Names

Recording Symbol Location

Recording References Between Symbols

Recording File Information for Syntax Highlighting

Recording Local Symbols

Recording Comments

Recording Errors

Use Transactions for Speed
Integrating with Sourcetrail
Applications using SourcetrailDB can be directly integrated with Sourcetrail by creating a project with a Custom Command Source Group. Choose in the project selection dialog:
Project Setup
A Custom Command Source Group defines:
- Custom Command: This command will be executed for each source file in the source group. You can pass these variables in the command:
- %{SOURCE_FILE_PATH}: The path to each source file in the source group
- %{DATABASE_FILE_PATH}: The path to the database of the project
- %{DATABASE_VERSION}: The database version of the used Sourcetrail instance
- %{PROJECT_FILE_PATH}: The path to the project file
- Files & Directories to Index: Paths to search for source files.
- Excluded Files & Directories: Files and directories within the above, that should not be indexed.
- Source File Extensions: The extension of the source files. Extension is ignored if left empty.

Indexing
Indexing the project works as usual, the specified Custom Command is executed with each source file passed in %{SOURCE_FILE_PATH}. The files in the Custom Command Source Group will be indexed after all other files.
