From d4f1f4a56b87c5fee8d808705910f598b5670072 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 16 Nov 2012 11:38:32 +0100 Subject: qdoc: better copying of .css files This change ignores templatedir for css files. It assumes that the paths in the stylesheets variable are relative to the qdocconf file that contains the stylesheets variable. Task-number: QTBUG-27878 Change-Id: I2155e58f352e17d710c93ad4e92679beb169d823 Reviewed-by: Jerome Pasion --- src/tools/qdoc/config.cpp | 202 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 149 insertions(+), 53 deletions(-) (limited to 'src/tools/qdoc/config.cpp') diff --git a/src/tools/qdoc/config.cpp b/src/tools/qdoc/config.cpp index 89d4f1afe9..a378d19306 100644 --- a/src/tools/qdoc/config.cpp +++ b/src/tools/qdoc/config.cpp @@ -156,6 +156,7 @@ QString Config::installDir; QSet Config::overrideOutputFormats; QMap Config::extractedDirs; int Config::numInstances; +QStack Config::workingDirs_; /*! \class Config @@ -173,10 +174,10 @@ Config::Config(const QString& programName) : prog(programName) { loc = Location::null; - lastLoc = Location::null; + lastLocation_ = Location::null; locMap.clear(); - stringValueMap.clear(); - stringListValueMap.clear(); + stringPairMap.clear(); + stringListPairMap.clear(); numInstances++; } @@ -205,7 +206,7 @@ void Config::load(const QString& fileName) else { loc.setEtc(true); } - lastLoc = Location::null; + lastLocation_ = Location::null; } /*! @@ -214,9 +215,9 @@ void Config::load(const QString& fileName) */ void Config::unload(const QString& fileName) { - QStringMultiMap::ConstIterator v = stringValueMap.constBegin(); - while (v != stringValueMap.constEnd()) { - qDebug() << v.key() << " = " << v.value(); + QStringPairMap::ConstIterator v = stringPairMap.constBegin(); + while (v != stringPairMap.constEnd()) { + qDebug() << v.key() << " = " << v.value().second; ++v; } qDebug() << "fileName:" << fileName; @@ -231,8 +232,10 @@ void Config::unload(const QString& fileName) */ void Config::setStringList(const QString& var, const QStringList& values) { - stringValueMap[var] = values.join(QLatin1Char(' ')); - stringListValueMap[var] = values; + stringPairMap[var].first = QDir::currentPath(); + stringPairMap[var].second = values.join(QLatin1Char(' ')); + stringListPairMap[var].first = QDir::currentPath(); + stringListPairMap[var].second = values; } /*! @@ -292,16 +295,37 @@ QSet Config::getOutputFormats() const /*! First, this function looks up the configuration variable \a var in the location map and, if found, sets the internal variable - \c{lastLoc} to the Location that \a var maps to. + \c{lastLocation_} to the Location that \a var maps to. Then it looks up the configuration variable \a var in the string - map, and returns the string that \a var maps to. + map and returns the string that \a var maps to. */ QString Config::getString(const QString& var) const { if (!locMap[var].isEmpty()) - (Location&) lastLoc = locMap[var]; - return stringValueMap[var]; + (Location&) lastLocation_ = locMap[var]; + return stringPairMap[var].second; +} + +/*! + This function looks up the variable \a var in the location map + and, if found, sets the internal variable \c{lastLocation_} to the + location that \a var maps to. + + Then it looks up \a var in the configuration variable map and, + if found, constructs a path from the pair value, which consists + of the directory path of the configuration file where the value + came from, and the value itself. The constructed path is returned. + */ +QString Config::getPath(const QString& var) const +{ + if (!locMap[var].isEmpty()) + (Location&) lastLocation_ = locMap[var]; + QString path; + if (stringPairMap.contains(var)) { + path = QDir(stringPairMap[var].first + "/" + stringPairMap[var].second).absolutePath(); + } + return path; } /*! @@ -317,7 +341,7 @@ QSet Config::getStringSet(const QString& var) const /*! First, this function looks up the configuration variable \a var in the location map and, if found, sets the internal variable - \c{lastLoc} to the Location that \a var maps to. + \c{lastLocation_} to the Location that \a var maps to. Then it looks up the configuration variable \a var in the string list map, and returns the string list that \a var maps to. @@ -325,8 +349,8 @@ QSet Config::getStringSet(const QString& var) const QStringList Config::getStringList(const QString& var) const { if (!locMap[var].isEmpty()) - (Location&) lastLoc = locMap[var]; - return stringListValueMap[var]; + (Location&) lastLocation_ = locMap[var]; + return stringListPairMap[var].second; } @@ -339,11 +363,11 @@ QStringList Config::getStringList(const QString& var) const QStringList Config::getCanonicalRelativePathList(const QString& var) const { if (!locMap[var].isEmpty()) - (Location&) lastLoc = locMap[var]; + (Location&) lastLocation_ = locMap[var]; QStringList t; - QMap::const_iterator it = stringListValueMap.constFind(var); - if (it != stringListValueMap.constEnd()) { - const QStringList& sl = it.value(); + QStringListPairMap::const_iterator it = stringListPairMap.constFind(var); + if (it != stringListPairMap.constEnd()) { + const QStringList& sl = it.value().second; if (!sl.isEmpty()) { t.reserve(sl.size()); for (int i=0; i::const_iterator it = stringListValueMap.constFind(var); - if (it != stringListValueMap.constEnd()) { - const QStringList& sl = it.value(); + QStringListPairMap::const_iterator it = stringListPairMap.constFind(var); + if (it != stringListPairMap.constEnd()) { + const QStringList& sl = it.value().second; if (!sl.isEmpty()) { t.reserve(sl.size()); for (int i=0; i Config::subVars(const QString& var) const { QSet result; QString varDot = var + QLatin1Char('.'); - QStringMultiMap::ConstIterator v = stringValueMap.constBegin(); - while (v != stringValueMap.constEnd()) { + QStringPairMap::ConstIterator v = stringPairMap.constBegin(); + while (v != stringPairMap.constEnd()) { if (v.key().startsWith(varDot)) { QString subVar = v.key().mid(varDot.length()); int dot = subVar.indexOf(QLatin1Char('.')); @@ -462,11 +527,11 @@ QSet Config::subVars(const QString& var) const with the matching keys (stripped of the prefix \a var and mapped to their values. The pairs are inserted into \a t */ -void Config::subVarsAndValues(const QString& var, QStringMultiMap& t) const +void Config::subVarsAndValues(const QString& var, QStringPairMap& t) const { QString varDot = var + QLatin1Char('.'); - QStringMultiMap::ConstIterator v = stringValueMap.constBegin(); - while (v != stringValueMap.constEnd()) { + QStringPairMap::ConstIterator v = stringPairMap.constBegin(); + while (v != stringPairMap.constEnd()) { if (v.key().startsWith(varDot)) { QString subVar = v.key().mid(varDot.length()); int dot = subVar.indexOf(QLatin1Char('.')); @@ -550,10 +615,10 @@ QString Config::findFile(const Location& location, const QString& fileName, QString& userFriendlyFilePath) { - if (debug) - qDebug() << "FILES:" << files - << "DIRS:" << dirs - << "FILENAME:" << fileName; + if (debug) { + qDebug() << "FINDFILE DIRS:" << dirs; + qDebug() << "FINDFILE FILENAME:" << fileName; + } if (fileName.isEmpty() || fileName.startsWith(QLatin1Char('/'))) { userFriendlyFilePath = fileName; return fileName; @@ -637,10 +702,10 @@ QString Config::findFile(const Location& location, /*! Copies the \a sourceFilePath to the file name constructed by - concatenating \a targetDirPath and \a userFriendlySourceFilePath. - \a location is for identifying the file and line number where - a qdoc error occurred. The constructed output file name is - returned. + concatenating \a targetDirPath and the file name from the + \a userFriendlySourceFilePath. \a location is for identifying + the file and line number where a qdoc error occurred. The + constructed output file name is returned. */ QString Config::copyFile(const Location& location, const QString& sourceFilePath, @@ -649,8 +714,8 @@ QString Config::copyFile(const Location& location, { QFile inFile(sourceFilePath); if (!inFile.open(QFile::ReadOnly)) { - location.fatal(tr("Cannot open input file '%1': %2") - .arg(sourceFilePath).arg(inFile.errorString())); + location.warning(tr("Cannot open input file for copy: '%1': %2") + .arg(sourceFilePath).arg(inFile.errorString())); return QString(); } @@ -658,11 +723,14 @@ QString Config::copyFile(const Location& location, int slash = outFileName.lastIndexOf(QLatin1Char('/')); if (slash != -1) outFileName = outFileName.mid(slash); - - QFile outFile(targetDirPath + QLatin1Char('/') + outFileName); + if ((outFileName.size()) > 0 && (outFileName[0] != '/')) + outFileName = targetDirPath + QLatin1Char('/') + outFileName; + else + outFileName = targetDirPath + outFileName; + QFile outFile(outFileName); if (!outFile.open(QFile::WriteOnly)) { - location.fatal(tr("Cannot open output file '%1': %2") - .arg(outFile.fileName()).arg(outFile.errorString())); + location.warning(tr("Cannot open output file for copy: '%1': %2") + .arg(outFileName).arg(outFile.errorString())); return QString(); } @@ -745,6 +813,8 @@ bool Config::isMetaKeyChar(QChar ch) */ void Config::load(Location location, const QString& fileName) { + pushWorkingDir(QFileInfo(fileName).path()); + QDir::setCurrent(QFileInfo(fileName).path()); QRegExp keySyntax(QLatin1String("\\w+(?:\\.\\w+)*")); #define SKIP_CHAR() \ @@ -967,29 +1037,34 @@ void Config::load(Location location, const QString& fileName) else { locMap[*key].setEtc(true); } - if (stringValueMap[*key].isEmpty()) { - stringValueMap[*key] = stringValue; + if (stringPairMap[*key].second.isEmpty()) { + stringPairMap[*key].first = QDir::currentPath(); + stringPairMap[*key].second = stringValue; } else { - stringValueMap[*key] += - QLatin1Char(' ') + stringValue; + stringPairMap[*key].second += QLatin1Char(' ') + stringValue; } - stringListValueMap[*key] += stringListValue; + stringListPairMap[*key].first = QDir::currentPath(); + stringListPairMap[*key].second += stringListValue; } else { locMap[*key] = keyLoc; - stringValueMap[*key] = stringValue; - stringListValueMap[*key] = stringListValue; + stringPairMap[*key].first = QDir::currentPath(); + stringPairMap[*key].second = stringValue; + stringListPairMap[*key].first = QDir::currentPath(); + stringListPairMap[*key].second = stringListValue; } ++key; } } } else { - location.fatal(tr("Unexpected character '%1' at beginning of line") - .arg(c)); + location.fatal(tr("Unexpected character '%1' at beginning of line").arg(c)); } } + popWorkingDir(); + if (!workingDirs_.isEmpty()) + QDir::setCurrent(QFileInfo(workingDirs_.top()).path()); } QStringList Config::getFilesHere(const QString& uncleanDir, @@ -1035,4 +1110,25 @@ QStringList Config::getFilesHere(const QString& uncleanDir, return result; } +/*! + Push \a dir onto the stack of working directories. + */ +void Config::pushWorkingDir(const QString& dir) +{ + workingDirs_.push(dir); +} + +/*! + If the stack of working directories is not empty, pop the + top entry and return it. Otherwise return an empty string. + */ +QString Config::popWorkingDir() +{ + if (!workingDirs_.isEmpty()) { + return workingDirs_.pop(); + } + qDebug() << "RETURNED EMPTY WORKING DIR"; + return QString(); +} + QT_END_NAMESPACE -- cgit v1.2.3