chore: build scripts use sed -E for cross-OS compatibility#3275
chore: build scripts use sed -E for cross-OS compatibility#3275alex-courtis wants to merge 2 commits intomasterfrom
Conversation
|
Oh, I had a lot of "fun" with this as well in the past! GNU and BSD (default macOS) sed are slightly different, particularly around the Current usage: sed -i -e "/${inject}/r /tmp/DEFAULT_OPTS.6.lua" -e "/${inject}/d" "${WIP}"Workarounds:
# NOTE: POSIX `r` command reads the filename until end of line,
# so a newline is required after the filename to terminate it.
# GNU sed treats the end of the -e string as a line boundary, so it works, but technically it's not POSIX compliant.
sed "/${inject}/r /tmp/DEFAULT_OPTS.6.lua
" "${WIP}" | sed "/${inject}/d" > "${WIP}.tmp" && mv "${WIP}.tmp" "${WIP}"
if [ "$(uname -s)" = "Darwin" ]; then
sed -i '' "/${inject}/r /tmp/DEFAULT_OPTS.6.lua
" "${WIP}"
sed -i '' "/${inject}/d" "${WIP}"
else
sed -i -e "/${inject}/r /tmp/DEFAULT_OPTS.6.lua" -e "/${inject}/d" "${WIP}"
fi
awk "/${inject}/{while((getline line < \"/tmp/DEFAULT_OPTS.6.lua\") > 0) print line; next} {print}" "${WIP}" > "${WIP}.tmp" && mv "${WIP}.tmp" "${WIP}"
PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH" make help-updateor conditionally call |
|
@alex-courtis I will test this one shortly |
Nice one @v3ceban , many solutions there. 1 is clear and simple. Using -i is not really necessary and is fragile and confusing. 3 is pragmatic, simple, compatible and there is precedent with doc-comments.sh 2 and 4 aren't very friendly and create friction. Let's see how it tests. |
f55a655 to
c534eaf
Compare
Many thanks to @Uanela for finding this one: #3261 (comment)
I'd be really grateful for your testing with the "standard" macos sed.