blob: 4a08cbaf98540e67e272c179dede434f67ee5920 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Paul Sokolovsky476b0452024-06-18 22:20:32 +03003# Copyright (c) 2019-2024 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
Paul Sokolovsky476b0452024-06-18 22:20:32 +03008TEST_CASE="Line endings are valid"
Fathi Boudra422bf772019-12-02 11:10:16 +02009
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"
Wing Li7981fd72023-03-09 16:32:28 -080018 shopt -s globstar
Leonardo Sandoval9b3163e2020-10-13 12:55:24 -050019 parent=$(git merge-base HEAD refs/remotes/origin/master | head -1)
Wing Li7981fd72023-03-09 16:32:28 -080020 git diff $parent..HEAD --no-ext-diff --unified=0 --exit-code -a \
21 --no-prefix **/*.{S,c,h,i,dts,dtsi,rst,mk} Makefile | \
22 awk '/^\+/ && /\r$/' &> "$LOG_FILE"
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050023else
24 # For all the source and doc files
25 # We only return the files that contain CRLF
26 find "." -\( \
27 -name '*.S' -or \
28 -name '*.c' -or \
29 -name '*.h' -or \
30 -name '*.i' -or \
31 -name '*.dts' -or \
32 -name '*.dtsi' -or \
33 -name '*.rst' -or \
34 -name 'Makefile' -or \
35 -name '*.mk' \
36 -\) -exec grep --files-with-matches $'\r$' {} \; &> "$LOG_FILE"
37fi
Fathi Boudra422bf772019-12-02 11:10:16 +020038
39if [[ -s "$LOG_FILE" ]]; then
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050040 EXIT_VALUE=1
Fathi Boudra422bf772019-12-02 11:10:16 +020041fi
42
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050043{ echo; echo "****** $TEST_CASE ******"; echo; } >> "$LOG_TEST_FILENAME"
44
45{ if [[ "$EXIT_VALUE" == 0 ]]; then \
46 echo "Result : SUCCESS"; \
47 else \
48 echo "Result : FAILURE"; echo; cat "$LOG_FILE"; \
49 fi \
50} | tee -a "$LOG_TEST_FILENAME"
Fathi Boudra422bf772019-12-02 11:10:16 +020051
52rm "$LOG_FILE"
53
54exit "$EXIT_VALUE"