From 05dccbadc44c9bd44b32ea9712125deb1b88cbea Mon Sep 17 00:00:00 2001 From: Marcus Shawcroft Date: Fri, 1 Mar 2019 18:09:35 +0000 Subject: [PATCH] Improve task_lint.sh robustness (#2711) * [SCRIPT] Refactor grep for multiple patterns Tidy up the use of grep. Use -E rather than run multiple grep instances. * [SCRIPT] Refactor grep use in pipeline. Prefer to use stdin redirection rather than create a pipeline. * [SCRIPT] Refactor placement and cleanup of temporary files. Place temporary files in the conventional /tmp location. Avoid poisoning file name space by using $$. Ensure the temporary files get cleaned up, even when the script fails / exits early. * [SCRIPT] Improve robustness of task_lint.sh error handling. Ensure script failures are caught and propagated. Rather than trying to explicitly catch and propagate failures with explicit "|| exit" annotations, use the "set -e" idom from docker/install scripts and have the shell catch and propagate errors in the general case and special case the grep instances where non zero exit is permitted and should be ignored. --- tests/scripts/task_lint.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh index 95f700172ed5..318671b082e6 100755 --- a/tests/scripts/task_lint.sh +++ b/tests/scripts/task_lint.sh @@ -1,17 +1,26 @@ #!/bin/bash + +set -e +set -u +set -o pipefail + +cleanup() +{ + rm -rf /tmp/$$.* +} +trap cleanup 0 + echo "Check codestyle of c++ code..." -make cpplint || exit -1 +make cpplint echo "Check codestyle of python code..." -make pylint || exit -1 +make pylint echo "Check codestyle of jni code..." -make jnilint || exit -1 +make jnilint echo "Check documentations of c++ code..." -make doc 2>log.txt -(cat log.txt| grep -v ENABLE_PREPROCESSING |grep -v "unsupported tag") > logclean.txt +make doc 2>/tmp/$$.log.txt + +grep -v -E "ENABLE_PREPROCESSING|unsupported tag" < /tmp/$$.log.txt > /tmp/$$.logclean.txt || true echo "---------Error Log----------" -cat logclean.txt +cat /tmp/$$.logclean.txt echo "----------------------------" -(cat logclean.txt|grep warning) && exit -1 -(cat logclean.txt|grep error) && exit -1 -rm logclean.txt -rm log.txt +grep -E "warning|error" < /tmp/$$.logclean.txt || true