blob: 570b6b5bbd925aeeb484cef0369172ece245336b [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
3# Copyright (c) 2019, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8TEST_CASE="Line endings not valid"
9
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050010EXIT_VALUE=0
11
Fathi Boudra422bf772019-12-02 11:10:16 +020012echo "# Check Line Endings"
13
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050014LOG_FILE=$(mktemp -t common.XXXX)
Fathi Boudra422bf772019-12-02 11:10:16 +020015
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050016if [[ "$2" == "patch" ]]; then
17 cd "$1"
18 parent=$(git merge-base HEAD master | head -1)
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"
21else
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"
35fi
Fathi Boudra422bf772019-12-02 11:10:16 +020036
37if [[ -s "$LOG_FILE" ]]; then
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050038 EXIT_VALUE=1
Fathi Boudra422bf772019-12-02 11:10:16 +020039fi
40
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050041{ 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"
Fathi Boudra422bf772019-12-02 11:10:16 +020049
50rm "$LOG_FILE"
51
52exit "$EXIT_VALUE"