From 9b2bf17f3e34f8ff73f8fd492fe5212c8b9cbd9a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 27 Jan 2022 15:54:30 +0100 Subject: [PATCH] qmake: Print proper error if no .pro file could be detected When passing a directory to qmake, it tries to detect a .pro file in that directory. Whenever the detection failed, qmake printed an error message like "Access is denied." or "file to open is a directory". Now, qmake prints an actually helpful error message: ***Cannot detect .pro file in directory '../foo'. QMake expects the file '../foo/foo.pro' or exactly one .pro file in the given directory. Fixes: QTBUG-34673 Change-Id: I3d21ead247734172eee4eb68d3f9782d3ddaea52 Reviewed-by: Edward Welbourne Reviewed-by: Oliver Wolff --- qmake/option.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/qmake/option.cpp b/qmake/option.cpp index 72edf9c2713..99a8922cf6d 100644 --- a/qmake/option.cpp +++ b/qmake/option.cpp @@ -109,12 +109,15 @@ static Option::QMAKE_MODE default_mode(QString progname) return Option::QMAKE_GENERATE_MAKEFILE; } -static QString detectProjectFile(const QString &path) +static QString detectProjectFile(const QString &path, QString *singleProFileCandidate = nullptr) { QString ret; QDir dir(path); - if(dir.exists(dir.dirName() + Option::pro_ext)) { - ret = dir.filePath(dir.dirName()) + Option::pro_ext; + const QString candidate = dir.filePath(dir.dirName() + Option::pro_ext); + if (singleProFileCandidate) + *singleProFileCandidate = candidate; + if (QFile::exists(candidate)) { + ret = candidate; } else { //last try.. QStringList profiles = dir.entryList(QStringList("*" + Option::pro_ext)); if(profiles.count() == 1) @@ -287,11 +290,20 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state) if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL) { if(fi.isDir()) { - QString proj = detectProjectFile(arg); - if (!proj.isNull()) - arg = proj; + QString singleProFileCandidate; + QString proj = detectProjectFile(arg, &singleProFileCandidate); + if (proj.isNull()) { + fprintf(stderr, "***Cannot detect .pro file in directory '%s'.\n\n" + "QMake expects the file '%s' " + "or exactly one .pro file in the given directory.\n", + qUtf8Printable(arg), + qUtf8Printable(singleProFileCandidate)); + return Option::QMAKE_CMDLINE_ERROR; + } + Option::mkfile::project_files.append(proj); + } else { + Option::mkfile::project_files.append(arg); } - Option::mkfile::project_files.append(arg); } else if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) { Option::projfile::project_dirs.append(arg); } else {