Make architecture detection more robust.
authorGirish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Wed, 21 Mar 2012 04:01:20 +0000 (21:01 -0700)
committerQt by Nokia <qt-info@nokia.com>
Thu, 22 Mar 2012 19:59:27 +0000 (20:59 +0100)
Any message/error in mkspecs or qmake feature files ends up confusing
the current arch detection logic. Instead, search for
"Project MESSAGE: .* Architecture: <arch>".

Change-Id: I308932a5b75f3a1fcbc4fe30c74faf2e83b2d752
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
config.tests/arch/arch.cpp
config.tests/arch/arch.pro
configure
tools/configure/configureapp.cpp

index f942d0a..1a96fb9 100644 (file)
 #undef sparc
 #undef unknown
 #if defined(Q_PROCESSOR_ALPHA)
-alpha
+Architecture: alpha
 #elif defined(Q_PROCESSOR_ARM)
-arm
+Architecture: arm
 #elif defined(Q_PROCESSOR_AVR32)
-avr32
+Architecture: avr32
 #elif defined(Q_PROCESSOR_BLACKFIN)
-bfin
+Architecture: bfin
 #elif defined(Q_PROCESSOR_X86_32)
-i386
+Architecture: i386
 #elif defined(Q_PROCESSOR_X86_64)
-x86_64
+Architecture: x86_64
 #elif defined(Q_PROCESSOR_IA64)
-ia64
+Architecture: ia64
 #elif defined(Q_PROCESSOR_MIPS)
-mips
+Architecture: mips
 #elif defined(Q_PROCESSOR_POWER)
-power
+Architecture: power
 #elif defined(Q_PROCESSOR_S390)
-s390
+Architecture: s390
 #elif defined(Q_PROCESSOR_SH)
-sh
+Architecture: sh
 #elif defined(Q_PROCESSOR_SPARC)
-sparc
+Architecture: sparc
 #else
-unknown
+Architecture: unknown
 #endif
index 108f262..ea85a52 100644 (file)
@@ -1,7 +1,7 @@
 CONFIG -= qt debug_and_release
 # Detect target by preprocessing a file that uses Q_PROCESSOR_* macros from qprocessordetection.h
 COMMAND = $$QMAKE_CXX $$QMAKE_CXXFLAGS -E $$PWD/arch.cpp
-# 'false' as second argument to system() prevents qmake from stripping newlines
-COMPILER_ARCH = $$system($$COMMAND, false)
+# system function converts newline in output into spaces
+COMPILER_ARCH = $$system($$COMMAND)
 # Message back to configure so that it can set QT_ARCH and QT_HOST_ARCH
 message($$COMPILER_ARCH)
index 1d03e14..6b2cca4 100755 (executable)
--- a/configure
+++ b/configure
@@ -3933,11 +3933,12 @@ fi # Build qmake
 #-------------------------------------------------------------------------------
 
 # Use config.tests/arch/arch.pro to has the compiler tell us what the target architecture is
-CFG_ARCH=`"$outpath/bin/qmake" -spec "$XQMAKESPEC" -o /dev/null "$relpath/config.tests/arch/arch.pro" 2>&1 | sed -e "s,^Project MESSAGE: ,," -e "s,^#.*$,,g" | grep -v "^$"`
+CFG_ARCH=`"$outpath/bin/qmake" -spec "$XQMAKESPEC" -o /dev/null "$relpath/config.tests/arch/arch.pro" 2>&1 | sed -n -e 's,^Project MESSAGE:.*Architecture: \([a-zA-Z0-9]*\).*,\1,p'`
+
 [ -z "$CFG_ARCH" ] && CFG_ARCH="unknown"
 if [ "$QMAKESPEC" != "$XQMAKESPEC" ]; then
     # Do the same test again, using the host compiler
-    CFG_HOST_ARCH=`"$outpath/bin/qmake" -spec "$QMAKESPEC" -o /dev/null "$relpath/config.tests/arch/arch.pro" 2>&1 | sed -e "s,^Project MESSAGE: ,," -e "s,^#.*$,,g" | grep -v "^$"`
+    CFG_HOST_ARCH=`"$outpath/bin/qmake" -spec "$QMAKESPEC" -o /dev/null "$relpath/config.tests/arch/arch.pro" 2>&1 | sed -n -e 's,^Project MESSAGE:.*Architecture: \([a-zA-Z0-9]*\).*,\1,p'`
     [ -z "$CFG_HOST_ARCH" ] && CFG_HOST_ARCH="unknown"
 else
     # not cross compiling, host == target
index 0c9907f..58ffd28 100644 (file)
@@ -2584,32 +2584,9 @@ void Configure::detectArch()
         if (output.isEmpty())
             continue;
 
-        // strip everything up to and including 'Project MESSAGE: '
-        QString ProjectMESSAGE = QStringLiteral("Project MESSAGE: ");
-        int at = output.indexOf(ProjectMESSAGE);
-        if (at != -1)
-            output = output.mid(at + ProjectMESSAGE.length());
-
-        // strip lines beginning with a #
-        at = 0;
-        while ((at = output.indexOf('#', at)) != -1) {
-            if (at > 0 && output.at(at - 1) != '\n') {
-                // # isnt' at the beginning of a line, skip it
-                ++at;
-                continue;
-            }
-
-            int eol = output.indexOf('\n', at);
-            if (eol == -1) {
-                // end of string
-                output.remove(at, output.length() - at);
-                break;
-            }
-
-            output.remove(at, eol - at + 1);
-        }
-
-        dictionary[key] = output.simplified();
+        QRegExp re("Project MESSAGE:.*Architecture: ([a-zA-Z0-9]*)");
+        if (re.indexIn(output) != -1)
+            dictionary[key] = re.cap(1);
     }
 
     if (!dictionary.contains("QT_HOST_ARCH"))