summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-18 11:44:03 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-18 13:25:55 +0000
commit30e4967e8985ad6e0d2414c5e4a1dea1f1f9f8f4 (patch)
tree9325ca81626f49627d4dfffc09b3f8bfd5c6f5c2 /src
parentd38722eff3c7b07a452e5ce97b01c4f31bcedfcd (diff)
Fix glitches in !include directive
Includes like <"foo.mk"> were not possible. Includes like "foo.mk" did not recursively search through parent makefiles directories. Change-Id: I20daccae52c5af83a98ec2b95522a4ac03a99ddd Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/jomlib/preprocessor.cpp73
-rw-r--r--src/jomlib/preprocessor.h1
2 files changed, 43 insertions, 31 deletions
diff --git a/src/jomlib/preprocessor.cpp b/src/jomlib/preprocessor.cpp
index 1bf0682..566c926 100644
--- a/src/jomlib/preprocessor.cpp
+++ b/src/jomlib/preprocessor.cpp
@@ -62,36 +62,6 @@ bool Preprocessor::openFile(const QString& fileName)
bool Preprocessor::internalOpenFile(QString fileName)
{
- if (fileName.startsWith(QLatin1Char('"')) && fileName.endsWith(QLatin1Char('"')))
- fileName = fileName.mid(1, fileName.length() - 2);
- else if (fileName.startsWith(QLatin1Char('<')) && fileName.endsWith(QLatin1Char('>'))) {
- fileName = fileName.mid(1, fileName.length() - 2);
- QString includeVar = m_macroTable->macroValue(QLatin1String("INCLUDE")).replace(QLatin1Char('\t'), QLatin1Char(' '));
- QStringList includeDirs = includeVar.split(QLatin1Char(';'), QString::SkipEmptyParts);
- QString fullFileName;
- foreach (const QString& includeDir, includeDirs) {
- fullFileName = includeDir + QDir::separator() + fileName;
- if (QFile::exists(fullFileName)) {
- fileName = fullFileName;
- break;
- }
- }
- } else {
- QString fullFileName = fileName;
- QStack<TextFile> tmpStack;
- while (m_fileStack.count() >= 1) {
- if (QFile::exists(fullFileName)) {
- fileName = fullFileName;
- break;
- }
- TextFile textFile = m_fileStack.pop();
- tmpStack.push(textFile);
- fullFileName = textFile.fileDirectory + QDir::separator() + fileName;
- }
- while (!tmpStack.isEmpty())
- m_fileStack.push(tmpStack.pop());
- }
-
// make file name absolute for safe cycle detection
const QString origFileName = fileName;
QFileInfo fileInfo(fileName);
@@ -227,7 +197,7 @@ bool Preprocessor::parsePreprocessingDirective(const QString& line)
} else if (directive == QLatin1String("MESSAGE")) {
puts(qPrintable(value));
} else if (directive == QLatin1String("INCLUDE")) {
- internalOpenFile(value);
+ internalOpenFile(findIncludeFile(value));
} else if (directive == QLatin1String("IF")) {
bool followElseBranch = evaluateExpression(value) == 0;
enterConditional(followElseBranch);
@@ -288,6 +258,47 @@ bool Preprocessor::parsePreprocessingDirective(const QString& line)
return true;
}
+QString Preprocessor::findIncludeFile(const QString &filePathToInclude)
+{
+ QString filePath = filePathToInclude;
+ bool angleBrackets = false;
+ if (filePath.startsWith(QLatin1Char('<')) && filePath.endsWith(QLatin1Char('>'))) {
+ angleBrackets = true;
+ filePath.chop(1);
+ filePath.remove(0, 1);
+ }
+ removeDoubleQuotes(filePath);
+
+ QFileInfo fi(filePath);
+ if (fi.exists())
+ return fi.absoluteFilePath();
+
+ // Search recursively through all directories of all parent makefiles.
+ for (QStack<TextFile>::const_iterator it = m_fileStack.constEnd();
+ it != m_fileStack.constBegin();) {
+ --it;
+ fi.setFile(it->fileDirectory + QLatin1Char('/') + filePath);
+ if (fi.exists())
+ return fi.absoluteFilePath();
+ }
+
+ if (angleBrackets) {
+ // Search through all directories in the INCLUDE macro.
+ const QString includeVar = m_macroTable->macroValue(QLatin1String("INCLUDE"))
+ .replace(QLatin1Char('\t'), QLatin1Char(' '));
+ const QStringList includeDirs = includeVar.split(QLatin1Char(';'), QString::SkipEmptyParts);
+ foreach (const QString& includeDir, includeDirs) {
+ fi.setFile(includeDir + QLatin1Char('/') + filePath);
+ if (fi.exists())
+ return fi.absoluteFilePath();
+ }
+ }
+
+ const QString msg = QLatin1String("File %1 cannot be found.");
+ error(msg.arg(filePathToInclude));
+ return QString();
+}
+
bool Preprocessor::isPreprocessingDirective(const QString& line, QString& directive, QString& value)
{
if (line.isEmpty())
diff --git a/src/jomlib/preprocessor.h b/src/jomlib/preprocessor.h
index bf6773a..c3974e7 100644
--- a/src/jomlib/preprocessor.h
+++ b/src/jomlib/preprocessor.h
@@ -55,6 +55,7 @@ private:
void basicReadLine(QString& line);
bool parseMacro(const QString& line);
bool parsePreprocessingDirective(const QString& line);
+ QString findIncludeFile(const QString &filePathToInclude);
bool isPreprocessingDirective(const QString& line, QString& directive, QString& value);
void skipUntilNextMatchingConditional();
void error(const QString& msg);