blob: 77985e0bcd3174413e6b3b31c977f7b873926236 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Jayanth Dodderi Chidanand8262cc22022-08-04 17:34:42 +01003# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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"
Leonardo Sandoval9b3163e2020-10-13 12:55:24 -050018 parent=$(git merge-base HEAD refs/remotes/origin/master | head -1)
Jayanth Dodderi Chidanand8262cc22022-08-04 17:34:42 +010019 git diff ${parent}..HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix | awk '/^\+/ && /\r$/' &> "$LOG_FILE"
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050020else
21 # For all the source and doc files
22 # We only return the files that contain CRLF
23 find "." -\( \
24 -name '*.S' -or \
25 -name '*.c' -or \
26 -name '*.h' -or \
27 -name '*.i' -or \
28 -name '*.dts' -or \
29 -name '*.dtsi' -or \
30 -name '*.rst' -or \
31 -name 'Makefile' -or \
32 -name '*.mk' \
33 -\) -exec grep --files-with-matches $'\r$' {} \; &> "$LOG_FILE"
34fi
Fathi Boudra422bf772019-12-02 11:10:16 +020035
36if [[ -s "$LOG_FILE" ]]; then
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050037 EXIT_VALUE=1
Fathi Boudra422bf772019-12-02 11:10:16 +020038fi
39
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050040{ echo; echo "****** $TEST_CASE ******"; echo; } >> "$LOG_TEST_FILENAME"
41
42{ if [[ "$EXIT_VALUE" == 0 ]]; then \
43 echo "Result : SUCCESS"; \
44 else \
45 echo "Result : FAILURE"; echo; cat "$LOG_FILE"; \
46 fi \
47} | tee -a "$LOG_TEST_FILENAME"
Fathi Boudra422bf772019-12-02 11:10:16 +020048
49rm "$LOG_FILE"
50
51exit "$EXIT_VALUE"