Ejemplo n.º 1
0
/*!
  Processes the qdoc config file \a fileName. This is the
  controller for all of qdoc.
 */
static void processQdocconfFile(const QString &fileName)
{
#ifndef QT_NO_TRANSLATION
    QList<QTranslator *> translators;
#endif

    /*
      The Config instance represents the configuration data for qdoc.
      All the other classes are initialized with the config. Here we
      initialize the configuration with some default values.
     */
    Config config(tr("qdoc"));
    int i = 0;
    while (defaults[i].key) {
        config.setStringList(defaults[i].key, QStringList() << defaults[i].value);
        ++i;
    }
    config.setStringList(CONFIG_SYNTAXHIGHLIGHTING, QStringList(highlighting ? "true" : "false"));
    config.setStringList(CONFIG_SHOWINTERNAL, QStringList(showInternal ? "true" : "false"));
    config.setStringList(CONFIG_NOLINKERRORS, QStringList(noLinkErrors ? "true" : "false"));
    config.setStringList(CONFIG_OBSOLETELINKS, QStringList(obsoleteLinks ? "true" : "false"));

    /*
      If QT_INSTALL_DOCS is not set, set it here so it can be used from
      the qdocconf files.
    */
    QString qt_install_docs = qgetenv("QT_INSTALL_DOCS");
    if (qt_install_docs.isEmpty()) {
        documentationPath = QLibraryInfo::rawLocation(QLibraryInfo::DocumentationPath,
                                                      QLibraryInfo::EffectivePaths);
        qputenv("QT_INSTALL_DOCS", documentationPath.toLatin1());
    }

    /*
      With the default configuration values in place, load
      the qdoc configuration file. Note that the configuration
      file may include other configuration files.

      The Location class keeps track of the current location
      in the file being processed, mainly for error reporting
      purposes.
     */
    currentDir = QFileInfo(fileName).path();
    Location::initialize(config);
    config.load(fileName);

    /*
      Add the defines to the configuration variables.
     */
    QStringList defs = defines + config.getStringList(CONFIG_DEFINES);
    config.setStringList(CONFIG_DEFINES,defs);
    Location::terminate();

    prevCurrentDir = QDir::currentPath();
    currentDir = QFileInfo(fileName).path();
    if (!currentDir.isEmpty())
        QDir::setCurrent(currentDir);

    QString phase;
    if (Generator::runPrepareOnly())
        phase = " in -prepare mode ";
    else if (Generator::runGenerateOnly())
        phase = " in -generate mode ";
    QString msg = "Running qdoc for " + config.getString(CONFIG_PROJECT) + phase;
    Location::logToStdErr(msg);

    /*
      Initialize all the classes and data structures with the
      qdoc configuration.
     */
    Location::initialize(config);
    Tokenizer::initialize(config);
    Doc::initialize(config);
    CodeMarker::initialize(config);
    CodeParser::initialize(config);
    Generator::initialize(config);

#ifndef QT_NO_TRANSLATION
    /*
      Load the language translators, if the configuration specifies any.
     */
    QStringList fileNames = config.getStringList(CONFIG_TRANSLATORS);
    QStringList::Iterator fn = fileNames.constBegin();
    while (fn != fileNames.constEnd()) {
        QTranslator *translator = new QTranslator(0);
        if (!translator->load(*fn))
            config.lastLocation().error(tr("Cannot load translator '%1'").arg(*fn));
        QCoreApplication::instance()->installTranslator(translator);
        translators.append(translator);
        ++fn;
    }
#endif

    //QSet<QString> outputLanguages = config.getStringSet(CONFIG_OUTPUTLANGUAGES);

    /*
      Get the source language (Cpp) from the configuration
      and the location in the configuration file where the
      source language was set.
     */
    QString lang = config.getString(CONFIG_LANGUAGE);
    Location langLocation = config.lastLocation();

    /*
      Initialize the qdoc database, where all the parsed source files
      will be stored. The database includes a tree of nodes, which gets
      built as the source files are parsed. The documentation output is
      generated by traversing that tree.
     */
    QDocDatabase* qdb = QDocDatabase::qdocDB();
    qdb->setVersion(config.getString(CONFIG_VERSION));

    /*
      By default, the only output format is HTML.
     */
    QSet<QString> outputFormats = config.getOutputFormats();
    Location outputFormatsLocation = config.lastLocation();

    if (!Generator::runPrepareOnly())
        loadIndexFiles(config);

    QSet<QString> excludedDirs;
    QSet<QString> excludedFiles;
    QStringList headerList;
    QStringList sourceList;
    QStringList excludedDirsList;
    QStringList excludedFilesList;

    Generator::debugSegfault("Reading excludedirs");
    excludedDirsList = config.getCanonicalRelativePathList(CONFIG_EXCLUDEDIRS);
    foreach (const QString &excludeDir, excludedDirsList) {
        QString p = QDir::fromNativeSeparators(excludeDir);
        excludedDirs.insert(p);
    }
Ejemplo n.º 2
0
/*!
  Processes the qdoc config file \a fileName. This is the
  controller for all of qdoc.
 */
static void processQdocconfFile(const QString &fileName)
{
#ifndef QT_NO_TRANSLATION
    QList<QTranslator *> translators;
#endif

    /*
      The Config instance represents the configuration data for qdoc.
      All the other classes are initialized with the config. Here we
      initialize the configuration with some default values.
     */
    Config config(tr("qdoc"));
    int i = 0;
    while (defaults[i].key) {
        config.setStringList(defaults[i].key,
                             QStringList() << defaults[i].value);
        ++i;
    }
    config.setStringList(CONFIG_SYNTAXHIGHLIGHTING, QStringList(highlighting ? "true" : "false"));
    config.setStringList(CONFIG_SHOWINTERNAL, QStringList(showInternal ? "true" : "false"));
    config.setStringList(CONFIG_NOLINKERRORS, QStringList(noLinkErrors ? "true" : "false"));
    config.setStringList(CONFIG_OBSOLETELINKS, QStringList(obsoleteLinks ? "true" : "false"));

    QString documentationPath = QLibraryInfo::rawLocation(QLibraryInfo::DocumentationPath,
                                                          QLibraryInfo::EffectivePaths);

    // Set a few environment variables that can be used from the qdocconf file
    qputenv("QT_INSTALL_DOCS", documentationPath.toLatin1());

    /*
      With the default configuration values in place, load
      the qdoc configuration file. Note that the configuration
      file may include other configuration files.

      The Location class keeps track of the current location
      in the file being processed, mainly for error reporting
      purposes.
     */
    Location::initialize(config);
    config.load(fileName);

    /*
      Add the defines to the configuration variables.
     */
    QStringList defs = defines + config.getStringList(CONFIG_DEFINES);
    config.setStringList(CONFIG_DEFINES,defs);
    Location::terminate();

    QString prevCurrentDir = QDir::currentPath();
    QString dir = QFileInfo(fileName).path();
    if (!dir.isEmpty())
        QDir::setCurrent(dir);

    /*
      Initialize all the classes and data structures with the
      qdoc configuration.
     */
    Location::initialize(config);
    Tokenizer::initialize(config);
    Doc::initialize(config);
    CodeMarker::initialize(config);
    CodeParser::initialize(config);
    Generator::initialize(config);

#ifndef QT_NO_TRANSLATION
    /*
      Load the language translators, if the configuration specifies any.
     */
    QStringList fileNames = config.getStringList(CONFIG_TRANSLATORS);
    QStringList::Iterator fn = fileNames.constBegin();
    while (fn != fileNames.constEnd()) {
        QTranslator *translator = new QTranslator(0);
        if (!translator->load(*fn))
            config.lastLocation().error(tr("Cannot load translator '%1'")
                                        .arg(*fn));
        QCoreApplication::instance()->installTranslator(translator);
        translators.append(translator);
        ++fn;
    }
#endif

    //QSet<QString> outputLanguages = config.getStringSet(CONFIG_OUTPUTLANGUAGES);

    /*
      Get the source language (Cpp) from the configuration
      and the location in the configuration file where the
      source language was set.
     */
    QString lang = config.getString(CONFIG_LANGUAGE);
    Location langLocation = config.lastLocation();

    /*
      Initialize the qdoc database, where all the parsed source files
      will be stored. The database includes a tree of nodes, which gets
      built as the source files are parsed. The documentation output is
      generated by traversing that tree.
     */
    QDocDatabase* qdb = QDocDatabase::qdocDB();
    qdb->setVersion(config.getString(CONFIG_VERSION));

    /*
      By default, the only output format is HTML.
     */
    QSet<QString> outputFormats = config.getOutputFormats();
    Location outputFormatsLocation = config.lastLocation();

    /*
      Read some XML indexes containing definitions from other documentation sets.
     */
    QStringList indexFiles = config.getStringList(CONFIG_INDEXES);

    dependModules += config.getStringList(CONFIG_DEPENDS);

    // Allow modules and third-party application/libraries to link
    // to the Qt docs without having to explicitly pass --indexdir.
    if (!indexDirs.contains(documentationPath))
        indexDirs.append(documentationPath);

    if (dependModules.size() > 0) {
        if (indexDirs.size() > 0) {
            for (int i = 0; i < indexDirs.size(); i++) {
                if (indexDirs[i].startsWith("..")) {
                    const QString prefix(QDir(dir).relativeFilePath(prevCurrentDir));
                    if (!prefix.isEmpty())
                        indexDirs[i].prepend(prefix + QLatin1Char('/'));
                }
            }
            /*
                Add all subdirectories of the indexdirs as dependModules when an asterisk is used in
                the 'depends' list.
            */
            if (dependModules.contains("*")) {
                dependModules.removeOne("*");
                for (int i = 0; i < indexDirs.size(); i++) {
                    QDir scanDir = QDir(indexDirs[i]);
                    scanDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
                    QFileInfoList dirList = scanDir.entryInfoList();
                    for (int j = 0; j < dirList.size(); j++) {
                        if (dirList[j].fileName().toLower() != config.getString(CONFIG_PROJECT).toLower())
                            dependModules.append(dirList[j].fileName());
                    }
                }
            }
            for (int i = 0; i < dependModules.size(); i++) {
                QString indexToAdd;
                QList<QFileInfo> foundIndices;
                for (int j = 0; j < indexDirs.size(); j++) {
                    QString fileToLookFor = indexDirs[j] + QLatin1Char('/') + dependModules[i] +
                            QLatin1Char('/') + dependModules[i] + QLatin1String(".index");
                    if (QFile::exists(fileToLookFor)) {
                        QFileInfo tempFileInfo(fileToLookFor);
                        if (!foundIndices.contains(tempFileInfo))
                            foundIndices.append(tempFileInfo);
                    }
                }
                qSort(foundIndices.begin(), foundIndices.end(), creationTimeBefore);
                if (foundIndices.size() > 1) {
                    /*
                        QDoc should always use the last entry in the multimap when there are
                        multiple index files for a module, since the last modified file has the
                        highest UNIX timestamp.
                    */
                    qDebug() << "Multiple indices found for dependency:" << dependModules[i] << "\nFound:";
                    for (int k = 0; k < foundIndices.size(); k++)
                        qDebug() << foundIndices[k].absoluteFilePath();
                    qDebug() << "Using" << foundIndices[foundIndices.size() - 1].absoluteFilePath()
                            << "as index for" << dependModules[i];
                    indexToAdd = foundIndices[foundIndices.size() - 1].absoluteFilePath();
                }
                else if (foundIndices.size() == 1) {
                    indexToAdd = foundIndices[0].absoluteFilePath();
                }
                else {
                    qDebug() << "No indices for" << dependModules[i] <<
                                "could be found in the specified index directories.";
                }
                if (!indexToAdd.isEmpty() && !indexFiles.contains(indexToAdd))
                    indexFiles << indexToAdd;
            }
        }
        else {
            qDebug() << "Dependant modules specified, but no index directories or install directory were set."
                     << "There will probably be errors for missing links.";
        }
    }
    qdb->readIndexes(indexFiles);

    QSet<QString> excludedDirs;
    QSet<QString> excludedFiles;
    QStringList headerList;
    QStringList sourceList;
    QStringList excludedDirsList;
    QStringList excludedFilesList;

    Generator::debugSegfault("Reading excludedirs");
    excludedDirsList = config.getCanonicalRelativePathList(CONFIG_EXCLUDEDIRS);
    foreach (const QString &excludeDir, excludedDirsList) {
        QString p = QDir::fromNativeSeparators(excludeDir);
        excludedDirs.insert(p);
    }
Ejemplo n.º 3
0
static void loadIndexFiles(Config& config)
{
    QDocDatabase* qdb = QDocDatabase::qdocDB();
    /*
      Read some XML indexes containing definitions from other documentation sets.
     */
    QStringList indexFiles = config.getStringList(CONFIG_INDEXES);

    dependModules += config.getStringList(CONFIG_DEPENDS);

    // Allow modules and third-party application/libraries to link
    // to the Qt docs without having to explicitly pass --indexdir.
    if (!indexDirs.contains(documentationPath))
        indexDirs.append(documentationPath);

    if (dependModules.size() > 0) {
        if (indexDirs.size() > 0) {
            for (int i = 0; i < indexDirs.size(); i++) {
                if (indexDirs[i].startsWith("..")) {
                    const QString prefix(QDir(currentDir).relativeFilePath(prevCurrentDir));
                    if (!prefix.isEmpty())
                        indexDirs[i].prepend(prefix + QLatin1Char('/'));
                }
            }
            /*
              Add all subdirectories of the indexdirs as dependModules,
              when an asterisk is used in the 'depends' list.
            */
            if (dependModules.contains("*")) {
                dependModules.removeOne("*");
                for (int i = 0; i < indexDirs.size(); i++) {
                    QDir scanDir = QDir(indexDirs[i]);
                    scanDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
                    QFileInfoList dirList = scanDir.entryInfoList();
                    for (int j = 0; j < dirList.size(); j++) {
                        if (dirList[j].fileName().toLower() != config.getString(CONFIG_PROJECT).toLower())
                            dependModules.append(dirList[j].fileName());
                    }
                }
            }
            for (int i = 0; i < dependModules.size(); i++) {
                QString indexToAdd;
                QList<QFileInfo> foundIndices;
                for (int j = 0; j < indexDirs.size(); j++) {
                    QString fileToLookFor = indexDirs[j] + QLatin1Char('/') + dependModules[i] +
                            QLatin1Char('/') + dependModules[i] + QLatin1String(".index");
                    if (QFile::exists(fileToLookFor)) {
                        QFileInfo tempFileInfo(fileToLookFor);
                        if (!foundIndices.contains(tempFileInfo))
                            foundIndices.append(tempFileInfo);
                    }
                }
                qSort(foundIndices.begin(), foundIndices.end(), creationTimeBefore);
                if (foundIndices.size() > 1) {
                    /*
                        QDoc should always use the last entry in the multimap when there are
                        multiple index files for a module, since the last modified file has the
                        highest UNIX timestamp.
                    */
                    qDebug() << "Multiple indices found for dependency:" << dependModules[i] << "\nFound:";
                    for (int k = 0; k < foundIndices.size(); k++)
                        qDebug() << foundIndices[k].absoluteFilePath();
                    qDebug() << "Using" << foundIndices[foundIndices.size() - 1].absoluteFilePath()
                            << "as index for" << dependModules[i];
                    indexToAdd = foundIndices[foundIndices.size() - 1].absoluteFilePath();
                }
                else if (foundIndices.size() == 1) {
                    indexToAdd = foundIndices[0].absoluteFilePath();
                }
                if (!indexToAdd.isEmpty() && !indexFiles.contains(indexToAdd))
                    indexFiles << indexToAdd;
            }
        }
        else {
            qDebug() << "Dependant modules specified, but no index directories or "
                     << "install directory were set."
                     << "There will probably be errors for missing links.";
        }
    }
    qdb->readIndexes(indexFiles);
}