Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMAKE_POST_LINK action with sed: in file replacement?
Forum Updated to NodeBB v4.3 + New Features

QMAKE_POST_LINK action with sed: in file replacement?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 262 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bart_Vandewoestyne
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bart_Vandewoestyne
        wrote on last edited by
        #3

        Since qmake's sed apparently doesn't support in-file replacements, I redirected the output of the sed -e command to a .tmp file, and then renamed that .tmp file using $$QMAKE_MOVE. Works fair enough :-)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved