Convert headers to a binder friendly format.
repo: https://github.com/shakfu/header_utils
Default
- Convert include statements with quotes to pointy brackets.
#include "parent/abc.h" -> <parent/abc.h>- Convert relative to absolute include path references.
#include "../abc.h" -> <parent/abc.h>Optional
- Convert
#pragma onceentries to header guards.
#pragma oncebecomes
#ifndef ABC_H
#define ABC_H
...
#endif // ABC_H
- Generate a graphviz (pdf|png|svg) graph of header dependencies.
This requires:
pip install graphvizand graphviz to be installed on your system. On macOS for example:
brew install graphvizA few usage examples (full commandline api is provided below):
Note:
-
As a safety measure:
header_utils.pydoes not do in-place transformations. It will always write its transformations to a copy of theinput_dir. -
If
dry-runmode is active no changes are made, and anoutput_dirneed not be provide. In this mode, graphviz dependency graphs can be generated from theinput_dir. -
If
dry-runmode is not active, then anoutput_dirmust be provided.
./header_utils.py --graph=depends.pdf --dry-run includePrint out default transformations in dry-run mode without making any changes.
Also generate a pdf graph of header-file dependencies using graphviz.
./header_utils.py -o include-dst include-srcApply default transformations to headers copied to include-dst.
./header_utils.py -o include-dst --header-endings .hpp include-srcIn this case, only headers with an .hpp suffix will be modified as opposed to the default: any with ['.h', '.hpp', '.hh'] endings.
./header_utils.py -o include-dst --header-guards include-srcApply default transformations to headers and also convert #pragma once entries to header guards.
usage: header_utils.py [-h] [--output_dir OUTPUT_DIR]
[--header-endings HEADER_ENDINGS [HEADER_ENDINGS ...]]
[--header-guards] [--dry-run] [--force-overwrite]
[--list] [--graph GRAPH]
input_dir
Convert headers to a binder friendly format. (default: ['.h', '.hpp', '.hh'])
positional arguments:
input_dir input include directory containing source headers
optional arguments:
-h, --help show this help message and exit
--output_dir OUTPUT_DIR, -o OUTPUT_DIR
output directory for modified headers (default: None)
--header-endings HEADER_ENDINGS [HEADER_ENDINGS ...], -e HEADER_ENDINGS [HEADER_ENDINGS ...]
--header-guards convert `#pragma once` to header guards (default: False)
--dry-run, -d run in dry-run mode without actual changes (default: False)
--force-overwrite, -f
force overwrite output_dir if it already exists (default: False)
--list, -l list target headers only (default: False)
--graph GRAPH, -g GRAPH
output path for graphviz graph with format suffix
[png|pdf|svg] (default: None)
To test header_utils.py, ensure you have pytest installed.
Note: this project uses a snapshot of the actual headers from the taskflow project to test its functionality.
pytest- add more tests