blob: 9c0cda7611060008c0f3a330c60614e1963c39ee [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Paul Sokolovskyb187f672024-06-24 18:48:17 +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 Sokolovskye311dae2024-06-19 13:34:24 +03008this_dir="$(readlink -f "$(dirname "$0")")"
9. $this_dir/common.sh
10
11
12TEST_CASE="Line endings are valid"
Fathi Boudra422bf772019-12-02 11:10:16 +020013
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050014EXIT_VALUE=0
15
Fathi Boudra422bf772019-12-02 11:10:16 +020016echo "# Check Line Endings"
17
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050018LOG_FILE=$(mktemp -t common.XXXX)
Fathi Boudra422bf772019-12-02 11:10:16 +020019
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050020if [[ "$2" == "patch" ]]; then
21 cd "$1"
Wing Li7981fd72023-03-09 16:32:28 -080022 shopt -s globstar
Paul Sokolovskye311dae2024-06-19 13:34:24 +030023 parent=$(get_merge_base)
Wing Li7981fd72023-03-09 16:32:28 -080024 git diff $parent..HEAD --no-ext-diff --unified=0 --exit-code -a \
25 --no-prefix **/*.{S,c,h,i,dts,dtsi,rst,mk} Makefile | \
26 awk '/^\+/ && /\r$/' &> "$LOG_FILE"
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050027else
28 # For all the source and doc files
29 # We only return the files that contain CRLF
30 find "." -\( \
31 -name '*.S' -or \
32 -name '*.c' -or \
33 -name '*.h' -or \
34 -name '*.i' -or \
35 -name '*.dts' -or \
36 -name '*.dtsi' -or \
37 -name '*.rst' -or \
38 -name 'Makefile' -or \
39 -name '*.mk' \
40 -\) -exec grep --files-with-matches $'\r$' {} \; &> "$LOG_FILE"
41fi
Fathi Boudra422bf772019-12-02 11:10:16 +020042
43if [[ -s "$LOG_FILE" ]]; then
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050044 EXIT_VALUE=1
Fathi Boudra422bf772019-12-02 11:10:16 +020045fi
46
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050047{ echo; echo "****** $TEST_CASE ******"; echo; } >> "$LOG_TEST_FILENAME"
48
49{ if [[ "$EXIT_VALUE" == 0 ]]; then \
50 echo "Result : SUCCESS"; \
51 else \
52 echo "Result : FAILURE"; echo; cat "$LOG_FILE"; \
53 fi \
54} | tee -a "$LOG_TEST_FILENAME"
Fathi Boudra422bf772019-12-02 11:10:16 +020055
56rm "$LOG_FILE"
57
58exit "$EXIT_VALUE"