Skip to content

Commit

Permalink
Add more logs for linking and CLI verbosity level (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
ladisgin authored Feb 1, 2024
1 parent 9370dfa commit 0b13146
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
8 changes: 4 additions & 4 deletions server/src/building/BuildDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
if (Paths::isSourceFile(normalizedPath)) {
if (!CollectionUtils::containsKey(sourceFileInfos, normalizedPath)) {
std::string message =
"No executable or library found for current source file in link_commands.json: " + path.string();
"No source file found in compile_commands.json: " + path.string();
LOG_S(ERROR) << message;
throw CompilationDatabaseException(message);
}
Expand All @@ -273,7 +273,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
} else {
if (!CollectionUtils::containsKey(targetInfos, normalizedPath)) {
std::string message =
"No executable or library found for current source file in link_commands.json: " + path.string();
"No executable or library found in link_commands.json: " + path.string();
LOG_S(ERROR) << message;
throw CompilationDatabaseException(message);
}
Expand All @@ -287,7 +287,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
}

fs::path BuildDatabase::getRootForFirstSource() const {
if (sourceFileInfos.empty()){
if (sourceFileInfos.empty()) {
std::string message = "Source files not found";
LOG_S(ERROR) << message;
throw CompilationDatabaseException(message);
Expand Down Expand Up @@ -459,7 +459,7 @@ bool BuildDatabase::ObjectFileInfo::is32bits() const {
}

fs::path BuildDatabase::TargetInfo::getOutput() const {
if (commands.empty()){
if (commands.empty()) {
std::string message = "There are no targets";
LOG_S(ERROR) << message;
throw CompilationDatabaseException(message);
Expand Down
24 changes: 22 additions & 2 deletions server/src/building/ProjectBuildDatabse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);
initObjects(compileCommandsJson);
for (const auto i: sourceFileInfos) {
LOG_S(MAX) << "Source: " << i.first << " Objects: "
<< StringUtils::joinWith(CollectionUtils::transformTo<std::vector<std::string>>
(i.second, [](const std::shared_ptr<ObjectFileInfo> &s) {
return s->getOutputFile();
}), ", ");
}
initInfo(linkCommandsJson, skipObjectWithoutSource);
for (const auto i: targetInfos) {
LOG_S(MAX) << "Target: " << i.first << " Files: " << StringUtils::joinWith(i.second->files, ", ");
}
filterInstalledFiles();
addLocalSharedLibraries();
fillTargetInfoParents();
Expand Down Expand Up @@ -81,6 +91,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
} else {
jsonArguments = std::vector<std::string>(compileCommand.at("arguments"));
}
LOG_S(INFO) << "Processing build command: " << StringUtils::joinWith(jsonArguments, " ");
std::transform(jsonArguments.begin(), jsonArguments.end(), jsonArguments.begin(),
[&directory](const std::string &argument) {
return tryConvertOptionToPath(argument, directory);
Expand Down Expand Up @@ -177,8 +188,13 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool
} else {
jsonArguments = std::vector<std::string>(linkCommand.at("arguments"));
}
if (StringUtils::endsWith(jsonArguments[0], "ranlib") ||
StringUtils::endsWith(jsonArguments[0], "cmake")) {
LOG_S(INFO) << "Processing link command: " << StringUtils::joinWith(jsonArguments, " ");
if (StringUtils::endsWith(jsonArguments[0], "ranlib")) {
LOG_S(INFO) << "Skip ranlib command";
continue;
}
if (StringUtils::endsWith(jsonArguments[0], "cmake")) {
LOG_S(INFO) << "Skip cmake command";
continue;
}
std::transform(jsonArguments.begin(), jsonArguments.end(), jsonArguments.begin(),
Expand All @@ -190,6 +206,10 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool

utbot::LinkCommand command(jsonArguments, directory);
fs::path const &output = command.getOutput();
if (output.empty()) {
LOG_S(WARNING) << "Empty output of command: " << command.toString();
}

auto targetInfo = targetInfos[output];
if (targetInfo == nullptr) {
targetInfo = targetInfos[output] = std::make_shared<TargetInfo>();
Expand Down
31 changes: 17 additions & 14 deletions server/src/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

#include "utils/StringUtils.h"
#include "utils/CLIUtils.h"
#include "loguru.h"
#include "config.h"

uint32_t Commands::threadsPerUser = 0;
uint32_t Commands::kleeProcessNumber = 0;

Commands::MainCommands::MainCommands(CLI::App &app) {
app.set_help_all_flag("--help-all", "Expand all help");
app.add_flag_function("--version", [](int count){
app.add_flag_function("--version", [](int count) {
std::cout << PROJECT_NAME << " " << PROJECT_VERSION << std::endl;
if (strlen(RUN_INFO)) {
std::cout << "Build by " << RUN_INFO << std::endl;
}
exit(0);
}, "Get UTBotCpp version and build detail");

app.add_option("-v,--verbosity", verbosity, "Logger verbosity.")
->type_name(" ENUM:value in {" +
StringUtils::joinWith(CollectionUtils::getKeys(verbosityMap), "|") + "}")
->transform(CLI::CheckedTransformer(verbosityMap, CLI::ignore_case));
app.add_option("--log", logPath, "Path to folder with logs.");

serverCommand = app.add_subcommand("server", "Launch UTBot server.");
generateCommand =
app.add_subcommand("generate", "Generate unit tests and/or stubs.")->require_subcommand();
app.add_subcommand("generate", "Generate unit tests and/or stubs.")->require_subcommand();
runTestsCommand = app.add_subcommand("run", "Launch unit tests and generate coverage info.");
allCommand = app.add_subcommand(
"all", "Sequential launch of 'generate stubs' -> 'generate project' -> 'run'.");
"all", "Sequential launch of 'generate stubs' -> 'generate project' -> 'run'.");
app.require_subcommand(0, 1);
}

Expand All @@ -45,25 +53,20 @@ CLI::App *Commands::MainCommands::getAllCommand() {
Commands::ServerCommandOptions::ServerCommandOptions(CLI::App *command) {
command->add_option("-p,--port", port, "Port server run on.");
command->add_option("-j", threadsPerUser, "Maximum number of threads per user.");
command->add_option("--log", logPath, "Path to folder with logs.");
command->add_option("-v,--verbosity", verbosity, "Logger verbosity.")
->type_name(" ENUM:value in {" +
StringUtils::joinWith(CollectionUtils::getKeys(verbosityMap), "|") + "}")
->transform(CLI::CheckedTransformer(verbosityMap, CLI::ignore_case));
command->add_option("--klee-process-number", kleeProcessNumber,
"Number of threads for KLEE in interactive mode");
}

fs::path Commands::ServerCommandOptions::getLogPath() {
fs::path Commands::MainCommands::getLogPath() {
return logPath;
}

unsigned int Commands::ServerCommandOptions::getPort() {
return port;
loguru::NamedVerbosity Commands::MainCommands::getVerbosity() {
return verbosity;
}

loguru::NamedVerbosity Commands::ServerCommandOptions::getVerbosity() {
return verbosity;
unsigned int Commands::ServerCommandOptions::getPort() {
return port;
}

unsigned int Commands::ServerCommandOptions::getThreadsPerUser() {
Expand All @@ -74,7 +77,7 @@ unsigned int Commands::ServerCommandOptions::getKleeProcessNumber() {
return kleeProcessNumber;
}

const std::map<std::string, loguru::NamedVerbosity> Commands::ServerCommandOptions::verbosityMap = {
const std::map<std::string, loguru::NamedVerbosity> Commands::MainCommands::verbosityMap = {
{ "trace", loguru::NamedVerbosity::Verbosity_MAX },
{ "debug", loguru::NamedVerbosity::Verbosity_1 },
{ "info", loguru::NamedVerbosity::Verbosity_INFO },
Expand Down
15 changes: 7 additions & 8 deletions server/src/commands/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ namespace Commands {

CLI::App *getAllCommand();

fs::path getLogPath();

loguru::NamedVerbosity getVerbosity();

private:
loguru::NamedVerbosity verbosity = loguru::Verbosity_INFO;
fs::path logPath;
static const std::map<std::string, loguru::NamedVerbosity> verbosityMap;

CLI::App *serverCommand;
CLI::App *generateCommand;
CLI::App *runTestsCommand;
Expand All @@ -38,21 +45,13 @@ namespace Commands {
struct ServerCommandOptions {
explicit ServerCommandOptions(CLI::App *command);

fs::path getLogPath();

loguru::NamedVerbosity getVerbosity();

unsigned int getPort();

unsigned int getThreadsPerUser();

unsigned int getKleeProcessNumber();
private:
unsigned int port = 0;
fs::path logPath;

loguru::NamedVerbosity verbosity = loguru::Verbosity_INFO;
static const std::map<std::string, loguru::NamedVerbosity> verbosityMap;
};


Expand Down
5 changes: 3 additions & 2 deletions server/src/utils/CLIUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ void CLIUtils::parse(int argc, char **argv, CLI::App &app) {
// PARSE RESULTS
app.parse(argc, argv);

CLIUtils::setupLogger(mainCommands.getLogPath(),
mainCommands.getVerbosity());

if (app.got_subcommand(mainCommands.getGenerateCommand())) {
auto sourcePaths =
getSourcePaths(projectGenerateContext, generateCommandsOptions.getSrcPaths());
Expand Down Expand Up @@ -244,8 +247,6 @@ void CLIUtils::parse(int argc, char **argv, CLI::App &app) {

LOG_S(INFO) << "Successfully finished.";
} else {
CLIUtils::setupLogger(serverCommandOptions.getLogPath(),
serverCommandOptions.getVerbosity());
Server server;
if (serverCommandOptions.getPort() != 0) {
server.run(serverCommandOptions.getPort());
Expand Down

0 comments on commit 0b13146

Please sign in to comment.