blob: dabe42cd97f7510ce88c55f759c5abdc1d9a9ec8 [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
Harrison Mutaic05d1412025-07-16 08:26:58 +000019 parent=${merge_base}
Wing Li7981fd72023-03-09 16:32:28 -080020 git diff $parent..HEAD --no-ext-diff --unified=0 --exit-code -a \
Harrison Mutai1f1e6cf2025-06-24 09:28:18 +000021 --no-prefix **/{Makefile,*.{S,c,h,i,dts,dtsi,rst,mk,rs}} | \
Wing Li7981fd72023-03-09 16:32:28 -080022 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' \
Zachary Leafb6d86302024-10-29 10:29:15 +000036 -name '*.rs' \
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050037 -\) -exec grep --files-with-matches $'\r$' {} \; &> "$LOG_FILE"
38fi
Fathi Boudra422bf772019-12-02 11:10:16 +020039
40if [[ -s "$LOG_FILE" ]]; then
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050041 EXIT_VALUE=1
Fathi Boudra422bf772019-12-02 11:10:16 +020042fi
43
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050044{ echo; echo "****** $TEST_CASE ******"; echo; } >> "$LOG_TEST_FILENAME"
45
46{ if [[ "$EXIT_VALUE" == 0 ]]; then \
47 echo "Result : SUCCESS"; \
48 else \
49 echo "Result : FAILURE"; echo; cat "$LOG_FILE"; \
50 fi \
51} | tee -a "$LOG_TEST_FILENAME"
Fathi Boudra422bf772019-12-02 11:10:16 +020052
53rm "$LOG_FILE"
54
55exit "$EXIT_VALUE"