diff --git a/parser/include/parser/parsercontext.h b/parser/include/parser/parsercontext.h index 1b7928526..d576d1809 100644 --- a/parser/include/parser/parsercontext.h +++ b/parser/include/parser/parsercontext.h @@ -3,9 +3,9 @@ #include #include +#include #include - #include namespace po = boost::program_options; @@ -43,6 +43,7 @@ struct ParserContext std::string& compassRoot; po::variables_map& options; std::unordered_map fileStatus; + std::vector moduleDirectories; }; } // parser diff --git a/parser/src/parser.cpp b/parser/src/parser.cpp index 93cb0362b..50ae1997d 100644 --- a/parser/src/parser.cpp +++ b/parser/src/parser.cpp @@ -85,7 +85,11 @@ po::options_description commandLineArguments() "further actions modifying the state of the database.") ("incremental-threshold", po::value()->default_value(10), "This is a threshold percentage. If the total ratio of changed files " - "is greater than this value, full parse is forced instead of incremental parsing."); + "is greater than this value, full parse is forced instead of incremental parsing.") + ("modules,m", po::value(), + "For metrics calculations, you can specify the project's (sub)module structure." + "Provide the path of a text file for this setting." + "The file should contain directory paths, each on a separate line, which will be considered modules."); return desc; } diff --git a/parser/src/parsercontext.cpp b/parser/src/parsercontext.cpp index 937cbfa5e..3746e9b93 100644 --- a/parser/src/parsercontext.cpp +++ b/parser/src/parsercontext.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -12,6 +13,7 @@ #include namespace po = boost::program_options; +namespace fs = boost::filesystem; namespace cc { @@ -76,6 +78,31 @@ ParserContext::ParserContext( // TODO: detect ADDED files }); + + // Fill moduleDirectories vector + if (options.count("modules")) { + const std::string& modulesFilePath = options["modules"].as(); + + std::ifstream fileStream(modulesFilePath); + + if (!fileStream.good()) { + LOG(error) << "Failed to open modules file: " << modulesFilePath; + return; + } + + LOG(info) << "Processing modules file: " << modulesFilePath; + + std::string line; + while (std::getline(fileStream, line)) { + try { + const fs::path p = fs::canonical(line); + moduleDirectories.push_back(p.string()); + } catch (fs::filesystem_error& err) { + LOG(error) << "Failed to process path from modules file: " << line; + LOG(error) << err.what(); + } + } + } } } }