eraxillan
eraxillan

Reputation: 1620

qmake "system" command always return success code

I am writing the auto-build system for the one complicated Qt5 program.
Some of it's C++ sources contains special markers and need to be processed by the external utility.
So i decide to write a custom prebuild step in qmake project like this:

!build_pass {
    win32 {
         for( src, SOURCES ) {
            system("findstr \"MY_CUSTOM_MARKER\" $$src"):system( MyExternalUtil $$src )
         }
     }
}

But first system command always return success, i.e. all of my sources will be processed!
However, official Qt documentation say they should not.

So my question is: why such system command always returns 0?

P.S. I tried it in the Windows command prompt: findstr properly set %errorlevel% to the 1 when specified text was not found.

P.P.S Here is the workaround(just use other version of system):

!build_pass {
    win32 { 
         for( SRC_PATH, SOURCES ) {
             FULL_SRC_PATH = \"$$PWD/$$SRC_PATH\"
             FULL_SRC_PATH = $$replace( FULL_SRC_PATH, /, \ )

             FIND_RES = $$system( findstr \"MY_CUSTOM_MARKER\" $$FULL_SRC_PATH )
             !isEmpty( FIND_RES ) {
                 message( Processing $$SRC_PATH... )
                 system( MyExternalUtil $$FULL_SRC_PATH )
             }
         }
     }
 }

Upvotes: 4

Views: 957

Answers (1)

Wei Lou
Wei Lou

Reputation: 9

defineTest(systemWrapper) {
    ret = $$system($${ARGS} 2> /dev/null; echo $?)
    equals(ret, 0):return(true)
    return(false)
}

Upvotes: 1

Related Questions