jurplel / install-qt-action

Install Qt on your Github Actions workflows with just one simple action
MIT License
459 stars 78 forks source link

Fix directory separators in environment variables on Windows #122

Closed ddalcino closed 2 years ago

ddalcino commented 2 years ago

This PR uses the Node standard library path module to convert paths into the native format on every platform.

This action sets several environment variables that include paths. On Windows, many of these paths include / instead of \, or use some mix of both:

Example from: https://github.com/jurplel/install-qt-action/runs/3916210538?check_suite_focus=true#step:7:10

  shell: C:\Windows\system32\cmd.EXE /D /E:ON /V:OFF /S /C "CALL "{0}""
  env:
    pythonLocation: C:\hostedtoolcache\windows\Python\3.10.0\x64
    IQTA_TOOLS: D:\a\install-qt-action/Qt/Tools
    Qt5_Dir: D:/a/install-qt-action/Qt/5.9/msvc2017_64
    QT_PLUGIN_PATH: D:/a/install-qt-action/Qt/5.9/msvc2017_64/plugins
    QML2_IMPORT_PATH: D:/a/install-qt-action/Qt/5.9/msvc2017_64/qml

On Windows, many programs are resilient to this kind of thing, but several are not. For instance, see the output of dir %Qt5_DIR%/lib/cmake in the same workflow: Invalid switch - "install-qt-action".. This happens because dir, like many Windows programs, interprets / as the beginning of a switch or flag, not as part of a directory separator.

You could fix this problem by surrounding paths with double-quotes, like this:

C:\> dir "%Qt5_DIR%/lib/cmake"

This change prevents potential issues on Windows by making sure all the environment variables use the correct path separators. You can see the effects on a successful Windows build here: https://github.com/ddalcino/install-qt-action/runs/3969848239?check_suite_focus=true#step:7:1 In this case, dir prints properly, and there are no error messages.