diff options
| author | Joerg Bornemann <joerg.bornemann@qt.io> | 2025-12-03 17:19:36 +0100 |
|---|---|---|
| committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2025-12-05 09:33:24 +0000 |
| commit | 0213275ac075b8684eb518e584379dfbdc6b2b79 (patch) | |
| tree | 09fb5cbf80faa023970e626ff64098ffc37abe26 | |
| parent | 15a734c8dce3ae7db57a956c54e77340bf3bfdec (diff) | |
Preprocessor conditionals like
!if condition1
...
!else if condition2
...
!else
...
!endif
Were not recognized.
Now, we handle "!else if" as "!elseif". Same for !elseifdef and
!elseifndef.
Fixes: QTCREATORBUG-32129
Change-Id: I2e5e22deeec18650aed245fd32c16bbc6025fc10
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
| -rw-r--r-- | changelog.txt | 1 | ||||
| -rw-r--r-- | src/jomlib/preprocessor.cpp | 10 | ||||
| -rw-r--r-- | tests/makefiles/conditionals.mk | 28 | ||||
| -rw-r--r-- | tests/tests.cpp | 3 |
4 files changed, 42 insertions, 0 deletions
diff --git a/changelog.txt b/changelog.txt index f53e009..951e3a1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ This is the changelog for jom 1.1.5, the parallel make tool. Changes since jom 1.1.4 - Fixed compound defined() preprocessor expressions (QTCREATORBUG-24134). - A leading hyphen in MAKEFLAGS is now ignored. +- Fixed !else if preprocessor expressions (QTCREATORBUG-32129). Changes since jom 1.1.3 - Fixed handling of the command line option /j. diff --git a/src/jomlib/preprocessor.cpp b/src/jomlib/preprocessor.cpp index 97c28c2..b0e001c 100644 --- a/src/jomlib/preprocessor.cpp +++ b/src/jomlib/preprocessor.cpp @@ -392,6 +392,16 @@ bool Preprocessor::isPreprocessingDirective(const QString& line, QString& direct if (result) { directive = m_rexPreprocessingDirective.cap(1).toUpper(); value = m_rexPreprocessingDirective.cap(2).trimmed(); + + // Handle "!else if", "!else ifdef", "!else ifndef" as "!ELSEIF" etc. + if (directive == QLatin1String("ELSE")) { + static const QRegExp rex(QLatin1String("^(ifn?def|if)\\s+(.*)$"), + Qt::CaseInsensitive); + if (rex.exactMatch(value)) { + directive.append(rex.cap(1).toUpper()); + value = rex.cap(2); + } + } } } diff --git a/tests/makefiles/conditionals.mk b/tests/makefiles/conditionals.mk index a783e60..aecd32a 100644 --- a/tests/makefiles/conditionals.mk +++ b/tests/makefiles/conditionals.mk @@ -93,5 +93,33 @@ boo \ hoo !ENDIF +# Test !else if syntax (alternative to !elseif with space) +TEST11=false +!if "A" == "B" +TEST11=false +!else if "A"=="A" +TEST11=true +!else +TEST11=false +!endif + +TEST12=false +!ifdef NOT_DEFINED +TEST12=false +!else ifdef TEST1 +TEST12=true +!else +TEST12=false +!endif + +TEST13=false +!ifdef NOT_DEFINED +TEST13=false +!else ifndef NOT_DEFINED +TEST13=true +!else +TEST13=false +!endif + all: diff --git a/tests/tests.cpp b/tests/tests.cpp index 21e1df6..f1c3fe3 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -333,6 +333,9 @@ void Tests::conditionals() QCOMPARE(macroTable->macroValue("TEST8"), QLatin1String("true")); QCOMPARE(macroTable->macroValue("TEST9"), QLatin1String("foo bar baz")); QCOMPARE(macroTable->macroValue("TEST10"), QLatin1String("foo bar boo hoo")); + QCOMPARE(macroTable->macroValue("TEST11"), QLatin1String("true")); + QCOMPARE(macroTable->macroValue("TEST12"), QLatin1String("true")); + QCOMPARE(macroTable->macroValue("TEST13"), QLatin1String("true")); } void Tests::dotDirectives() |
