From a34d2beaa75f2bd17e5fa8c1491e6c06fb0e530c Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 10 Apr 2025 10:03:32 +0200 Subject: [PATCH] MT#61842 jdg-tap-tool-dispatcher: fix file-list handling with jdg-tap-merge-conflict Noticed via: | *** Skipping pep8 checks as tool pep8 isn't present *** | mkdir -p reports/source/functions ; /usr/bin/jdg-tap-checkbashism source/functions/host-summary > reports/source/functions/host-summary_checkbashism.tap ; /usr/bin/jdg-tap-perlcritic source/functions/host-summary > reports/source/functions/host-summary_perlcritic.tap ; /usr/bin/jdg-tap-shellcheck source/functions/host-summary > reports/source/functions/host-summary_shellcheck.tap ; | File source/functions/host-summary doesn't look like perl [Bourne-Again shell script, Unicode text, UTF-8 text executable]. Ignoring. | Error: file {} could not be read. | *** Getting rid of empty files *** We're invoking jdg-tap-tool-dispatcher with the -f ... option, to pass a certain list of files that should be checked. Our generated execution script from jdg-tap-tool-dispatcher looks like this: sed 's#^#source/#g' < /code/git.change | parallel -v -- \ mkdir -p reports'/'{//} ';' \ /usr/bin/jdg-tap-checkbashism '{}' '>' reports'/{}_checkbashism.tap' ';' \ /usr/bin/jdg-tap-perlcritic '{}' '>' reports'/{}_perlcritic.tap' ';' \ /usr/bin/jdg-tap-shellcheck '{}' '>' reports'/{}_shellcheck.tap' ';' /usr/bin/jdg-tap-merge-conflict '{}' '>' reports'/{}_mergecheck.tap' ';' So we try to invoke /usr/bin/jdg-tap-merge-conflict outside of the actual parallel run, as the trailing '\' in the shellcheck command line is missing. So /usr/bin/jdg-tap-merge-conflict is invoked with literally '{}', and therefore complaining with: Error: file {} could not be read. To avoid such a failure we need to end all jdp-* command lines with a "\" to mark them for continuation in next line. Also let's add a noop line to the end of the script to get valid code syntax. New execution script now looks like this then: sed 's#^#source/#g' < /code/git.change | parallel -v -- \ mkdir -p reports'/'{//} ';' \ /usr/bin/jdg-tap-checkbashism '{}' '>' reports'/{}_checkbashism.tap' ';' \ /usr/bin/jdg-tap-perlcritic '{}' '>' reports'/{}_perlcritic.tap' ';' \ /usr/bin/jdg-tap-shellcheck '{}' '>' reports'/{}_shellcheck.tap' ';' \ /usr/bin/jdg-tap-merge-conflict '{}' '>' reports'/{}_mergecheck.tap' ';' \ # EOF While at it, fix comment regarding generated script (we execute the generated script, not generate the executed script :)), and also fix a shellcheck issue reported for tap/jdg-tap-tool-dispatcher: | In tap/jdg-tap-tool-dispatcher line 12: | if [ $? -ne 0 ]; then | ^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. Change-Id: I3c8a557712c1dad78c2404ea83e44ff281e077ac --- tap/jdg-tap-tool-dispatcher | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tap/jdg-tap-tool-dispatcher b/tap/jdg-tap-tool-dispatcher index d2ff621..bf35ced 100755 --- a/tap/jdg-tap-tool-dispatcher +++ b/tap/jdg-tap-tool-dispatcher @@ -8,8 +8,7 @@ BASE_BIN=${BASE_BIN:-/usr/bin} CMDLINE_OPTS=disable-checkbashism,disable-pep8,disable-perlcritic,disable-shellcheck,disable-mergecheck CMDLINE_OPTS+=,file-list,help -_opt_temp=$(getopt --name jdg-tap-tool-dispatcher -o -f+h --long $CMDLINE_OPTS -- "$@") -if [ $? -ne 0 ]; then +if ! _opt_temp=$(getopt --name jdg-tap-tool-dispatcher -o -f+h --long $CMDLINE_OPTS -- "$@") ; then echo "Try '$0 --help' for more information." >& 2 exit 1 fi @@ -145,19 +144,22 @@ if ! [ -x "$(which shellcheck)" ] ; then echo "*** Skipping shellcheck checks as tool shellcheck isn't present ***" else if $_opt_shellcheck ; then - echo "${BASE_BIN}/jdg-tap-shellcheck '{}' '>' ${REPORTS_DIRECTORY}'/{}_shellcheck.tap' ';'" >> "${TMPFILE}" + echo "${BASE_BIN}/jdg-tap-shellcheck '{}' '>' ${REPORTS_DIRECTORY}'/{}_shellcheck.tap' ';' \\" >> "${TMPFILE}" else echo "*** Skipping shellcheck tests as requested via --disable-shellcheck ***" fi fi if $_opt_mergecheck ; then - echo "${BASE_BIN}/jdg-tap-merge-conflict '{}' '>' ${REPORTS_DIRECTORY}'/{}_mergecheck.tap' ';'" >> "${TMPFILE}" + echo "${BASE_BIN}/jdg-tap-merge-conflict '{}' '>' ${REPORTS_DIRECTORY}'/{}_mergecheck.tap' ';' \\" >> "${TMPFILE}" else echo "*** Skipping merge-conflict check tests as requested via --disable-mergecheck ***" fi -# generate the executed script +# generate noop to properly mark end of script +echo "# EOF" >> "${TMPFILE}" + +# execute the generated script bash "${TMPFILE}" rm -f "${TMPFILE}"