Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion parser/include/parser/parsercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <memory>
#include <unordered_map>
#include <vector>

#include <boost/program_options.hpp>

#include <odb/database.hxx>

namespace po = boost::program_options;
Expand Down Expand Up @@ -43,6 +43,7 @@ struct ParserContext
std::string& compassRoot;
po::variables_map& options;
std::unordered_map<std::string, IncrementalStatus> fileStatus;
std::vector<std::string> moduleDirectories;
};

} // parser
Expand Down
6 changes: 5 additions & 1 deletion parser/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ po::options_description commandLineArguments()
"further actions modifying the state of the database.")
("incremental-threshold", po::value<int>()->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<std::string>(),
"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;
}
Expand Down
27 changes: 27 additions & 0 deletions parser/src/parsercontext.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <boost/filesystem/exception.hpp>
#include <fstream>

#include <boost/filesystem.hpp>
Expand All @@ -12,6 +13,7 @@
#include <parser/sourcemanager.h>

namespace po = boost::program_options;
namespace fs = boost::filesystem;

namespace cc
{
Expand Down Expand Up @@ -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::string>();

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();
}
}
}
}
}
}
Expand Down