2020-12-24 20:06:38 +01:00
|
|
|
#!/usr/bin/env sh
|
2015-10-13 21:40:59 +02:00
|
|
|
#
|
|
|
|
#
|
util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
2015-10-13 21:40:59 +02:00
|
|
|
#set -x # uncomment for debug
|
|
|
|
|
2022-08-21 21:25:55 +02:00
|
|
|
JUNIT=0
|
2022-08-21 21:49:37 +02:00
|
|
|
INVERT=0
|
2022-08-21 21:25:55 +02:00
|
|
|
|
2015-10-13 21:40:59 +02:00
|
|
|
usage () {
|
2022-08-21 21:45:35 +02:00
|
|
|
printf "Usage: %s <sub-command> [Options]\n" "$0"
|
|
|
|
printf " Sub-commands:\n"
|
|
|
|
printf " lint-stable : Run standard lint tests - should pass\n"
|
|
|
|
printf " lint-extended : Run extended lint tests - should pass\n"
|
|
|
|
printf " lint : Run full lint tests - Not expected to pass\n\n"
|
|
|
|
|
|
|
|
printf " Options:\n"
|
|
|
|
printf " -h | --help : Show this help message\n"
|
2022-08-21 21:49:37 +02:00
|
|
|
printf " -I | --invert : Invert results - used for testing linters\n"
|
2022-08-21 21:45:35 +02:00
|
|
|
printf " -J | --junit : Send test output to a JUnit file\n"
|
|
|
|
printf "\n"
|
2015-10-13 23:04:17 +02:00
|
|
|
}
|
|
|
|
|
2015-10-16 18:23:57 +02:00
|
|
|
#write to the junit xml file if --junit was specified
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write () {
|
|
|
|
if [ "$JUNIT" -eq 1 ]; then
|
|
|
|
echo "$1" >> "$XMLFILE"
|
|
|
|
fi
|
2015-10-13 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-21 21:49:37 +02:00
|
|
|
if ! cmd_args="$(getopt -l help,junit,invert -o hIJ -- "$@")"; then
|
2022-08-21 21:25:55 +02:00
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
eval set -- "${cmd_args}"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-h | --help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2022-08-21 21:49:37 +02:00
|
|
|
-I | --invert)
|
|
|
|
INVERT=1
|
|
|
|
;;
|
2022-08-21 21:25:55 +02:00
|
|
|
-J | --junit)
|
|
|
|
echo "selected junit"
|
|
|
|
JUNIT=1
|
|
|
|
;;
|
|
|
|
--) shift; break ;;
|
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2015-10-16 18:23:57 +02:00
|
|
|
#verify the first command line parameter
|
2022-08-21 21:25:55 +02:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Error: A sub-command is needed."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
elif [ "$1" != "lint" ] && [ "$1" != "lint-stable" ] &&
|
2016-08-30 17:39:48 +02:00
|
|
|
[ "$1" != "lint-extended" ]; then
|
2022-08-21 21:25:55 +02:00
|
|
|
echo "Error: $1 is not a valid sub-command."
|
2015-10-13 21:40:59 +02:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-05-17 21:57:57 +02:00
|
|
|
LINTLOG=$(mktemp .tmpconfig.lintXXXXXX);
|
2015-10-16 18:23:57 +02:00
|
|
|
XMLFILE="$(dirname "$0")/junit.xml"
|
2016-08-30 17:39:48 +02:00
|
|
|
if [ "$1" = "lint-extended" ]; then
|
|
|
|
XMLFILE="$(dirname "$0")/extended-junit.xml"
|
|
|
|
fi
|
2015-10-13 21:40:59 +02:00
|
|
|
FAILED=0;
|
|
|
|
|
2022-08-21 21:25:55 +02:00
|
|
|
if [ "${JUNIT}" -eq 1 ]; then
|
2015-10-13 23:04:17 +02:00
|
|
|
echo '<?xml version="1.0" encoding="utf-8"?>' > "$XMLFILE"
|
|
|
|
junit_write '<testsuite>'
|
|
|
|
fi
|
2015-10-16 18:23:57 +02:00
|
|
|
|
|
|
|
#run all scripts of the requested type
|
|
|
|
for script in "$(dirname "$0")/${1}-"*; do
|
2018-05-30 18:43:32 +02:00
|
|
|
printf "%s " "$(grep '^# DESCR:' "$script" | sed 's,.*DESCR: *,,')"
|
|
|
|
printf "(%s): " "$(basename "$script")"
|
2015-10-16 18:23:57 +02:00
|
|
|
junit_write " <testcase classname='lint' name='$(basename "$script")'>"
|
2016-10-24 22:36:32 +02:00
|
|
|
$script | tee "$LINTLOG"
|
2015-10-16 18:23:57 +02:00
|
|
|
|
|
|
|
#if the lint script gives any output, that's a failure
|
2022-08-21 21:49:37 +02:00
|
|
|
if [ "${INVERT}" -eq 1 ] && [ "$(wc -l < "$LINTLOG")" -ne 0 ]; then
|
|
|
|
echo "success"
|
|
|
|
junit_write " <system-out><![CDATA[success]]></system-out>"
|
|
|
|
elif [ "${INVERT}" -eq 0 ] && [ "$(wc -l < "$LINTLOG")" -eq 0 ]; then
|
2015-10-13 21:40:59 +02:00
|
|
|
echo "success"
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write " <system-out><![CDATA[success]]></system-out>"
|
2015-10-13 21:40:59 +02:00
|
|
|
else
|
2016-10-24 22:36:32 +02:00
|
|
|
echo "test failed"
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write " <failure type='testFailed'><![CDATA["
|
2015-10-16 18:23:57 +02:00
|
|
|
junit_write "$(cat "$LINTLOG")"
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write "]]></failure>"
|
2015-10-16 18:23:57 +02:00
|
|
|
rm -f "$LINTLOG"
|
|
|
|
FAILED=$(( FAILED + 1 ))
|
2015-10-13 21:40:59 +02:00
|
|
|
fi
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write ' </testcase>'
|
2015-10-13 21:40:59 +02:00
|
|
|
done
|
|
|
|
|
2015-10-16 18:23:57 +02:00
|
|
|
rm -f "$LINTLOG"
|
2015-10-13 23:04:17 +02:00
|
|
|
junit_write '</testsuite>'
|
2015-11-19 15:46:37 +01:00
|
|
|
test $FAILED -eq 0 || { echo "ERROR: $FAILED test(s) failed."; exit 1; };
|