For small ports not so much, but when updating bigger ones with lots of
patches and/or churn, I always find cumbersome to go scroll back in my
terminal to look for failed hunks or cd into WRKSRC and look for .rej
files, so here's a diff that prints the list of failed patches iff there
are any, e.g.,

        $ make patch
        ...
        Hunk #1 succeeded at 22.
        done
        ===>   Failed patches: 
            patch-src_tests_hitch_test_sh

        *** Error 1 in . (/usr/ports/infrastructure/mk/bsd.port.mk:2793 
'/usr/ports/pobj/hitch-1.5.2/.patch_done': @if cd /p/security/hitch/patches ...)
        *** Error 2 in /p/security/hitch 
(/usr/ports/infrastructure/mk/bsd.port.mk:2581 'patch': @lock=hitch-1.5.2;  
export _LOCKS_HELD=" hitch-1.5....)

It seems that 'echo' is used for errors in bsd.port.mk targets instead
of ${ECHO_MSG}, but other shell syntax seem used inconsistently, so I
just went with 'echo' to always print the error/list and used && instead
of if/else as is with the `error' variable.

I'm also deliberately using backslashes and the fact that sh's echo
interprets them instead of doing a for loop over $failed_patches in the
end.

Feedback? OK?


Index: infrastructure/mk/bsd.port.mk
===================================================================
RCS file: /cvs/ports/infrastructure/mk/bsd.port.mk,v
retrieving revision 1.1540
diff -u -p -r1.1540 bsd.port.mk
--- infrastructure/mk/bsd.port.mk       9 Jun 2020 11:01:08 -0000       1.1540
+++ infrastructure/mk/bsd.port.mk       13 Jun 2020 16:39:43 -0000
@@ -2758,6 +2758,7 @@ ${_PATCH_COOKIE}: ${_EXTRACT_COOKIE}
        @${_MAKE} _internal-distpatch
 .  endif
        @if cd ${PATCHDIR} 2>/dev/null || [ x"${PATCH_LIST:M/*}" != x"" ]; then 
\
+               failed_patches=''; \
                error=false; \
                for i in ${PATCH_LIST}; do \
                        case $$i in \
@@ -2773,6 +2774,7 @@ ${_PATCH_COOKIE}: ${_EXTRACT_COOKIE}
                                                if [ -s $$i ]; then \
                                                        ${_PBUILD} ${PATCH} 
${PATCH_ARGS} < $$i || \
                                                                { echo "***>   
$$i did not apply cleanly"; \
+                                                               
failed_patches="$$failed_patches\n    $$i"; \
                                                                error=true; }; \
                                                else \
                                                        ${ECHO_MSG} "===>   
Ignoring empty patchfile $$i"; \
@@ -2786,6 +2788,7 @@ ${_PATCH_COOKIE}: ${_EXTRACT_COOKIE}
                                        ;; \
                        esac; \
                done;\
+               [ -n "$$failed_patches" ] && echo "===>   Failed patches: 
$$failed_patches\n"; \
                if $$error; then exit 1; fi; \
        fi
 # End of PATCH.

Reply via email to