From 1533bfc5fcc4ec5865c1de606504b6aba8a5f6fe Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Mar 2012 14:43:45 -0300 Subject: Improve the architecture-detection mechanism For the Unix part, this now obeys the -v option, printing the full command-line it used to compile, allowing testers to identify why something went wrong. Unfortunately, it requires a full compilation cycle, instead of just preprocessing. Just one more among the many on Unix, but maybe a noticeable slow-down on Windows. Change-Id: I654b70d99887e04c96731a5b91be9ad555e4d8fe Reviewed-by: Oswald Buddenhagen Reviewed-by: Girish Ramakrishnan --- tools/configure/configureapp.cpp | 47 +++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 050dd6b8e1..1059f0f83b 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -2561,16 +2561,47 @@ void Configure::detectArch() QString qmakespec = dictionary.value(pair.first); QString key = pair.second; + // run qmake QString command = - fixSeparators(QString("%1/bin/qmake.exe -spec %2 %3/config.tests/arch/arch.pro -o %4/Makefile.unused 2>&1") - .arg(buildPath, qmakespec, sourcePath, newpwd)); - QString output = Environment::execute(command); - if (output.isEmpty()) - continue; + fixSeparators(QString("%1/bin/qmake.exe -spec %2 %3/config.tests/arch/arch.pro 2>&1") + .arg(buildPath, qmakespec, sourcePath)); + Environment::execute(command); + + // compile + command = dictionary[ "MAKE" ]; + if (command.contains("nmake")) + command += " /NOLOGO"; + command += " -s"; + Environment::execute(command); + + // find the executable that was generated + QFile exe("arch.exe"); + if (!exe.open(QFile::ReadOnly)) { // no Text, this is binary + cout << "Could not find output file: " << qPrintable(exe.errorString()) << endl; + dictionary["DONE"] = "error"; + return; + } + QByteArray exeContents = exe.readAll(); + exe.close(); + + static const char magic[] = "==Qt=magic=Qt== Architecture:"; + int magicPos = exeContents.indexOf(magic); + if (magicPos == -1) { + cout << "Internal error, could not find the architecture of the executable" << endl; + dictionary["DONE"] = "error"; + return; + } + //cout << "Found magic at offset 0x" << hex << magicPos << endl; + + // the conversion from QByteArray will stop at the ending NUL anyway + QString arch = QString::fromLatin1(exeContents.constData() + magicPos + + sizeof(magic) - 1); + dictionary[key] = arch; + + //cout << "Detected arch '" << qPrintable(arch) << "'\n"; - QRegExp re("Project MESSAGE:.*Architecture: ([a-zA-Z0-9_]*)"); - if (re.indexIn(output) != -1) - dictionary[key] = re.cap(1); + // clean up + Environment::execute(command + " distclean"); } if (!dictionary.contains("QT_HOST_ARCH")) -- cgit v1.2.3