qdoc: Improve handling of current working directory

When qdoc reads (potentially nested) documentation files, it sets
the current working directory to the path of the currently read
file to make relative paths work for include statements and
config variables. This works as long as there's only one top-level
.qdocconf file.

This change fixes problems with handling the CWD to enable
relative paths also when we have multiple top-level .qdocconf
files, as is the case when running qdoc in single-exec mode.

Change-Id: I03a7ec5af93d54070ea29f90ea2ba29c57028781
Reviewed-by: Venugopal Shivashankar <venugopal.shivashankar@digia.com>
Reviewed-by: Martin Smith <martin.smith@digia.com>
bb10
Topi Reinio 2015-02-17 13:22:53 +01:00 committed by Topi Reiniö
parent 3146dadb42
commit 4fd8513475
2 changed files with 8 additions and 6 deletions

View File

@ -912,8 +912,10 @@ QStringList Config::loadMaster(const QString& fileName)
*/
void Config::load(Location location, const QString& fileName)
{
pushWorkingDir(QFileInfo(fileName).path());
QDir::setCurrent(QFileInfo(fileName).path());
QFileInfo fileInfo(fileName);
QString path = fileInfo.canonicalPath();
pushWorkingDir(path);
QDir::setCurrent(path);
QRegExp keySyntax(QLatin1String("\\w+(?:\\.\\w+)*"));
#define SKIP_CHAR() \
@ -935,7 +937,7 @@ void Config::load(Location location, const QString& fileName)
if (location.depth() > 16)
location.fatal(tr("Too many nested includes"));
QFile fin(fileName);
QFile fin(fileInfo.fileName());
if (!fin.open(QFile::ReadOnly | QFile::Text)) {
if (!Config::installDir.isEmpty()) {
int prefix = location.filePath().length() - location.fileName().length();
@ -1030,7 +1032,7 @@ void Config::load(Location location, const QString& fileName)
/*
Here is the recursive call.
*/
load(location, QFileInfo(QFileInfo(fileName).dir(), includeFile).filePath());
load(location, QFileInfo(QDir(path), includeFile).filePath());
}
else {
/*

View File

@ -227,6 +227,8 @@ static void processQdocconfFile(const QString &fileName)
config.setStringList(CONFIG_AUTOLINKERRORS, QStringList(autolinkErrors ? "true" : "false"));
config.setStringList(CONFIG_OBSOLETELINKS, QStringList(obsoleteLinks ? "true" : "false"));
prevCurrentDir = QDir::currentPath();
/*
With the default configuration values in place, load
the qdoc configuration file. Note that the configuration
@ -236,7 +238,6 @@ static void processQdocconfFile(const QString &fileName)
in the file being processed, mainly for error reporting
purposes.
*/
currentDir = QFileInfo(fileName).path();
Location::initialize(config);
config.load(fileName);
QString project = config.getString(CONFIG_PROJECT);
@ -248,7 +249,6 @@ static void processQdocconfFile(const QString &fileName)
config.setStringList(CONFIG_DEFINES,defs);
Location::terminate();
prevCurrentDir = QDir::currentPath();
currentDir = QFileInfo(fileName).path();
if (!currentDir.isEmpty())
QDir::setCurrent(currentDir);