1#! /bin/bash
2################################################################################
3# Check Build Errors
4#
5# Copyright (C) Nintendo.  All rights reserved.
6#
7# These coded instructions, statements, and computer programs contain
8# proprietary information of Nintendo of America Inc. and/or Nintendo
9# Company Ltd., and are protected by Federal copyright law.  They may
10# not be disclosed to third parties or copied or duplicated in any form,
11# in whole or in part, without the prior written consent of Nintendo.
12#
13# usage: ./check_build_errors.sh ${BUILD_LOG}
14#    e.g)
15#        ./check_build_errors.sh build_output.txt
16#
17###############################################################################
18TMP_MESSAGES=${TMPDIR:-/tmp}/messages_$$.txt
19
20function remove_temporary_files
21{
22    rm -f ${TMP_MESSAGES}
23}
24
25function interrupted
26{
27    echo "INTERRUPTED"
28    remove_temporary_files
29    exit 6
30}
31
32trap interrupted SIGINT
33
34remove_temporary_files
35
36# check for messages
37# match lines which start with error
38# match lines where the word error or errors is found
39# exclude "-C error" (for example make -C error)
40# match "permission denied" (but don't count as an error)
41# match ": no such file or directory"
42# Note: using -n to sed does not output unless there is a "p" command
43# Also Note: using "I" makes the pattern case insensative
44# exclude the warnings "-jn forced", "skip the hash", and "found in FST or locally" warnings
45# lines with "is missing" are reported, except for the "if this option is missing"
46{
47	sed -n	\
48		-e '/-C error/Id'	\
49		-e '/ has modification time.*in the future/Id' \
50		-e '/Clock skew detected.  Your build may be incomplete/Id' \
51		-e '/No rule to make target.*Stop/Ip' \
52		-e '/[-A-Za-z0-9_\/]error/Id' \
53		-e '/ 0 error(s)/Id'	\
54		-e '/^\**error/Ip'		\
55		-e '/\*\*\*.* Stop\./Ip'	\
56		-e '/[^a-z0-9/.]error[s]*[ :(]/Ip'			\
57		-e '/permission denied/Ip'	\
58		-e '/: no such file or directory/Ip'	\
59		-e '/rm: cannot remove /Ip'	\
60		-e '/rm: error closing file/Ip'	\
61		-e '/file data section size is 0byte./Id'	\
62		-e '/has been deleted as it is empty./Id'	\
63		-e '/Empty Section has been deleted./Id'	\
64		-e '/Missing \[CODE\] or \[DATA\] directive/Id'	\
65		-e '/problems were encountered while processing debug information/Id'	\
66		-e '/warning/I{/-jn forced/Id;/[^ 	*]warnings*/Id;/warnings*[^ 	:]/Id;/skip the hash/Id;/found in FST or locally/Id;p}'	\
67		-e '/is missing/I{/if this option is missing/Id;p}'	\
68	$1
69} > ${TMP_MESSAGES}
70
71# get number of errors and warnings
72error_num=`grep -i -w -e error ${TMP_MESSAGES} | wc -l`
73warning_num=`grep -i -w -e warning ${TMP_MESSAGES} | wc -l`
74missing_num=`grep -i -e "is missing" ${TMP_MESSAGES} | wc -l`
75
76PATH_FROM_CAFE_ROOT=${PWD//$CAFE_ROOT\//}
77
78# print out result
79if [[ $error_num != 0 ]] ; then
80	echo
81	echo "=================================================================="
82	echo "  BUILD RESULT ($PATH_FROM_CAFE_ROOT)"
83	echo "=================================================================="
84	echo "   Error  : $error_num"
85	echo "   Warning: $warning_num"
86	echo "   Missing: $missing_num"
87	echo
88	echo "--------------------------------"
89	echo "-> Error Modules:"
90	echo
91	sed -n -e "/.*make.* \*\*\* \[.*\] Error /{s/.*make.* \*\*\* \[\(.*\)\] Error \(.*\)/\t\1 - Error \2/p}"	\
92		-e "s/[0-9]*>\(.*\) - \(.*\) error(s).*/\t\1 - \2 error(s)/Ip"	\
93		-e "/Errors: /{s/Errors: .*>//g;s'^.*/'  'g;s/: $//g;s/:/ - line: /g;p}" ${TMP_MESSAGES}
94	echo
95
96	if [[ $missing_num != 0 ]] ; then
97		echo "-> Missing Modules:"
98		echo
99        grep -i "is missing" ${TMP_MESSAGES}
100		echo
101	fi
102
103	echo "--------------------------------"
104	echo "-> Error and Warning Log:"
105	echo
106	cat ${TMP_MESSAGES}
107	echo
108
109    remove_temporary_files
110	exit 1
111
112else
113#	echo "  ================================================================"
114#	echo "  BUILD RESULT ($PATH_FROM_CAFE_ROOT)"
115#	echo "  ================================================================"
116#	echo "  Success! :^)8"
117# print out result
118	if [[ $warning_num != 0 ]] ; then
119		echo "--------------------------------"
120		echo "-> Error and Warning Log:"
121		echo
122		cat ${TMP_MESSAGES}
123		echo
124	fi
125    remove_temporary_files
126	exit 0
127fi
128
129