diff --git a/server/src/building/BuildDatabase.cpp b/server/src/building/BuildDatabase.cpp index 3911cff46..9b1fb8673 100644 --- a/server/src/building/BuildDatabase.cpp +++ b/server/src/building/BuildDatabase.cpp @@ -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); } @@ -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); } @@ -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); @@ -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); diff --git a/server/src/building/ProjectBuildDatabse.cpp b/server/src/building/ProjectBuildDatabse.cpp index cddbb5254..96841c593 100644 --- a/server/src/building/ProjectBuildDatabse.cpp +++ b/server/src/building/ProjectBuildDatabse.cpp @@ -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> + (i.second, [](const std::shared_ptr &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(); @@ -81,6 +91,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson } else { jsonArguments = std::vector(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); @@ -177,8 +188,13 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool } else { jsonArguments = std::vector(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(), @@ -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(); diff --git a/server/src/commands/Commands.cpp b/server/src/commands/Commands.cpp index 77be39ec3..f42f8a700 100644 --- a/server/src/commands/Commands.cpp +++ b/server/src/commands/Commands.cpp @@ -2,6 +2,7 @@ #include "utils/StringUtils.h" #include "utils/CLIUtils.h" +#include "loguru.h" #include "config.h" uint32_t Commands::threadsPerUser = 0; @@ -9,19 +10,26 @@ 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); } @@ -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() { @@ -74,7 +77,7 @@ unsigned int Commands::ServerCommandOptions::getKleeProcessNumber() { return kleeProcessNumber; } -const std::map Commands::ServerCommandOptions::verbosityMap = { +const std::map Commands::MainCommands::verbosityMap = { { "trace", loguru::NamedVerbosity::Verbosity_MAX }, { "debug", loguru::NamedVerbosity::Verbosity_1 }, { "info", loguru::NamedVerbosity::Verbosity_INFO }, diff --git a/server/src/commands/Commands.h b/server/src/commands/Commands.h index d8a87a3ac..b52fae53c 100644 --- a/server/src/commands/Commands.h +++ b/server/src/commands/Commands.h @@ -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 verbosityMap; + CLI::App *serverCommand; CLI::App *generateCommand; CLI::App *runTestsCommand; @@ -38,10 +45,6 @@ namespace Commands { struct ServerCommandOptions { explicit ServerCommandOptions(CLI::App *command); - fs::path getLogPath(); - - loguru::NamedVerbosity getVerbosity(); - unsigned int getPort(); unsigned int getThreadsPerUser(); @@ -49,10 +52,6 @@ namespace Commands { unsigned int getKleeProcessNumber(); private: unsigned int port = 0; - fs::path logPath; - - loguru::NamedVerbosity verbosity = loguru::Verbosity_INFO; - static const std::map verbosityMap; }; diff --git a/server/src/utils/CLIUtils.cpp b/server/src/utils/CLIUtils.cpp index 27d6089c8..2d7e8d0cd 100644 --- a/server/src/utils/CLIUtils.cpp +++ b/server/src/utils/CLIUtils.cpp @@ -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()); @@ -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());