summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2018-04-03 13:39:42 +0200
committerTopi Reiniƶ <topi.reinio@qt.io>2018-04-05 11:56:09 +0000
commit61062f6769670b1a33c3f4406d51892c221a26fd (patch)
treea87748d0fecd7cce43b9574e614b5e9064fe8b68
parent944b0f8b7b4426471fb475bc9b98152d005b197b (diff)
downloadqttools-61062f6769670b1a33c3f4406d51892c221a26fd.tar.gz
qdoc: Query environment variables from qmake
If qgetenv() doesn't return a valid environment variable, try querying from qmake (assuming the variable name starts with 'Q'). This is useful for projects outside Qt, as it allows using e.g. QT_INSTALL_DOCS and QT_INSTALL_HEADERS. The former can be used for accessing the Qt documentation template, and the latter is useful for projects that need to pass Qt's include paths to Clang (which QDoc uses for parsing C++ documentation). The build system doesn't provide these paths when trying to build docs for a module that doesn't build on the host platform; for example, building Active Qt documentation on Linux. Change-Id: I758a5067d3dfdf13cadf979476323faea519ee40 Reviewed-by: Martin Smith <martin.smith@qt.io>
-rw-r--r--src/qdoc/config.cpp31
-rw-r--r--src/qdoc/config.h1
2 files changed, 30 insertions, 2 deletions
diff --git a/src/qdoc/config.cpp b/src/qdoc/config.cpp
index 64c8786f6..27018007b 100644
--- a/src/qdoc/config.cpp
+++ b/src/qdoc/config.cpp
@@ -39,6 +39,9 @@
#include "config.h"
#include "generator.h"
#include <stdlib.h>
+#if QT_CONFIG(process)
+#include "qprocess.h"
+#endif
QT_BEGIN_NAMESPACE
@@ -929,6 +932,30 @@ QStringList Config::loadMaster(const QString& fileName)
}
/*!
+ Returns the value of the environment variable \a varName.
+ If qgetenv() returns null and \a varName starts with 'Q',
+ try to query the variable from qmake.
+*/
+QByteArray Config::getEnv(const char *varName)
+{
+ QByteArray var = qgetenv(varName);
+#if QT_CONFIG(process)
+ if (var.isNull() && varName[0] == 'Q') {
+ QString path(QCoreApplication::applicationFilePath());
+ path.replace(path.lastIndexOf('/') + 1, prog.size(), "qmake");
+ QProcess qmake;
+ qmake.start(path, QStringList() << "-query" << varName);
+ if (qmake.waitForFinished()) {
+ QByteArray result = qmake.readAll().trimmed();
+ if (result.at(0) != '*')
+ var = result;
+ }
+ }
+#endif
+ return var;
+}
+
+/*!
Load, parse, and process a qdoc configuration file. This
function is only called by the other load() function, but
this one is recursive, i.e., it calls itself when it sees
@@ -1032,7 +1059,7 @@ void Config::load(Location location, const QString& fileName)
SKIP_CHAR();
}
if (!var.isEmpty()) {
- const QByteArray val = qgetenv(var.toLatin1().data());
+ const QByteArray val = getEnv(var.toLatin1().data());
if (val.isNull()) {
location.fatal(tr("Environment variable '%1' undefined").arg(var));
}
@@ -1140,7 +1167,7 @@ void Config::load(Location location, const QString& fileName)
SKIP_CHAR();
}
if (!var.isEmpty()) {
- const QByteArray val = qgetenv(var.toLatin1().constData());
+ const QByteArray val = getEnv(var.toLatin1().constData());
if (val.isNull()) {
location.fatal(tr("Environment variable '%1' undefined").arg(var));
}
diff --git a/src/qdoc/config.h b/src/qdoc/config.h
index 0de7076eb..ce705370b 100644
--- a/src/qdoc/config.h
+++ b/src/qdoc/config.h
@@ -102,6 +102,7 @@ public:
QString getIncludeFilePath(const QString& fileName) const;
QStringList getExampleQdocFiles(const QSet<QString> &excludedDirs, const QSet<QString> &excludedFiles);
QStringList getExampleImageFiles(const QSet<QString> &excludedDirs, const QSet<QString> &excludedFiles);
+ QByteArray getEnv(const char *varName);
static QStringList loadMaster(const QString& fileName);
static bool isFileExcluded(const QString &fileName, const QSet<QString> &excludedFiles);