-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlegacy-suggest.sh
246 lines (215 loc) · 5.42 KB
/
legacy-suggest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
# gcc settings, -fatal-errors
ERROR_FILE=tmp-build-errors.txt
FAKES_BASENAME=tmp-xfakes
SORTED_UNDEFINES=tmp-undefined-sorted.txt
INCLUDE_ROOT=${INCLUDE_ROOT:-.}
MAKEFILE_INCLUDE_STR=${MAKEFILE_INCLUDE_STR:-"INCLUDE_DIRS += "}
MAKEFILE_WARNING_STR=${MAKEFILE_WARNING_STR:-"CPPUTEST_WARNINGFLAGS += "}
# GEN_XFAKES=$(dirname $0)/gen-xfakes.sh
# if [ ! -e "${GEN_XFAKES}" ]; then
# echo "error: missing ${GEN_XFAKES}"
# exit 1
# fi
# source $GEN_XFAKES
looks_like()
{
echo "Looks like you $1"
}
declare -a not_declared=(
"not declared in this scope"
"unknown type name"
)
declare -a include_head=(
".* error: '"
".* error: "
)
declare -a include_tail=(
": No such file or directory"
"' file not found"
)
declare -a linker_error_in_file=(
"error: ld"
"clang: error: linker"
"LNK2019"
)
show_not_declared()
{
for text in "${not_declared[@]}"; do
out=$(grep "${text}" $1)
if [ "$?" = "0" ]; then
echo $out
looks_like "have a missing #include (${text})"
return 0
fi
done
return 1
}
show_missing_include_path()
{
for text in "${include_tail[@]}"; do
out=$(grep "${text}" $1)
if [ "$?" = "0" ]; then
echo $out
looks_like "a missing include path in your makefile (${text})"
grep "#include" $1
file=$(isolate_missing_file "${out}")
echo "Missing include path to ${file}"
suggest_include_path $file
return 0
fi
done
return 1
}
isolate_missing_file()
{
line="$@"
for text in "${include_head[@]}" ]; do
line=$(echo $line | sed -e"s/${text}//")
done
for text in "${include_tail[@]}" ]; do
line=$(echo $line | sed -e"s/${text}//")
done
echo $line
}
suggest_include_path()
{
cd $INCLUDE_ROOT
target=$(basename $1)
partial_path=$(dirname $1)
echo "$ cd ${INCLUDE_ROOT}"
echo "$ find . -name ${target}"
cd ${INCLUDE_ROOT}
filepath=$(find . -name ${target})
if [ "${filepath}" == "" ]; then
echo "${target} not found under ${INCLUDE_ROOT}"
else
echo "Path to $1 under ${INCLUDE_ROOT}"
echo $filepath
if [ "${partial_path}" == "." ]; then
dir=$(dirname $filepath)
include_path="\$(INCLUDE_ROOT)${dir#?}"
echo "Add this to your makefile:"
echo "${MAKEFILE_INCLUDE_STR}${include_path}"
fi
fi
}
show_noise_reduced_heading()
{
echo "-----------------------------------------------------"
echo "--------- Noise reduced build error output ----------"
echo "-----------------------------------------------------"
}
show_warnings()
{
grep "\[\-W" $1
test "$?" = "1" && return 1
echo "You could [temporarily] turn off the warning with"
echo "${MAKEFILE_WARNING_STR}-Wno-<warning-spec>"
return 0
}
link_errors_exist()
{
rm -f $SORTED_UNDEFINES
for text in "${linker_error_in_file[@]}"; do
grep "${text}" $1 >/dev/null
if [ "$?" == "0" ]; then
return 0
fi
done
return 1
}
show_other_compile_errors()
{
link_errors_exist $1 && return 1
grep ": error: " $1
[ "$?" = "1" ] && return 1
echo "Sorry, I can't help with this build error."
rm -f outcome.special
return 0
}
linkErrorClang()
{
grep ", referenced from:"
}
isolateUndefinedSymbolsClang()
{
linkErrorClang | sed -e's/^ *"//' -e's/".*//' -e's/^_//'
}
linkErrorGcc()
{
grep ": undefined reference to "
}
isolateUndefinedSymbolsGcc()
{
linkErrorGcc | sed -e's/.*`//' -e"s/'$//"
}
linkErrorVS_C()
{
grep "LNK2019.*symbol _"
}
linkErrorVS_Cpp()
{
grep "LNK2019\|LNK2001" | grep ".*symbol \""
}
isolateUndefinedSymbolsVS_C()
{
linkErrorVS_C | sed -e's/^.*symbol _/__C__/' -e's/ referenced.*//' -e's/__C__//'
}
isolateUndefinedSymbolsVS_Cpp()
{
linkErrorVS_Cpp | sed -e's/^.*symbol "/__CPP__/' -e's/" .*//' -e's/__CPP__//'
}
isolate_linker_errors()
{
input_file=$1
must_exist $input_file
undefines=$(mktemp)
isolateUndefinedSymbolsGcc <$input_file >$undefines
isolateUndefinedSymbolsClang <$input_file >>$undefines
isolateUndefinedSymbolsVS_C <$input_file >>$undefines
isolateUndefinedSymbolsVS_Cpp <$input_file >>$undefines
LC_ALL=C sort $undefines | uniq >$SORTED_UNDEFINES
echo "***********************************"
echo "You have linker errors. See '${SORTED_UNDEFINES}' for a sorted list."
echo "You have a choice to make."
echo " 1) Add the missing implementation to the build."
echo " 2) Add the generated exploding fakes to the build."
echo " 3) Make your own fake."
echo "***********************************"
rm $undefines
}
file_empty()
{
[ ! -s $1 ]
}
legacy_suggest()
{
echo "one of the recognized errors" > outcome.special
file_empty $1 && return 0
show_noise_reduced_heading
show_not_declared $1 && return 1
show_missing_include_path $1 && return 1
show_warnings $1 && return 1
show_other_compile_errors $1 && return 1
link_errors_exist $1 && isolate_linker_errors $1
return 1
}
check_input()
{
if [ "$#" == "0" ]; then
echo "usage: $0 compiler-output-error-file"
exit 1
fi
if [[ ! -e "$1" ]]; then
echo "Error file does not exist: $1"
exit 1
fi
}
legacy_build_suggestion()
{
check_input $1 && legacy_suggest $1
}
if [[ "$0" = "$BASH_SOURCE" ]]; then
legacy_build_suggestion $1
fi