Jayanth Dodderi Chidanand | 5132cb1 | 2021-08-09 17:54:47 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2021 Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # static-checks-detect-newly-added-files.sh |
| 9 | # This script aims at identifying the newly added source files |
| 10 | # between the commits. |
| 11 | # It runs on every TF-A patch and detects the new files and updates |
| 12 | # the patch contibutor to include them for Coverity Scan analysis. |
| 13 | |
| 14 | LOG_FILE=$(mktemp -t files-detection-check.XXXX) |
| 15 | TFA_PATCH_NEWFILES_LIST=$(mktemp -t tfa-patch-newfiles-list.XXXX) |
| 16 | EXIT_VALUE=0 |
| 17 | |
| 18 | # Function : file_updation_report |
| 19 | # Description : To update the inclusion of files listed in the temp file |
| 20 | # (tfa-patch-newfiles-list.XXXX) for Coverity Scan Analysis. |
| 21 | # Return : newly added source files,are captured onto the error log |
| 22 | # and the Error status is printed. |
| 23 | function file_updation_report( ) |
| 24 | { |
| 25 | echo "========================================================================" |
| 26 | echo "New source files have been identified in your patch.." |
| 27 | echo >> "$LOG_FILE" |
| 28 | echo "New source files have been identified in your patch.." >> "$LOG_FILE" |
| 29 | # Iterating through the patch filenames and logging them onto error report. |
| 30 | while read filename |
| 31 | do |
| 32 | echo "$filename" |
| 33 | echo "$filename" >> "$LOG_FILE" |
| 34 | done < "$TFA_PATCH_NEWFILES_LIST" |
| 35 | |
| 36 | echo |
| 37 | echo -e "1. Kindly ensure they are updated in the \"tf_cov_make\" build script as \n \ |
| 38 | well to consider them for Coverity Scan analysis." |
| 39 | echo >> "$LOG_FILE" |
| 40 | echo -e "1. Kindly ensure they are updated in the \"tf_cov_make\" build script as \n \ |
| 41 | well to consider them for Coverity Scan analysis." >> "$LOG_FILE" |
| 42 | |
| 43 | echo |
| 44 | echo -e "2. Please ignore if files are already updated. Further the Code Maintainer \n \ |
| 45 | will resolve the issue by taking appropriate action." |
| 46 | echo >> "$LOG_FILE" |
| 47 | echo -e "2. Please ignore if files are already updated. Further the Code Maintainer \n \ |
| 48 | will resolve the issue by taking appropriate action." >> "$LOG_FILE" |
| 49 | echo "========================================================================" |
| 50 | |
| 51 | EXIT_VALUE=1 |
| 52 | } |
| 53 | |
| 54 | # Detecting source files not analysed by tf-coverity-job in the latest patch |
| 55 | echo "# Check to detect whether newly added files are analysed by Coverity in the patch" |
| 56 | TEST_CASE="Newly added files detection check for Coverity Scan analysis on patch(es)" |
| 57 | # Extracting newly added source files added between commits. |
| 58 | git diff origin/master...HEAD --name-only --diff-filter=A "*.c" &> "$TFA_PATCH_NEWFILES_LIST" |
| 59 | if [ -s "$TFA_PATCH_NEWFILES_LIST" ] |
| 60 | then |
| 61 | file_updation_report |
| 62 | fi |
| 63 | |
| 64 | echo >> "$LOG_TEST_FILENAME" |
| 65 | echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME" |
| 66 | echo >> "$LOG_TEST_FILENAME" |
| 67 | |
| 68 | if [[ "$EXIT_VALUE" == 0 ]]; then |
| 69 | echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME" |
| 70 | else |
| 71 | echo "Result : FAILURE" >> "$LOG_TEST_FILENAME" |
| 72 | fi |
| 73 | |
| 74 | # Printing the script output to show the warnings. |
| 75 | echo >> "$LOG_TEST_FILENAME" |
| 76 | cat "$LOG_FILE" >> "$LOG_TEST_FILENAME" |
| 77 | echo >> "$LOG_TEST_FILENAME" |
| 78 | |
| 79 | #Deleting temporary files |
| 80 | rm -f "$LOG_FILE" |
| 81 | rm -f "$TFA_PATCH_NEWFILES_LIST" |
| 82 | |
| 83 | exit "$EXIT_VALUE" |