Skip to content

Commit

Permalink
integrate sorting of includes into astyle.sh/astyle-all.sh/prepare-co…
Browse files Browse the repository at this point in the history
…mmit.sh
  • Loading branch information
jef-n committed Jun 10, 2015
1 parent a6eb0f5 commit facfe6e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 23 deletions.
46 changes: 24 additions & 22 deletions scripts/astyle.sh
Expand Up @@ -43,27 +43,29 @@ fi

set -e

export ARTISTIC_STYLE_OPTIONS="\
--preserve-date \
--indent-preprocessor \
--brackets=break \
--convert-tabs \
--indent=spaces=2 \
--indent-classes \
--indent-labels \
--indent-namespaces \
--indent-switches \
--one-line=keep-blocks \
--one-line=keep-statements \
--max-instatement-indent=40 \
--min-conditional-indent=-1 \
--suffix=none"

export ARTISTIC_STYLE_OPTIONS="\
$ARTISTIC_STYLE_OPTIONS \
--pad=oper \
--pad=paren-in \
--unpad=paren"
astyleit()
{
scripts/sort_includes.pl "$1"

$ASTYLE \
--preserve-date \
--indent-preprocessor \
--brackets=break \
--convert-tabs \
--indent=spaces=2 \
--indent-classes \
--indent-labels \
--indent-namespaces \
--indent-switches \
--one-line=keep-blocks \
--one-line=keep-statements \
--max-instatement-indent=40 \
--min-conditional-indent=-1 \
--suffix=none \
--pad=oper \
--pad=paren-in \
--unpad=paren "$1"
}

for f in "$@"; do
case "$f" in
Expand All @@ -73,7 +75,7 @@ for f in "$@"; do
;;

*.cpp|*.h|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.hpp)
cmd="$ASTYLE $ARTISTIC_STYLE_OPTIONS"
cmd=astyleit
;;

*.ui|*.qgm|*.txt|*.t2t|resources/context_help/*)
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-commit.sh
Expand Up @@ -31,7 +31,7 @@ fi

if [ "$1" = "-c" ]; then
echo "Cleaning..."
find . \( -name "*.prepare" -o -name "*.astyle" -o -name "*.nocopyright" -o -name "astyle.*.diff" -o -name "sha-*.diff" \) -print -delete
find . \( -name "*.prepare" -o -name "*.astyle" -o -name "*.nocopyright" -o -name "astyle.*.diff" -o -name "sha-*.diff" -o -name "*.sortinc" \) -print -delete
fi

set -e
Expand Down
56 changes: 56 additions & 0 deletions scripts/sort_includes.pl
@@ -0,0 +1,56 @@
#!/usr/bin/perl -i.sortinc -n
###########################################################################
# sort_includes.pl
# ---------------------
# begin : June 2015
# copyright : (C) 2015 by Juergen E. Fischer
# email : jef at norbit dot de
#
###########################################################################
# #
# 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. #
# #
###########################################################################

# adapted from scripts/sort_includes.sh

use strict;
use warnings;

our %uis;
our %sys;
our %others;
our $sorting;

BEGIN { $sorting = 0; }
END { die "header files not empty" if keys %uis || keys %sys || keys %others; }

if(/^\s*#include/ ) {
if(/"ui_/ ) {
$uis{$_}=1;
} elsif(/</) {
$sys{$_}=1;
} else {
$others{$_}=1;
}
$sorting=1;
next;
}

if( $sorting ) {
print foreach sort keys %uis;
print foreach sort keys %sys;
print foreach sort keys %others;

undef %uis;
undef %sys;
undef %others;
}


$sorting=0;

print;

3 comments on commit facfe6e

@3nids
Copy link
Member

@3nids 3nids commented on facfe6e Jun 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure but if run on qgsofflineediting.cpp, it will put spatialiate.h before sqlite3.h and it will cause an error in compilation

@3nids
Copy link
Member

@3nids 3nids commented on facfe6e Jun 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this makes my script useless, right?

@jef-n
Copy link
Member Author

@jef-n jef-n commented on facfe6e Jun 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I meanwhile changed it to just remove duplicate includes - that should be save - otherwise prepare-commit.sh or astyle-all.sh could break stuff.

Please sign in to comment.