qdoc: Simplify config code for reading file paths
This change greatly simplifies the code used for reading paths from config files: near-identical functions Config::getCanonicalPathList() and Config::getPathList() are combined into one, and the use of Config::getCleanPathList() is replaced with the above. Effectively, all paths read from the config files are now converted into canonical ones. It also adds support for absolute paths in config files. Task-number: QTBUG-36193 Change-Id: I2dc1ee6a67a400e056404ec1c09c6e81f643aa77 Reviewed-by: Martin Smith <martin.smith@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>bb10
parent
2e44a9e491
commit
9e44204bf8
|
|
@ -454,12 +454,21 @@ QStringList Config::getStringList(const QString& var) const
|
|||
}
|
||||
|
||||
/*!
|
||||
\brief Returns the a path list where all paths are canonicalized, then
|
||||
made relative to the config file.
|
||||
\param var The variable containing the list of paths.
|
||||
\see Location::canonicalRelativePath()
|
||||
Returns the a path list where all paths from the config variable \a var
|
||||
are canonicalized. If \a validate is true, a warning for invalid paths is
|
||||
generated.
|
||||
|
||||
First, this function looks up the configuration variable \a var
|
||||
in the location map and, if found, sets the internal variable
|
||||
\c{lastLocation_} the Location that \a var maps to.
|
||||
|
||||
Then it looks up the configuration variable \a var in the string
|
||||
list map, which maps to one or more records that each contains a
|
||||
list of file paths.
|
||||
|
||||
\sa Location::canonicalRelativePath()
|
||||
*/
|
||||
QStringList Config::getCanonicalPathList(const QString& var) const
|
||||
QStringList Config::getCanonicalPathList(const QString& var, bool validate) const
|
||||
{
|
||||
QStringList t;
|
||||
QList<ConfigVar> configVars = configVars_.values(var);
|
||||
|
|
@ -476,88 +485,14 @@ QStringList Config::getCanonicalPathList(const QString& var) const
|
|||
if (!sl.isEmpty()) {
|
||||
t.reserve(t.size() + sl.size());
|
||||
for (int i=0; i<sl.size(); ++i) {
|
||||
QDir dir(d + "/" + sl[i]);
|
||||
t.append(dir.canonicalPath());
|
||||
}
|
||||
}
|
||||
--i;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/*!
|
||||
This function should only be called when the configuration
|
||||
variable \a var maps to string lists that contain file paths.
|
||||
It cleans the paths with QDir::cleanPath() before returning
|
||||
them.
|
||||
*/
|
||||
QStringList Config::getCleanPathList(const QString& var) const
|
||||
{
|
||||
QStringList t;
|
||||
QList<ConfigVar> configVars = configVars_.values(var);
|
||||
if (!configVars.empty()) {
|
||||
int i = configVars.size() - 1;
|
||||
while (i >= 0) {
|
||||
const ConfigVar& cv = configVars[i];
|
||||
if (!cv.plus_)
|
||||
t.clear();
|
||||
if (!cv.location_.isEmpty())
|
||||
(Location&) lastLocation_ = cv.location_;
|
||||
const QStringList& sl = cv.values_;
|
||||
if (!sl.isEmpty()) {
|
||||
t.reserve(t.size() + sl.size());
|
||||
for (int i=0; i<sl.size(); ++i) {
|
||||
t.append(QDir::cleanPath(sl[i].simplified()));
|
||||
}
|
||||
}
|
||||
--i;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/*!
|
||||
This function should only be called when the configuration
|
||||
variable \a var maps to string lists that contain file paths.
|
||||
It cleans the paths with QDir::cleanPath() before returning
|
||||
them.
|
||||
|
||||
First, this function looks up the configuration variable \a var
|
||||
in the location map and, if found, sets the internal variable
|
||||
\c{lastLocation_} the Location that \a var maps to.
|
||||
|
||||
Then it looks up the configuration variable \a var in the string
|
||||
list map, which maps to one or more records that each contains a
|
||||
list of file paths.
|
||||
|
||||
These paths might not be clean, so QDir::cleanPath() is called
|
||||
for each one. The string list returned contains cleaned paths.
|
||||
*/
|
||||
QStringList Config::getPathList(const QString& var) const
|
||||
{
|
||||
QStringList t;
|
||||
QList<ConfigVar> configVars = configVars_.values(var);
|
||||
if (!configVars.empty()) {
|
||||
int i = configVars.size() - 1;
|
||||
while (i >= 0) {
|
||||
const ConfigVar& cv = configVars[i];
|
||||
if (!cv.plus_)
|
||||
t.clear();
|
||||
if (!cv.location_.isEmpty())
|
||||
(Location&) lastLocation_ = cv.location_;
|
||||
const QString d = cv.currentPath_;
|
||||
const QStringList& sl = cv.values_;
|
||||
if (!sl.isEmpty()) {
|
||||
t.reserve(t.size() + sl.size());
|
||||
for (int i=0; i<sl.size(); ++i) {
|
||||
QFileInfo fileInfo;
|
||||
QString path = d + "/" + QDir::cleanPath(sl[i].simplified());
|
||||
fileInfo.setFile(path);
|
||||
if (!fileInfo.exists())
|
||||
lastLocation_.warning(tr("File '%1' does not exist").arg(path));
|
||||
QDir dir(sl[i].simplified());
|
||||
QString path = dir.path();
|
||||
if (dir.isRelative())
|
||||
dir.setPath(d + "/" + path);
|
||||
if (validate && !QFileInfo::exists(dir.path()))
|
||||
lastLocation_.warning(tr("Cannot find file or directory: %1").arg(path));
|
||||
else
|
||||
t.append(path);
|
||||
t.append(dir.canonicalPath());
|
||||
}
|
||||
}
|
||||
--i;
|
||||
|
|
@ -566,7 +501,6 @@ QStringList Config::getPathList(const QString& var) const
|
|||
return t;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Calls getRegExpList() with the control variable \a var and
|
||||
iterates through the resulting list of regular expressions,
|
||||
|
|
|
|||
|
|
@ -103,9 +103,7 @@ public:
|
|||
QString getString(const QString& var) const;
|
||||
QSet<QString> getStringSet(const QString& var) const;
|
||||
QStringList getStringList(const QString& var) const;
|
||||
QStringList getCanonicalPathList(const QString& var) const;
|
||||
QStringList getCleanPathList(const QString& var) const;
|
||||
QStringList getPathList(const QString& var) const;
|
||||
QStringList getCanonicalPathList(const QString& var, bool validate = false) const;
|
||||
QRegExp getRegExp(const QString& var) const;
|
||||
QList<QRegExp> getRegExpList(const QString& var) const;
|
||||
QSet<QString> subVars(const QString& var) const;
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@ void CppCodeParser::initializeParser(const Config &config)
|
|||
nodeTypeMap.insert(COMMAND_PROPERTY, Node::Property);
|
||||
nodeTypeMap.insert(COMMAND_VARIABLE, Node::Variable);
|
||||
|
||||
exampleFiles = config.getCleanPathList(CONFIG_EXAMPLES);
|
||||
exampleDirs = config.getCleanPathList(CONFIG_EXAMPLEDIRS);
|
||||
exampleFiles = config.getCanonicalPathList(CONFIG_EXAMPLES);
|
||||
exampleDirs = config.getCanonicalPathList(CONFIG_EXAMPLEDIRS);
|
||||
QStringList exampleFilePatterns = config.getStringList(
|
||||
CONFIG_EXAMPLES + Config::dot + CONFIG_FILEEXTENSIONS);
|
||||
|
||||
|
|
|
|||
|
|
@ -3054,10 +3054,10 @@ const Config* Doc::config_ = 0;
|
|||
void Doc::initialize(const Config& config)
|
||||
{
|
||||
DocParser::tabSize = config.getInt(CONFIG_TABSIZE);
|
||||
DocParser::exampleFiles = config.getCleanPathList(CONFIG_EXAMPLES);
|
||||
DocParser::exampleDirs = config.getCleanPathList(CONFIG_EXAMPLEDIRS);
|
||||
DocParser::sourceFiles = config.getCleanPathList(CONFIG_SOURCES);
|
||||
DocParser::sourceDirs = config.getCleanPathList(CONFIG_SOURCEDIRS);
|
||||
DocParser::exampleFiles = config.getCanonicalPathList(CONFIG_EXAMPLES);
|
||||
DocParser::exampleDirs = config.getCanonicalPathList(CONFIG_EXAMPLEDIRS);
|
||||
DocParser::sourceFiles = config.getCanonicalPathList(CONFIG_SOURCES);
|
||||
DocParser::sourceDirs = config.getCanonicalPathList(CONFIG_SOURCEDIRS);
|
||||
DocParser::quoting = config.getBool(CONFIG_QUOTINGINFORMATION);
|
||||
|
||||
QmlClassNode::qmlOnly = config.getBool(CONFIG_QMLONLY);
|
||||
|
|
|
|||
|
|
@ -1585,13 +1585,13 @@ void Generator::initialize(const Config &config)
|
|||
config.lastLocation().fatal(tr("Cannot create style directory '%1'").arg(outDir_ + "/style"));
|
||||
}
|
||||
|
||||
imageFiles = config.getCleanPathList(CONFIG_IMAGES);
|
||||
imageDirs = config.getCleanPathList(CONFIG_IMAGEDIRS);
|
||||
scriptFiles = config.getCleanPathList(CONFIG_SCRIPTS);
|
||||
scriptDirs = config.getCleanPathList(CONFIG_SCRIPTDIRS);
|
||||
styleFiles = config.getCleanPathList(CONFIG_STYLES);
|
||||
styleDirs = config.getCleanPathList(CONFIG_STYLEDIRS);
|
||||
exampleDirs = config.getCleanPathList(CONFIG_EXAMPLEDIRS);
|
||||
imageFiles = config.getCanonicalPathList(CONFIG_IMAGES);
|
||||
imageDirs = config.getCanonicalPathList(CONFIG_IMAGEDIRS);
|
||||
scriptFiles = config.getCanonicalPathList(CONFIG_SCRIPTS);
|
||||
scriptDirs = config.getCanonicalPathList(CONFIG_SCRIPTDIRS);
|
||||
styleFiles = config.getCanonicalPathList(CONFIG_STYLES);
|
||||
styleDirs = config.getCanonicalPathList(CONFIG_STYLEDIRS);
|
||||
exampleDirs = config.getCanonicalPathList(CONFIG_EXAMPLEDIRS);
|
||||
exampleImgExts = config.getStringList(CONFIG_EXAMPLES + Config::dot + CONFIG_IMAGEEXTENSIONS);
|
||||
|
||||
QString imagesDotFileExtensions = CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS;
|
||||
|
|
@ -1607,9 +1607,9 @@ void Generator::initialize(const Config &config)
|
|||
if (outputFormats.contains((*g)->format())) {
|
||||
currentGenerator_ = (*g);
|
||||
(*g)->initializeGenerator(config);
|
||||
QStringList extraImages = config.getPathList((*g)->format() +
|
||||
QStringList extraImages = config.getCanonicalPathList((*g)->format() +
|
||||
Config::dot +
|
||||
CONFIG_EXTRAIMAGES);
|
||||
CONFIG_EXTRAIMAGES, true);
|
||||
QStringList::ConstIterator e = extraImages.constBegin();
|
||||
while (e != extraImages.constEnd()) {
|
||||
QString filePath = *e;
|
||||
|
|
@ -1620,7 +1620,7 @@ void Generator::initialize(const Config &config)
|
|||
}
|
||||
|
||||
// Documentation template handling
|
||||
QStringList scripts = config.getPathList((*g)->format()+Config::dot+CONFIG_SCRIPTS);
|
||||
QStringList scripts = config.getCanonicalPathList((*g)->format()+Config::dot+CONFIG_SCRIPTS, true);
|
||||
e = scripts.constBegin();
|
||||
while (e != scripts.constEnd()) {
|
||||
QString filePath = *e;
|
||||
|
|
@ -1630,7 +1630,7 @@ void Generator::initialize(const Config &config)
|
|||
++e;
|
||||
}
|
||||
|
||||
QStringList styles = config.getPathList((*g)->format()+Config::dot+CONFIG_STYLESHEETS);
|
||||
QStringList styles = config.getCanonicalPathList((*g)->format()+Config::dot+CONFIG_STYLESHEETS, true);
|
||||
e = styles.constBegin();
|
||||
while (e != styles.constEnd()) {
|
||||
QString filePath = *e;
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ static void processQdocconfFile(const QString &fileName)
|
|||
}
|
||||
|
||||
Generator::debug("Reading excludefiles");
|
||||
excludedFilesList = config.getCleanPathList(CONFIG_EXCLUDEFILES);
|
||||
excludedFilesList = config.getCanonicalPathList(CONFIG_EXCLUDEFILES);
|
||||
foreach (const QString& excludeFile, excludedFilesList) {
|
||||
QString p = QDir::fromNativeSeparators(excludeFile);
|
||||
excludedFiles.insert(p);
|
||||
|
|
|
|||
Loading…
Reference in New Issue