Add astyle pre-commit hook and update readme with coding style info
This commit is contained in:
parent
90eb400763
commit
142c995370
45
README.md
45
README.md
|
@ -26,7 +26,7 @@ telecommunication schemes.
|
|||
* libfec (it will automatically installed if not present)
|
||||
|
||||
#### Debian / Ubuntu
|
||||
```
|
||||
```bash
|
||||
apt install -y build-essential cmake gnuradio g++ \
|
||||
python-mako python-six libogg-dev \
|
||||
libvorbis-dev libpng-dev libpng++-dev \
|
||||
|
@ -43,13 +43,15 @@ sudo make install
|
|||
|
||||
### Installation from source
|
||||
|
||||
1. `git clone https://gitlab.com/librespacefoundation/satnogs/gr-satnogs.git`
|
||||
2. `cd gr-satnogs`
|
||||
3. `mkdir build`
|
||||
4. `cd build`
|
||||
5. `cmake ..`
|
||||
6. `make -j $(nproc --all)`
|
||||
7. `sudo make install`
|
||||
```bash
|
||||
git clone https://gitlab.com/librespacefoundation/satnogs/gr-satnogs.git
|
||||
cd gr-satnogs
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc --all)
|
||||
sudo make install
|
||||
```
|
||||
|
||||
If this is the first time you are building the gr-satnogs module run
|
||||
`sudo ldconfig`
|
||||
|
@ -162,6 +164,33 @@ decoded and its data are available on the `data` field.
|
|||
information regarding it, using the `gr-satnogs` metadata format. More about them
|
||||
in the [Metadata](#metadata) section
|
||||
|
||||
### Coding style
|
||||
For the C++ code, `gr-satnogs` uses a slightly modified version of the
|
||||
**Stroustrup** style, which is a nicer adaptation of the well known K&R style.
|
||||
In addition, we decided to decrease the indentation from 4 to 2 spaces.
|
||||
This choice was made mainly to avoid braking statements with long namespaces.
|
||||
We also found ourselves, that with smaller indentation we use more descriptive
|
||||
variable names, avoiding frustrating abbreviations without phoenixes etc.
|
||||
|
||||
At the root directory of the project there is the `astyle` options
|
||||
file `.astylerc` containing the proper configuration.
|
||||
Developers can import this configuration to their favorite editor.
|
||||
In addition the `hooks/pre-commit` file contains a Git hook,
|
||||
that can be used to perform before every commit, code style formatting
|
||||
with `astyle` and the `.astylerc` parameters.
|
||||
To enable this hook developers should copy the hook at their `.git/hooks`
|
||||
directory.
|
||||
Failing to comply with the coding style described by the `.astylerc`
|
||||
will result to failure of the automated tests running on our CI services.
|
||||
So make sure that you either import on your editor the coding style rules
|
||||
or use the `pre-commit` Git hook.
|
||||
|
||||
|
||||
Regarding the naming of files and variables, we use the underscore naming convention (`do_this`) instead of
|
||||
camel cases (`DoNotDoThis`).
|
||||
Exception to this rule is the CMake module filenames. In addition, all private variables of a C++ class, should start with the prefix `d_` allowing the developers to spot easily private members of the object.
|
||||
|
||||
|
||||
### Metadata
|
||||
Each decoder generates a `pmt::pmt_t` dictionary containing the decoded data and
|
||||
other information regarding the decoded frame.
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# This pre-commit hook beautifies the C++ code using the integrated
|
||||
# astyle configuration.
|
||||
# In order to use this hook, astyle should be installed in the system
|
||||
#
|
||||
# To install this hook, just copy the script to your .git/hooks directory
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
# If you want to allow non-ASCII filenames set this variable to true.
|
||||
allownonascii=$(git config --bool hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
cat <<\EOF
|
||||
Error: Attempt to add a non-ASCII file name.
|
||||
|
||||
This can cause problems if you want to work with people on other platforms.
|
||||
|
||||
To be portable it is advisable to rename the file.
|
||||
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.allownonascii true
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ASTYLE=astyle
|
||||
|
||||
case `$ASTYLE --version 2> /dev/null` in
|
||||
Artistic*)
|
||||
;;
|
||||
default)
|
||||
echo "Did not find astyle, please install it before continuing."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
files=$(git-diff-index --diff-filter=ACMR --name-only -r --cached $against -- | grep -i '\.c$\|\.cc$\|\.cpp$\|\.hpp$\|\.h$')
|
||||
for file in $files; do
|
||||
x=`echo $file`
|
||||
if test "x$x" != "x"; then
|
||||
# Remove trailing spaces
|
||||
sed -i 's/[[:space:]]*$//' $file
|
||||
$ASTYLE --options=.astylerc $file
|
||||
git add $file
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue