Leonardo Sandoval | 314eed8 | 2020-08-05 13:32:04 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | TEST_CASE="Line endings not valid" |
| 9 | |
| 10 | EXIT_VALUE=0 |
| 11 | |
| 12 | echo "# Check Line Endings" |
| 13 | |
| 14 | LOG_FILE=$(mktemp -t common.XXXX) |
| 15 | |
| 16 | if [[ "$2" == "patch" ]]; then |
| 17 | cd "$1" |
Leonardo Sandoval | 900de58 | 2020-09-07 18:34:57 -0500 | [diff] [blame] | 18 | parent=$(git merge-base HEAD origin/master | head -1) |
Leonardo Sandoval | 314eed8 | 2020-08-05 13:32:04 -0500 | [diff] [blame] | 19 | git diff ${parent}..HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix | grep -E "^\+" | \ |
| 20 | grep --files-with-matches $'\r$' &> "$LOG_FILE" |
| 21 | else |
| 22 | # For all the source and doc files |
| 23 | # We only return the files that contain CRLF |
| 24 | find "." -\( \ |
| 25 | -name '*.S' -or \ |
| 26 | -name '*.c' -or \ |
| 27 | -name '*.h' -or \ |
| 28 | -name '*.i' -or \ |
| 29 | -name '*.dts' -or \ |
| 30 | -name '*.dtsi' -or \ |
| 31 | -name '*.rst' -or \ |
| 32 | -name 'Makefile' -or \ |
| 33 | -name '*.mk' \ |
| 34 | -\) -exec grep --files-with-matches $'\r$' {} \; &> "$LOG_FILE" |
| 35 | fi |
| 36 | |
| 37 | if [[ -s "$LOG_FILE" ]]; then |
| 38 | EXIT_VALUE=1 |
| 39 | fi |
| 40 | |
| 41 | { echo; echo "****** $TEST_CASE ******"; echo; } >> "$LOG_TEST_FILENAME" |
| 42 | |
| 43 | { if [[ "$EXIT_VALUE" == 0 ]]; then \ |
| 44 | echo "Result : SUCCESS"; \ |
| 45 | else \ |
| 46 | echo "Result : FAILURE"; echo; cat "$LOG_FILE"; \ |
| 47 | fi \ |
| 48 | } | tee -a "$LOG_TEST_FILENAME" |
| 49 | |
| 50 | rm "$LOG_FILE" |
| 51 | |
| 52 | exit "$EXIT_VALUE" |