linuxkit/kubernetes

make update-hashes is not portable

Closed this issue · 5 comments

It fails on macOS:

> make update-hashes
set -e ; for tag in $(linuxkit pkg show-tag pkg/kubelet) \
	           $(linuxkit pkg show-tag pkg/cri-containerd) \
	           $(linuxkit pkg show-tag pkg/kubernetes-docker-image-cache-common) \
	           $(linuxkit pkg show-tag pkg/kubernetes-docker-image-cache-control-plane) ; do \
	    image=${tag%:*} ; \
	    git grep -E -l "\b$image:" | xargs --no-run-if-empty sed -i.bak -e "s,$image:[[:xdigit:]]\{40\}\(-dirty\)\?,$tag,g" ; \
	done
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
make: *** [update-hashes] Error 1
ijc commented

Ah, it's the old lack of xargs --no-run-if-empty on MacOS, I think.

Perhaps a while read loop will do for the inner loop instead, something like:

git grep -E -l "\b$image:" | while read f ; do sed -i.bak -e "s,$image:[[:xdigit:]]\{40\}\(-dirty\)\?,$tag,g" "$f" ; done

will do the job.

ijc commented

Or maybe drop the --no-run-if-empty but add a /dev/null to the end (so sed always gets some input file).

ijc commented

Don't you think we need gsed also?

There's not currently any reason suggested here why we would, but I could believe it would be blocked by the xargs issue since sed is never actually executed while the problem is present so it might rear its head soon.

If the sed expression is non-portable (not sure about the portability of [:xdigit:] for example) then I would rather change it to be portable than require people to install gsed (and to hack up our build to call it when appropriate).