Solved QMAKE_POST_LINK action with sed: in file replacement?
-
I have the following
QMAKE_POST_LINK
action to replace some text in a certain configuration file:QMAKE_POST_LINK += $$QMAKE_QMAKE -install sed -e 's/foo/bar/g' $$shell_path($${DST_FILE})$$escape_expand(\n\t)
The problem however is, that this does not change the file in place. sed simply spits the new file to standard output.
I tried using the-i
option, but qmake's simple implementation of sed does not support that in my version of Qt (5.15.1).I do want to keep this
QMAKE_POST_LINK
as portable as possible, and do want to stick with qmake's sed implementation because I don't want my users to have to install sed for this.I also tried redirecting to an output file with
QMAKE_POST_LINK += $$QMAKE_QMAKE -install sed -e 's/foo/bar/g' $$shell_path($${DST_FILE}) > $$shell_path($${DST_FILE})$$escape_expand(\n\t)
but that results in an empty file.
Any suggestions on how to make this text replacement in place in a portable way?
-
Does it have to be in place? I would do this in two steps. First, use sed to create your destination path and assign it to a variable (Use system). Then, use that variable in the call to qmake -install.
-
Since qmake's
sed
apparently doesn't support in-file replacements, I redirected the output of thesed -e
command to a .tmp file, and then renamed that .tmp file using$$QMAKE_MOVE
. Works fair enough :-)