External tool and versionAtLeast(variablename, versionNumber)



  • I'm struggling with the versionAtLeast() test function and an external tool.

    TOOLPATH=$$shell_path($$TOOLPATH/$$TOOLEXE)
    !build_pass:message("Path to tool: " $$TOOLPATH)
    # Invoke the tool for a version check.
    TOOLVER=$$system($$TOOLPATH --ver)
    !build_pass:message(Tool version is $$TOOLVER".")
    TOOLMINVER=1.0.52
    !versionAtLeast(TOOLVER, $$TOOLMINVER) {
    	message("Unsupported tool version " $${TOOLVER}".")
    	error("We require tool version "$$TOOLMINVER" or greater")
    }
    

    I somehow can't see anything wrong with this qmake code.
    However, when running qmake, it shows these messages:

    Path to tool: <Correct path to executable is shown here>
    Tool version is 1.0.52.
    Unsupported tool version  .
    We require tool version 1.0.52 or greater
    

    Note the missing output of the version number at "Unsupported tool version .". And also, please note the correct output at "Tool version is 1.0.52." (?!?)
    The test doesn't work either. It always fails with unsupported version, meaning that versionAtLeast() keeps evalutating to FALSE.

    The funny bit is when I set the version manually it works:

    TOOLPATH=$$shell_path($$TOOLPATH/$$TOOLEXE)
    !build_pass:message("Path to tool: " $$TOOLPATH)
    # Invoke the tool for a version check.
    TOOLVER=$$system($$TOOLPATH --ver)
    TOOLVER=1.0.52
    !build_pass:message(Tool version is $$TOOLVER".")
    TOOLMINVER=1.0.52
    !versionAtLeast(TOOLVER, $$TOOLMINVER) {
    	message("Unsupported tool version " $${TOOLVER}".")
    	error("We require tool version "$$TOOLMINVER" or greater")
    }
    

    I tested every combination I could think of. It's always the same. Setting the version that is supposed to be returned from the external tool works. Using the result from the system() function doesn't.

    I also tried to squeeze in these lines

    #TOOLVER=$$val_escape(TOOLVER)
    #eval(TOOLVER="$$TOOLVER")
    

    in any combination possible since I suspected that the tool returns \n or \r as part of its output and maybe qmake isn't happy with this. Of course I've got to admit that the purpose of these functions isn't entirely clear to me.

    Maybe someone with a little bit more experience could have a quick look at those lines. What am I doing wrong?


  • Qt Champions 2018

    Hi @Padlock,

    I really think the system output contains some stray characters that makes the test fail.

    I've modified your example a bit and tried on Linux successfully:

    TOOLVER=$$system(echo 1.0.52)
    !build_pass:message("Tool version is $${TOOLVER}")
    TOOLMINVER=1.0.52
    !versionAtLeast(TOOLVER, $${TOOLMINVER}) {
        error("Unsupported tool version $${TOOLVER}, $${TOOLMINVER} or greater required.")
    } else {
        message("Tool version $${TOOLVER} supported!")
    }
    

    and that gives the expected output:

    12:19:07: Running steps for project VersionAtLeast...
    12:19:07: Starting: "/opt/Qt/5.12.0/gcc_64/bin/qmake" VersionAtLeast.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
    Project MESSAGE: Tool version is 1.0.52
    Project MESSAGE: Tool version 1.0.52 supported!
    12:19:07: The process "/opt/Qt/5.12.0/gcc_64/bin/qmake" exited normally.
    12:19:07: Elapsed time: 00:00.
    

    On Windows, you could try by replacing echo with cmd /c echo and see what that gives.

    Edit: And the negative test fails, as expected (leading to an error in Creators Build Issues!):

    12:21:46: Running steps for project VersionAtLeast...
    12:21:46: Starting: "/opt/Qt/5.12.0/gcc_64/bin/qmake" VersionAtLeast.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
    Project MESSAGE: Tool version is 1.0.51
    Project ERROR: Unsupported tool version 1.0.51, 1.0.52 or greater required.
    12:21:46: The process "/opt/Qt/5.12.0/gcc_64/bin/qmake" exited with code 3.
    Error while building/deploying project VersionAtLeast (kit: Desktop Qt 5.12.0 GCC 64bit)
    When executing step "qmake"
    12:21:46: Elapsed time: 00:00.
    


  • Thanks a lot!

    As expected, your changes didn't work here either but they gave me the clue I needed!

    I'm obtaining the path to the tool before that fragment, and all I had to do was enclose the code in a

    !build_pass {
    }
    

    block.

    !build_pass {
    	TOOLPATH=$$shell_path($$TOOLPATH/$$TOOLEXE)
    	message("Path to tool: " $$TOOLPATH)
    	# Invoke the tool for a version check.
    	TOOLVER=$$system($$TOOLPATH --ver)
    	message(Tool version is $$TOOLVER".")
    	TOOLMINVER=1.0.52
    	!versionAtLeast(TOOLVER, $${TOOLMINVER}) {
    		message("Unsupported tool version " $${TOOLVER}".")
    		error("We require tool version "$$TOOLMINVER" or greater")
    	}
    }
    

    This means at some point during the qmake process the path is computed incorrectly. The !build_pass block solved it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.