|
IPPL (Independent Parallel Particle Layer)
IPPL
|
This guide explains how to set up automatic code formatting for IPPL development using the pre-commit git hook.
IPPL uses two automatic formatters:
.c, .cc, .cpp, .cxx, .h, .hpp, etc.)CMakeLists.txt, *.cmake)The pre-commit hook runs these formatters automatically before each commit, ensuring all committed code adheres to the project's styling conventions.
Add the LLVM repository and install clang-format-21:
Verify the installation:
Note: If you have clang-format installed but it doesn't use the full name clang-format-21, then just create a symlink in your .local path that redirects clang-format-21 to your real clang-format executable
For other operating systems, visit the LLVM download page or use your system's package manager to locate clang-format version 21 or later.
cmake-format is a Python package available via pip:
Verify the installation:
If you prefer to install it system-wide or in a virtual environment, refer to the cmake-format documentation.
The repository includes the git hook script. From the repository root, setup a symlink to the git hook (in the .git/hooks dir):
(note that the extra ../../ in the path is because git runs the hook from the .git/hooks directory, so the symlink has to be redirected)
Alternatively, create a symbolic link manually directly from the git hooks dir:
To verify the hook is installed, check that the symlink exists:
You should see output similar to:
When you run git commit:
git commitNote that we include the command-line parameter -style=file in all clang-format commands mentioned here, but this is actually the default and skipping it should not cause problems. Providing there is a .clang-format file present in the repository root, all should work as expected.
If you need to commit without running the hook (not recommended), use:
Warning: Code committed without formatting may not adhere to project standards.
To format files without committing:
chmod +x .git/hooks/pre-commitls -la .git/hooks/pre-commitclang-format-21 and cmake-format are in your $PATH: which clang-format-21 cmake-formatThis is typically due to:
clang-format-21 versions installed (ensure you have version 21).clang-format configuration files in subdirectories that override the root configIf you're on a shared HPC system where multiple compiler modules are available:
module load llvm/21 or similarclang-format in ~/.local/bin if module loading is inconvenientThe formatting behavior is controlled by:
.clang-format (repository root and subdirectories).cmake-format.py (repository root)These files define all style rules. For detailed customization, refer to:
Refer to the main WORKFLOW.md guide for additional context on IPPL's development practices.