Fix "qmake -spec foo" call for cross builds

In a cross built Qt, for example Qt for Android, calling "qmake -spec
android-clang" led to an error message:
    "Could not find qmake spec '-qtconf'."

This happened, because:
- the qmake in Qt for Android is a wrapper script that calls
  "qmake -qtconf qt_target.conf -spec android-clang"
- the first stage of command line argument handling in qmake garbled the
  call to "qmake -spec -qtconf qt_target.conf android-clang"

We do not modify the order of arguments anymore.

Instead, we skip the "-qtconf <file>" arguments in the first argument
handling stage that is supposed to determine qmake's modus
operandi (like -project or -query).

In addition, we need to fix the assignment of
QLibraryInfoPrivate::qtconfManualPath which was only done if
QMakeGlobals::addCommandLineArguments returned ArgumentsOk. However,
this function returns ArgumentUnknown, if it encounters an argument it
cannot handle - like the project name.
Now, we assign QLibraryInfoPrivate::qtconfManualPath if there was no
error detected.

Document the return values of addCommandLineArguments.

This amends commit 661b586a69.

Pick-to: 6.1 6.0
Fixes: QTBUG-93079
Task-number: QTBUG-85136
Change-Id: I12ec25b17d64c00be2a3904b7c4a975b781500a0
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2021-04-23 15:42:15 +02:00
parent 6235893d54
commit 63a812b851
2 changed files with 19 additions and 12 deletions

View File

@ -103,6 +103,13 @@ QString QMakeGlobals::cleanSpec(QMakeCmdLineParserState &state, const QString &s
return ret; return ret;
} }
/*
* Return value meanings:
* ArgumentUnknown The argument at *pos was not handled by this function.
* Leave it to the caller to handle this argument.
* ArgumentMalformed There was an error detected.
* ArgumentsOk All arguments were known. There are no arguments left to handle.
*/
QMakeGlobals::ArgumentReturn QMakeGlobals::addCommandLineArguments( QMakeGlobals::ArgumentReturn QMakeGlobals::addCommandLineArguments(
QMakeCmdLineParserState &state, QStringList &args, int *pos) QMakeCmdLineParserState &state, QStringList &args, int *pos)
{ {

View File

@ -204,14 +204,13 @@ Option::parseCommandLine(QStringList &args, QMakeCmdLineParserState &state)
continue; continue;
default: default:
QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x); QMakeGlobals::ArgumentReturn cmdRet = globals->addCommandLineArguments(state, args, &x);
if (cmdRet == QMakeGlobals::ArgumentsOk) {
QLibraryInfoPrivate::qtconfManualPath = globals->qtconf;
break;
}
if (cmdRet == QMakeGlobals::ArgumentMalformed) { if (cmdRet == QMakeGlobals::ArgumentMalformed) {
fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1))); fprintf(stderr, "***Option %s requires a parameter\n", qPrintable(args.at(x - 1)));
return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR; return Option::QMAKE_CMDLINE_SHOW_USAGE | Option::QMAKE_CMDLINE_ERROR;
} }
QLibraryInfoPrivate::qtconfManualPath = globals->qtconf;
if (cmdRet == QMakeGlobals::ArgumentsOk)
break;
Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown); Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown);
QString arg = args.at(x); QString arg = args.at(x);
if (arg.startsWith(QLatin1Char('-'))) { if (arg.startsWith(QLatin1Char('-'))) {
@ -381,8 +380,9 @@ Option::init(int argc, char **argv)
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
args << QString::fromLocal8Bit(argv[i]); args << QString::fromLocal8Bit(argv[i]);
while (!args.isEmpty()) { qsizetype idx = 0;
QString opt = args.at(0); while (idx < args.size()) {
QString opt = args.at(idx);
if (opt == "-project") { if (opt == "-project") {
Option::recursive = true; Option::recursive = true;
Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT; Option::qmake_mode = Option::QMAKE_GENERATE_PROJECT;
@ -399,15 +399,15 @@ Option::init(int argc, char **argv)
} else if (opt == "-makefile") { } else if (opt == "-makefile") {
Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE; Option::qmake_mode = Option::QMAKE_GENERATE_MAKEFILE;
} else if (opt == "-qtconf") { } else if (opt == "-qtconf") {
if (args.length() >= 3) { // Skip "-qtconf <file>" and proceed.
// Move the argument following "-qtconf <file>" in front and check again. ++idx;
args.prepend(args.takeAt(2)); if (idx + 1 < args.length())
continue; ++idx;
} continue;
} else { } else {
break; break;
} }
args.takeFirst(); args.takeAt(idx);
break; break;
} }