Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bash cript to sort includes and remove duplicates
* this sorts and remove duplicates in #include in src and tests folders * sorts includes in <...> before "..." * keep #include "ui_..." on top of list * can skip includes if an order should be kept * can exlcude directories (hard-copies of external libraries)
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
########################################################################### | ||
# sort_include.sh | ||
# --------------------- | ||
# Date : June 2015 | ||
# Copyright : (C) 2015 by Denis Rouzaud | ||
# Email : denis.rouzaud@gmail.com | ||
########################################################################### | ||
# # | ||
# This program is free software; you can redistribute it and/or modify # | ||
# it under the terms of the GNU General Public License as published by # | ||
# the Free Software Foundation; either version 2 of the License, or # | ||
# (at your option) any later version. # | ||
# # | ||
########################################################################### | ||
|
||
|
||
# this sorts and remove duplicates in #include in src and tests folders | ||
# sorts includes in <...> before "..." | ||
# keep #include "ui_..." on top of list | ||
# can skip includes if an order should be kept | ||
# can exlcude directories (hard-copies of external libraries) | ||
|
||
SORTING=false | ||
FILE1=.sort_include_1.tmp | ||
FILE2=.sort_include_2.tmp | ||
FILE3=.sort_include_3.tmp | ||
|
||
# files not to be sorted (leads to compile errors otherwise) | ||
DoNotSort="(sqlite3.h)|(spatialite.h)" | ||
|
||
for file in $(find . \ | ||
! -path "src/app/gps/qwtpolar-*" \ | ||
! -path "src/core/gps/qextserialport/*" \ | ||
! -path "src/plugins/grass/qtermwidget/*" \ | ||
! -path "src/astyle/*" \ | ||
! -path "python/ext-libs/*" \ | ||
! -path "src/providers/spatialite/qspatialite/*" \ | ||
! -path "src/plugins/dxf2shp_converter/dxflib/src/*" \ | ||
! -path "src/plugins/globe/osgEarthQt/*" \ | ||
! -path "src/plugins/globe/osgEarthUtil/*" \ | ||
-type f -regex "(src)|(tests)/(.+/)*.*\.\(h\|cpp\)") | ||
do | ||
echo "$file" | ||
touch $FILE1 | ||
while IFS= read -r line | ||
do | ||
if [[ "$line" =~ ^[[:space:]]*"#"include ]] && [[ ! "$line" =~ $DoNotSort ]]; then | ||
if ! $SORTING; then | ||
touch $FILE2 | ||
touch $FILE3 | ||
fi | ||
SORTING=true | ||
if [[ "$line" =~ ^"#"include[[:space:]]*\"ui_ ]]; then | ||
echo "$line" >> $FILE1 # keep ui_ on top of list | ||
elif [[ "$line" =~ ^"#"include[[:space:]]*\<[^[:space:]]+\> ]]; then | ||
echo "$line" >> $FILE2 | ||
else | ||
echo "$line" >> $FILE3 | ||
fi | ||
else | ||
if $SORTING; then | ||
sort -u $FILE2 >> $FILE1 | ||
sort -u $FILE3 >> $FILE1 | ||
rm -f $FILE2 $FILE3 | ||
SORTING=false | ||
fi | ||
echo "$line" >> $FILE1 | ||
fi | ||
done < "$file" | ||
rm -f $FILE2 $FILE3 | ||
mv $FILE1 $file | ||
rm -f $FILE1 | ||
done | ||
|
684b2bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@3nids this is cool! Have you thought about adding it to the prepare commit script?
684b2bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still testing...
I'll see if I can integrate it later on!
684b2bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in facfe6e. I'll do a test build on Windows after
astyle-all.sh
finishes...Thoughts on also integrating autopep8 for python (instead of just warning with pep8)?