When process_file function fails the output of the processed script is show to the user, some parsing is performed as well to look for common errors so we can point to the right input file.
This can only be done when the scc_output_file have some valid content otherwise it will show invalid messages to the user. Signed-off-by: Jose Quaresma <[email protected]> --- tools/scc | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/tools/scc b/tools/scc index 78e7445..58a9e46 100755 --- a/tools/scc +++ b/tools/scc @@ -249,28 +249,32 @@ process_file() if [ $? -ne 0 ]; then echo "[ERROR]: processing of file $in failed" - cat ${scc_output_file} - # look for common errors so we can point to the right input file - - # 1) /tmp/tmp.gfN6WsbDHN: line 403: cat: No such file or directory - # "grep -oh" will only output what matches, which gets us "line 404: .." - # cut gets us the second field, which is the line number - line=$(cat ${scc_output_file} | grep -oh "line.*:" | cut -f2 -d' ' | sed 's/://g') - if [ -n "$line" ]; then - let start_line=$line-20 - let end_line=$line+10 - if [ $start_line -lt 0 ]; then - start_line=0 + # if the scc_output_file has content + if [ ! -s "${scc_output_file}" ]; then + cat ${scc_output_file} + + # look for common errors so we can point to the right input file + + # 1) /tmp/tmp.gfN6WsbDHN: line 403: cat: No such file or directory + # "grep -oh" will only output what matches, which gets us "line 404: .." + # cut gets us the second field, which is the line number + line=$(cat ${scc_output_file} | grep -oh "line.*:" | cut -f2 -d' ' | sed 's/://g') + if [ -n "$line" ]; then + let start_line=$line-20 + let end_line=$line+10 + if [ $start_line -lt 0 ]; then + start_line=0 + fi + echo "" + echo "Context around the error is:" + echo "" + sed -n -e "$start_line,$end_line p" -e "$end_line q" $in | sed 's/^/ /' + echo "" + echo "See pre-processed file $in for more details" fi - echo "" - echo "Context around the error is:" - echo "" - sed -n -e "$start_line,$end_line p" -e "$end_line q" $in | sed 's/^/ /' - echo "" - echo "See pre-processed file $in for more details" fi - rm -f ${scc_output_file} + rm -f ${scc_output_file} exit 1 elif [ -n "${verbose}" ]; then cat ${scc_output_file} -- 2.34.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#11740): https://lists.yoctoproject.org/g/linux-yocto/message/11740 Mute This Topic: https://lists.yoctoproject.org/mt/93998448/21656 Group Owner: [email protected] Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
