From 02ccb3291bd1053df30600211b0ceefbb7fea00f Mon Sep 17 00:00:00 2001 From: Eric NOULARD Date: Sat, 4 Feb 2012 12:15:57 +0100 Subject: Create getDocumentedModulesListInDir which may be used in other context. This should makes it easier to use the same "documented module" techniques for CTest, CMake or user module. --- Source/CPack/cpack.cxx | 67 +++++++++------------------------------------- Source/cmDocumentation.cxx | 55 +++++++++++++++++++++++++++++++++++++ Source/cmDocumentation.h | 33 ++++++++++++++++++++++- 3 files changed, 99 insertions(+), 56 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 25a72fa..3182915 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -26,7 +26,6 @@ #include "cmCPackLog.h" #include -#include #include #include // auto_ptr @@ -527,68 +526,26 @@ int main (int argc, char *argv[]) std::vector commands; - typedef std::pair docModuleSectionPair_t; - typedef std::list docedModulesList_t; - docedModulesList_t docedModList; - docModuleSectionPair_t docPair; - std::string docedFile; + std::string docedFile; + std::string docPath; + cmDocumentation::documentedModulesList_t docedModList; - cmsys::Glob gl; - std::string findExpr; - std::vector files; - std::string line; docedFile = globalMF->GetModulesFile("CPack.cmake"); if (docedFile.length()!=0) { - findExpr += cmSystemTools::GetFilenamePath(docedFile.c_str()); - findExpr += "/CPack*.cmake"; - if (gl.FindFiles(findExpr)) - { - files = gl.GetFiles(); - for (std::vector::iterator itf=files.begin(); - itf!=files.end();++itf) - { - std::ifstream fin((*itf).c_str()); - if (!fin) continue; - if (cmSystemTools::GetLineFromStream(fin, line)) - { - if (line.find("##section")!=std::string::npos) - { - docPair.first = cmSystemTools::GetFilenameName(*itf); - // 10 is the size of '##section' + 1 - docPair.second = line.substr(10,std::string::npos); - docedModList.push_back(docPair); - } - } - else - { - line.clear(); - } - } - } - else - { - // build the list of files to be parsed for documentation - // extraction - docPair.first = "CPack.cmake"; - docPair.second = "Variables common to all CPack generators"; - docedModList.push_back(docPair); - docPair.first = "CPackComponent.cmake"; - docedModList.push_back(docPair); - } + docPath = cmSystemTools::GetFilenamePath(docedFile.c_str()); + doc.getDocumentedModulesListInDir(docPath,"CPack*.cmake",docedModList); } // parse the files for documentation. - for (docedModulesList_t::iterator it = docedModList.begin(); - it!= docedModList.end(); ++it) + cmDocumentation::documentedModulesList_t::iterator docedIt; + for (docedIt = docedModList.begin(); + docedIt!= docedModList.end(); ++docedIt) { - docedFile = globalMF->GetModulesFile((it->first).c_str()); - if (docedFile.length()!=0) - { - doc.GetStructuredDocFromFile(docedFile.c_str(), - commands,&cminst,(it->second).c_str()); - } - } + doc.GetStructuredDocFromFile( + (docedIt->first).c_str(), + commands,&cminst,(docedIt->second).c_str()); + } std::map propDocs; cminst.GetPropertiesDocumentation(propDocs); diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index ed1e5e1..dde4953 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -14,6 +14,7 @@ #include "cmSystemTools.h" #include "cmVersion.h" #include +#include //---------------------------------------------------------------------------- @@ -745,6 +746,60 @@ void cmDocumentation::addCPackStandardDocSections() } //---------------------------------------------------------------------------- +int cmDocumentation::getDocumentedModulesListInDir( + std::string path, + std::string globExpr, + documentedModulesList_t& docedModuleList) +{ + cmsys::Glob gl; + std::string findExpr; + std::vector files; + std::string line; + documentedModuleSectionPair_t docPair; + int nbDocumentedModules = 0; + + findExpr = path + "/" + globExpr; + if (gl.FindFiles(findExpr)) + { + files = gl.GetFiles(); + for (std::vector::iterator itf=files.begin(); + itf!=files.end();++itf) + { + std::ifstream fin((*itf).c_str()); + // file access trouble ignore it (ignore this kind of error) + if (!fin) continue; + /* read first line in order to get doc section */ + if (cmSystemTools::GetLineFromStream(fin, line)) + { + /* Doc section indicates that + * this file has structured doc in it. + */ + if (line.find("##section")!=std::string::npos) + { + // ok found one more documented module + ++nbDocumentedModules; + docPair.first = *itf; + // 10 is the size of '##section' + 1 + docPair.second = line.substr(10,std::string::npos); + docedModuleList.push_back(docPair); + } + // No else if no section is found (undocumented module) + } + // No else cannot read first line (ignore this kind of error) + line.clear(); + } + } + if (nbDocumentedModules>0) + { + return 0; + } + else + { + return 1; + } +} + +//---------------------------------------------------------------------------- static void trim(std::string& s) { std::string::size_type pos = s.find_last_not_of(' '); diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 83a0a09..00dba1a 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -35,6 +35,21 @@ public: cmDocumentation(); ~cmDocumentation(); + + /** + * An helper type pair for [structured] documented modules. + * The comment of those module contains structure markup + * which makes it possible to retrieve the documentation + * of variables, macros and functions defined in the module. + * - first is the filename of the module + * - second is the section of the doc the module belongs too + */ + typedef std::pair documentedModuleSectionPair_t; + /** + * A list of documented module(s). + */ + typedef std::list documentedModulesList_t; + // High-level interface for standard documents: /** @@ -133,6 +148,21 @@ public: void addCPackStandardDocSections(); /** + * Retrieve the list of documented module located in + * path which match the globing expression globExpr. + * @param[in] path, directory where to start the search + * we will recurse into it. + * @param[in] globExpr, the globing expression used to + * match the file in path. + * @param[out] the list of obtained pairs (may be empty) + * @return 0 on success 1 on error or empty list + */ + int getDocumentedModulesListInDir( + std::string path, + std::string globExpr, + documentedModulesList_t& docModuleList); + + /** * Get the documentation of macros, functions and variable documented * with CMake structured documentation in a CMake script. * (in fact it may be in any file which follow the structured doc format) @@ -140,7 +170,8 @@ public: * ## (double sharp) in column 1 & 2 immediately followed * by a markup. Those ## are ignored by the legacy module * documentation parser @see CreateSingleModule. - * Current markup are ##macro, ##function, ##variable and ##end. + * Current markup are ##section, ##module, + * ##macro, ##function, ##variable and ##end. * ##end is closing either of the previous ones. * @param[in] fname the script file name to be parsed for documentation * @param[in,out] commands the vector of command/macros documentation -- cgit v0.12