diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-01-27 15:54:30 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2022-02-02 19:36:42 +0100 |
commit | 9b2bf17f3e34f8ff73f8fd492fe5212c8b9cbd9a (patch) | |
tree | d6b81e13cea279f532c49ca0bb2af7073eaac3b9 /qmake | |
parent | 747bca3d67b019d0a6a9ae3df8e6703463201fe4 (diff) |
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 <edward.welbourne@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r-- | qmake/option.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/qmake/option.cpp b/qmake/option.cpp index 72edf9c271..99a8922cf6 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 { |