@@ -26,16 +26,24 @@ using namespace nlohmann;
2626namespace fs = std::filesystem;
2727
2828fs::path findQmlImportScanner () {
29- auto path = which (" qmlimportscanner" );
30- if (path.empty ()) {
31- // at least on FreeBSD the qmlimportscanner binary is installed under
32- // QT_INSTALL_LIBEXECS for Qt 6 and QT_INSTALL_BINS for Qt5,
33- // so is not locatable via $PATH
34- auto qmakeVars = queryQmake (findQmake ());
35- path = which (qmakeVars[" QT_INSTALL_LIBEXECS" ] + " /qmlimportscanner" );
36- if (path.empty ())
37- path = which (qmakeVars[" QT_INSTALL_BINS" ] + " /qmlimportscanner" );
38- }
29+ // Calling plain which("qmlimportscanner") is problematic, because it
30+ // is symlinked to qtchooser on some distros. qtchooser's Qt6 support
31+ // is less than ideal, qmlimportscanner used to be in
32+ // /usr/lib/qt5/bin/qmlimportscanner, but it was moved to
33+ // /usr/lib/qt6/libexec/qmlimportscanner in Qt6. qtchooser is capable
34+ // of checking only a single directory for executables at a time,
35+ // and it usually checks the bin/ one, so qmlimportscanner cannot
36+ // be executed on Qt6 (if you are flabbergasted by this, remember that
37+ // current latest release of qtchooser, 66_3, doesn't even include a
38+ // qt6 config lookup file).
39+ // Either way, QT_INSTALL_LIBEXECS/QT_INSTALL_BINS lookup is the more
40+ // robust solution.
41+ auto qmakeVars = queryQmake (findQmake ());
42+ auto path = which (qmakeVars[" QT_INSTALL_LIBEXECS" ] + " /qmlimportscanner" );
43+ if (path.empty ())
44+ path = which (qmakeVars[" QT_INSTALL_BINS" ] + " /qmlimportscanner" );
45+ if (path.empty ())
46+ path = which (" qmlimportscanner" );
3947
4048 return path;
4149}
@@ -45,7 +53,7 @@ std::string runQmlImportScanner(const std::vector<std::filesystem::path> &source
4553
4654 if (qmlImportScannerPath.empty ()) {
4755 // TODO: come up with some more user friendly logging like it's done for qmake
48- throw std::runtime_error (" error: qmlimportscanner not found $ PATH" );
56+ throw std::runtime_error (" error: qmlimportscanner not found in Qt standard directories nor PATH" );
4957 }
5058
5159 std::vector<std::string> command{qmlImportScannerPath.string ()};
0 commit comments