diff options
Diffstat (limited to 'build_tools')
-rwxr-xr-x | build_tools/lint.fish | 23 | ||||
-rwxr-xr-x | build_tools/style.fish | 42 |
2 files changed, 39 insertions, 26 deletions
diff --git a/build_tools/lint.fish b/build_tools/lint.fish index 96efc71b..287269da 100755 --- a/build_tools/lint.fish +++ b/build_tools/lint.fish @@ -34,13 +34,8 @@ if test $all = yes else # We haven't been asked to lint all the source. If there are uncommitted # changes lint those, else lint the files in the most recent commit. - set pending (git status --porcelain --short --untracked-files=all | sed -e 's/^ *//') - if set -q pending[1] - # There are pending changes so lint those files. - for arg in $pending - set files $files (string split -m 1 ' ' $arg)[2] - end - else + set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//') + if not set -q files[1] # No pending changes so lint the files in the most recent commit. set files (git show --word-diff=porcelain --name-only --pretty=oneline head)[2..-1] end @@ -56,10 +51,9 @@ if set -q c_files[1] echo ======================================== echo Running cppcheck echo ======================================== - # The stderr to stdout redirection is because cppcheck, incorrectly - # IMHO, writes its diagnostic messages to stderr. Anyone running - # this who wants to capture its output will expect those messages to be - # written to stdout. + # The stderr to stdout redirection is because cppcheck, incorrectly IMHO, writes its + # diagnostic messages to stderr. Anyone running this who wants to capture its output will + # expect those messages to be written to stdout. cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>& 1 end @@ -68,10 +62,9 @@ if set -q c_files[1] echo ======================================== echo Running oclint echo ======================================== - # The stderr to stdout redirection is because oclint, incorrectly - # writes its final summary counts of the errors detected to stderr. - # Anyone running this who wants to capture its output will expect those - # messages to be written to stdout. + # The stderr to stdout redirection is because oclint, incorrectly writes its final summary + # counts of the errors detected to stderr. Anyone running this who wants to capture its + # output will expect those messages to be written to stdout. if test (uname -s) = "Darwin" if not test -f compile_commands.json xcodebuild > xcodebuild.log diff --git a/build_tools/style.fish b/build_tools/style.fish index 76cf920d..62d8d5c7 100755 --- a/build_tools/style.fish +++ b/build_tools/style.fish @@ -6,6 +6,7 @@ # This runs C++ files and fish scripts (*.fish) through their respective code # formatting programs. # +set git_clang_format no set c_files set f_files set all no @@ -21,17 +22,21 @@ if set -q argv[1] end if test $all = yes + set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//') + if set -q files[1] + echo + echo You have uncommited changes. Cowardly refusing to restyle the entire code base. + echo + exit 1 + end set c_files src/*.h src/*.cpp set f_files ***.fish else - # We haven't been asked to reformat all the source. If there are uncommitted - # changes reformat those, else reformat the files in the most recent commit. - set pending (git status --porcelain --short --untracked-files=all | sed -e 's/^ *//') - if count $pending > /dev/null - # There are pending changes so lint those files. - for arg in $pending - set files $files (string split -m 1 ' ' $arg)[2] - end + # We haven't been asked to reformat all the source. If there are uncommitted changes reformat + # those using `git clang-format`. Else reformat the files in the most recent commit. + set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//') + if set -q files[1] + set git_clang_format yes else # No pending changes so lint the files in the most recent commit. set files (git show --name-only --pretty=oneline head | tail --lines=+2) @@ -45,18 +50,32 @@ end # Run the C++ reformatter if we have any C++ files. if set -q c_files[1] - if type -q clang-format + if test $git_clang_format = yes + if type -q git-clang-format + echo + echo ======================================== + echo Running git-clang-format + echo ======================================== + git add $c_files + git-clang-format + else + echo + echo 'WARNING: Cannot find git-clang-format command' + echo + end + else if type -q clang-format echo echo ======================================== echo Running clang-format echo ======================================== for file in $c_files - clang-format $file > $file.new + clang-format $file >$file.new if cmp --quiet $file $file.new echo $file was correctly formatted rm $file.new else echo $file was NOT correctly formatted + chmod --reference=$file $file.new mv $file.new $file end end @@ -78,12 +97,13 @@ if set -q f_files[1] echo Running fish_indent echo ======================================== for file in $f_files - fish_indent < $file > $file.new + fish_indent <$file >$file.new if cmp --quiet $file $file.new echo $file was correctly formatted rm $file.new else echo $file was NOT correctly formatted + chmod --reference=$file $file.new mv $file.new $file end end |