Skip to content

Development Setup

Claudio Lucisano edited this page Sep 22, 2026 · 1 revision

Development Setup

Everything you need to change OpenABE and get a green pull request. Read CONTRIBUTING.md first for the PR rules.

1. Build toolchain

Follow Getting Started for your platform. As a contributor you also need bison and flex (already in the package lists there). The parser is regenerated from src/zparser.yy and src/zscanner.ll whenever you change them.

2. Code style: clang-format 18.1.8

The style is defined in .clang-format and enforced by CI. It is LLVM with these changes:

Option LLVM OpenABE
ColumnLimit 80 100
PointerAlignment Right (int *p) Left (int* p)
AllowShortFunctionsOnASingleLine All Empty
SortIncludes CaseSensitive Never: see below

Indentation is 2 spaces, with no tabs.

Use exactly version 18.1.8. Other releases format some constructs differently, and CI would reject your code even though it looks formatted to you:

pipx install clang-format==18.1.8     # or: pip install --user clang-format==18.1.8
clang-format --version                 # must print 18.1.8

Format before committing:

clang-format -i --style=file path/to/changed_file.cpp
# or every C/C++ file you touched compared to master:
git diff --name-only master -- '*.c' '*.cc' '*.cpp' '*.h' '*.hh' | xargs clang-format -i --style=file

Why include sorting is off

Many headers are not self-contained: they compile only because openabe.h includes their dependencies first, in a specific order. Sorting includes alphabetically breaks the build. Until every header includes what it uses, keep the existing include order and add new includes where they are needed, not where they would sort. See Known Limitations.

Generated files are never formatted

src/zparser.tab.cc, src/zparser.tab.hh, src/location.hh, src/position.hh, src/stack.hh and src/zscanner.cpp are bison/flex output and are listed in .clang-format-ignore. Edit zparser.yy / zscanner.ll instead and rebuild.

3. VS Code

With the C/C++ extension (ms-vscode.cpptools), create .vscode/settings.json. It is git-ignored, so it stays on your machine:

{
  // Point this to the clang-format 18.1.8 you installed
  "C_Cpp.clang_format_path": "/path/to/clang-format",
  "C_Cpp.clang_format_style": "file",
  "C_Cpp.clang_format_fallbackStyle": "none",
  "C_Cpp.formatting": "clangFormat",

  "[c]":   { "editor.defaultFormatter": "ms-vscode.cpptools", "editor.formatOnSave": true, "editor.formatOnSaveMode": "modifications" },
  "[cpp]": { "editor.defaultFormatter": "ms-vscode.cpptools", "editor.formatOnSave": true, "editor.formatOnSaveMode": "modifications" },

  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.detectIndentation": false,
  "editor.rulers": [100],
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true
}

Where the binary lives:

Installed with Path
pipx (Linux/macOS) ~/.local/bin/clang-format
pip --user (Windows) %APPDATA%\Python\PythonXY\Scripts\clang-format.exe

Two notes on these settings:

  • Why not the bundled clang-format? The extension ships its own clang-format, whose version changes with extension updates. Pinning the path keeps your editor and CI in agreement.
  • Why formatOnSaveMode: modifications? When VS Code formats a file it passes the code through stdin, and clang-format then ignores .clang-format-ignore. Formatting only the lines you changed keeps the generated files intact if you ever save one of them.

4. Useful git settings

The bulk reformatting commit is listed in .git-blame-ignore-revs. GitHub already skips it in blame; to do the same locally:

git config blame.ignoreRevsFile .git-blame-ignore-revs

5. Before opening a PR

. ./env
make && make test && make -C examples test
clang-format --dry-run --Werror --style=file <changed files>
git diff --check

Then fill in the PR template. Testing and CI lists everything CI will run.

Clone this wiki locally