Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122622

configure on Windows can't handle unquoted -DFOO=0 arguments

    XMLWordPrintable

Details

    • Windows
    • 0165a91bf (dev), 3d18b218d (6.7), 5e41dde4c (6.6), 4353a8e60 (tqtc/lts-6.5), 2c9664ca3 (dev), 29019c9ca (dev)

    Description

      It appears that the configure.bat script on windows can't properly handle -DFOO=<single-digit> assignments

      See the following outputs:

      ..\qtbase\configure -- -DFOO=0
      -- -DFOO= # this gets echoed for no reason
      'E:/dev/cmakes/cmake-3.28.3/bin/cmake.exe' '-DQT_INTERNAL_CALLED_FROM_CONFIGURE:BOOL=TRUE' '-G' 'Ninja' 'E:/dev/qt/src/qt6_alt/qtbase' # no -DFOO argument at all
      
      ..\qtbase\configure -- -DFOO=1
      'E:/dev/cmakes/cmake-3.28.3/bin/cmake.exe' '-DFOO=' '-DQT_INTERNAL_CALLED_FROM_CONFIGURE:BOOL=TRUE' '-G' 'Ninja' 'E:/dev/qt/src/qt6_alt/qtbase'
      # -DFOO= is missing its value
      
      # Same as -DFOO=0, it gets echoed, and no -DFOO argument at all
      ..\qtbase\configure -- -DFOO=2
      -- -DFOO=
      'E:/dev/cmakes/cmake-3.28.3/bin/cmake.exe' '-DQT_INTERNAL_CALLED_FROM_CONFIGURE:BOOL=TRUE' '-G' 'Ninja' 'E:/dev/qt/src/qt6_alt/qtbase'
      

      Same happens for -DFOO=3 up to -DFOO=9.
      -DFOO=10 works fine.

      It works fine for -DFOO=ON / -DFOO=OFF or -DFOO=<some_non_digit_value>.

      This happens starting with Qt 6.2, when we switched to passing the bat arguments to configure by first writing them into a file: https://codereview.qt-project.org/c/qt/qtbase/+/366271

      Specifically

      echo %*>config.opt.in
      

      My guess is that the echo command treats the equal sign in -DFOO=1 as a delimiter, but only sometimes. But it doesn't explain why some other equal assignments work fine, so this theory might be wrong.

      In Qt 5 we didn't have this problem presumably because we use the following construct:

      set ARGS=%*
      ...
      "%QTDIR%\bin\qmake.exe" "%TOPQTSRC%" -- %ARGS%
      

      ss64 says

      If you use %* to refer to all parameters, the value returned will include the delimiters.

      So I guess assigning '%*' to a variable ARGS and expanding %ARGS% to a command invocation, instead of echo-ing preserves the values.

      At least
      https://ss64.com/nt/syntax-esc.html
      and
      https://stackoverflow.com/questions/20572424/preserving-equal-characters-in-batch-file-parameters
      claim that it's not really possible to preserve the exact arguments that contain '=' when echoing, unless they are quoted, but again, i might be wrong. At least i haven't found a solution yet.

      Finally, the correct quoting necessary is different when calling configure.bat in cmd.exe vs powershell.

      In cmd.exe you need to use

      ..\qtbase\configure -- "-DFOO=2"
      

      in powershell you need to use

      ..\qtbase\configure -- '"-DFOO=2"'
      

      the single quotes are for powershell to keep the literal double quotes, so they get passed along to the bat processor.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-122622
          # Subject Branch Project Status CR V

          Activity

            People

              alexandru.croitor Alexandru Croitor
              alexandru.croitor Alexandru Croitor
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes