Skip to content

Commit 0b13146

Browse files
authored
Add more logs for linking and CLI verbosity level (#666)
1 parent 9370dfa commit 0b13146

File tree

5 files changed

+53
-30
lines changed

5 files changed

+53
-30
lines changed

server/src/building/BuildDatabase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
256256
if (Paths::isSourceFile(normalizedPath)) {
257257
if (!CollectionUtils::containsKey(sourceFileInfos, normalizedPath)) {
258258
std::string message =
259-
"No executable or library found for current source file in link_commands.json: " + path.string();
259+
"No source file found in compile_commands.json: " + path.string();
260260
LOG_S(ERROR) << message;
261261
throw CompilationDatabaseException(message);
262262
}
@@ -273,7 +273,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
273273
} else {
274274
if (!CollectionUtils::containsKey(targetInfos, normalizedPath)) {
275275
std::string message =
276-
"No executable or library found for current source file in link_commands.json: " + path.string();
276+
"No executable or library found in link_commands.json: " + path.string();
277277
LOG_S(ERROR) << message;
278278
throw CompilationDatabaseException(message);
279279
}
@@ -287,7 +287,7 @@ fs::path BuildDatabase::getRootForSource(const fs::path &path) const {
287287
}
288288

289289
fs::path BuildDatabase::getRootForFirstSource() const {
290-
if (sourceFileInfos.empty()){
290+
if (sourceFileInfos.empty()) {
291291
std::string message = "Source files not found";
292292
LOG_S(ERROR) << message;
293293
throw CompilationDatabaseException(message);
@@ -459,7 +459,7 @@ bool BuildDatabase::ObjectFileInfo::is32bits() const {
459459
}
460460

461461
fs::path BuildDatabase::TargetInfo::getOutput() const {
462-
if (commands.empty()){
462+
if (commands.empty()) {
463463
std::string message = "There are no targets";
464464
LOG_S(ERROR) << message;
465465
throw CompilationDatabaseException(message);

server/src/building/ProjectBuildDatabse.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ ProjectBuildDatabase::ProjectBuildDatabase(fs::path _buildCommandsJsonPath,
4848
auto linkCommandsJson = JsonUtils::getJsonFromFile(linkCommandsJsonPath);
4949
auto compileCommandsJson = JsonUtils::getJsonFromFile(compileCommandsJsonPath);
5050
initObjects(compileCommandsJson);
51+
for (const auto i: sourceFileInfos) {
52+
LOG_S(MAX) << "Source: " << i.first << " Objects: "
53+
<< StringUtils::joinWith(CollectionUtils::transformTo<std::vector<std::string>>
54+
(i.second, [](const std::shared_ptr<ObjectFileInfo> &s) {
55+
return s->getOutputFile();
56+
}), ", ");
57+
}
5158
initInfo(linkCommandsJson, skipObjectWithoutSource);
59+
for (const auto i: targetInfos) {
60+
LOG_S(MAX) << "Target: " << i.first << " Files: " << StringUtils::joinWith(i.second->files, ", ");
61+
}
5262
filterInstalledFiles();
5363
addLocalSharedLibraries();
5464
fillTargetInfoParents();
@@ -81,6 +91,7 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
8191
} else {
8292
jsonArguments = std::vector<std::string>(compileCommand.at("arguments"));
8393
}
94+
LOG_S(INFO) << "Processing build command: " << StringUtils::joinWith(jsonArguments, " ");
8495
std::transform(jsonArguments.begin(), jsonArguments.end(), jsonArguments.begin(),
8596
[&directory](const std::string &argument) {
8697
return tryConvertOptionToPath(argument, directory);
@@ -177,8 +188,13 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool
177188
} else {
178189
jsonArguments = std::vector<std::string>(linkCommand.at("arguments"));
179190
}
180-
if (StringUtils::endsWith(jsonArguments[0], "ranlib") ||
181-
StringUtils::endsWith(jsonArguments[0], "cmake")) {
191+
LOG_S(INFO) << "Processing link command: " << StringUtils::joinWith(jsonArguments, " ");
192+
if (StringUtils::endsWith(jsonArguments[0], "ranlib")) {
193+
LOG_S(INFO) << "Skip ranlib command";
194+
continue;
195+
}
196+
if (StringUtils::endsWith(jsonArguments[0], "cmake")) {
197+
LOG_S(INFO) << "Skip cmake command";
182198
continue;
183199
}
184200
std::transform(jsonArguments.begin(), jsonArguments.end(), jsonArguments.begin(),
@@ -190,6 +206,10 @@ void ProjectBuildDatabase::initInfo(const nlohmann::json &linkCommandsJson, bool
190206

191207
utbot::LinkCommand command(jsonArguments, directory);
192208
fs::path const &output = command.getOutput();
209+
if (output.empty()) {
210+
LOG_S(WARNING) << "Empty output of command: " << command.toString();
211+
}
212+
193213
auto targetInfo = targetInfos[output];
194214
if (targetInfo == nullptr) {
195215
targetInfo = targetInfos[output] = std::make_shared<TargetInfo>();

server/src/commands/Commands.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22

33
#include "utils/StringUtils.h"
44
#include "utils/CLIUtils.h"
5+
#include "loguru.h"
56
#include "config.h"
67

78
uint32_t Commands::threadsPerUser = 0;
89
uint32_t Commands::kleeProcessNumber = 0;
910

1011
Commands::MainCommands::MainCommands(CLI::App &app) {
1112
app.set_help_all_flag("--help-all", "Expand all help");
12-
app.add_flag_function("--version", [](int count){
13+
app.add_flag_function("--version", [](int count) {
1314
std::cout << PROJECT_NAME << " " << PROJECT_VERSION << std::endl;
1415
if (strlen(RUN_INFO)) {
1516
std::cout << "Build by " << RUN_INFO << std::endl;
1617
}
1718
exit(0);
1819
}, "Get UTBotCpp version and build detail");
20+
21+
app.add_option("-v,--verbosity", verbosity, "Logger verbosity.")
22+
->type_name(" ENUM:value in {" +
23+
StringUtils::joinWith(CollectionUtils::getKeys(verbosityMap), "|") + "}")
24+
->transform(CLI::CheckedTransformer(verbosityMap, CLI::ignore_case));
25+
app.add_option("--log", logPath, "Path to folder with logs.");
26+
1927
serverCommand = app.add_subcommand("server", "Launch UTBot server.");
2028
generateCommand =
21-
app.add_subcommand("generate", "Generate unit tests and/or stubs.")->require_subcommand();
29+
app.add_subcommand("generate", "Generate unit tests and/or stubs.")->require_subcommand();
2230
runTestsCommand = app.add_subcommand("run", "Launch unit tests and generate coverage info.");
2331
allCommand = app.add_subcommand(
24-
"all", "Sequential launch of 'generate stubs' -> 'generate project' -> 'run'.");
32+
"all", "Sequential launch of 'generate stubs' -> 'generate project' -> 'run'.");
2533
app.require_subcommand(0, 1);
2634
}
2735

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

57-
fs::path Commands::ServerCommandOptions::getLogPath() {
60+
fs::path Commands::MainCommands::getLogPath() {
5861
return logPath;
5962
}
6063

61-
unsigned int Commands::ServerCommandOptions::getPort() {
62-
return port;
64+
loguru::NamedVerbosity Commands::MainCommands::getVerbosity() {
65+
return verbosity;
6366
}
6467

65-
loguru::NamedVerbosity Commands::ServerCommandOptions::getVerbosity() {
66-
return verbosity;
68+
unsigned int Commands::ServerCommandOptions::getPort() {
69+
return port;
6770
}
6871

6972
unsigned int Commands::ServerCommandOptions::getThreadsPerUser() {
@@ -74,7 +77,7 @@ unsigned int Commands::ServerCommandOptions::getKleeProcessNumber() {
7477
return kleeProcessNumber;
7578
}
7679

77-
const std::map<std::string, loguru::NamedVerbosity> Commands::ServerCommandOptions::verbosityMap = {
80+
const std::map<std::string, loguru::NamedVerbosity> Commands::MainCommands::verbosityMap = {
7881
{ "trace", loguru::NamedVerbosity::Verbosity_MAX },
7982
{ "debug", loguru::NamedVerbosity::Verbosity_1 },
8083
{ "info", loguru::NamedVerbosity::Verbosity_INFO },

server/src/commands/Commands.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ namespace Commands {
2727

2828
CLI::App *getAllCommand();
2929

30+
fs::path getLogPath();
31+
32+
loguru::NamedVerbosity getVerbosity();
3033

3134
private:
35+
loguru::NamedVerbosity verbosity = loguru::Verbosity_INFO;
36+
fs::path logPath;
37+
static const std::map<std::string, loguru::NamedVerbosity> verbosityMap;
38+
3239
CLI::App *serverCommand;
3340
CLI::App *generateCommand;
3441
CLI::App *runTestsCommand;
@@ -38,21 +45,13 @@ namespace Commands {
3845
struct ServerCommandOptions {
3946
explicit ServerCommandOptions(CLI::App *command);
4047

41-
fs::path getLogPath();
42-
43-
loguru::NamedVerbosity getVerbosity();
44-
4548
unsigned int getPort();
4649

4750
unsigned int getThreadsPerUser();
4851

4952
unsigned int getKleeProcessNumber();
5053
private:
5154
unsigned int port = 0;
52-
fs::path logPath;
53-
54-
loguru::NamedVerbosity verbosity = loguru::Verbosity_INFO;
55-
static const std::map<std::string, loguru::NamedVerbosity> verbosityMap;
5655
};
5756

5857

server/src/utils/CLIUtils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ void CLIUtils::parse(int argc, char **argv, CLI::App &app) {
110110
// PARSE RESULTS
111111
app.parse(argc, argv);
112112

113+
CLIUtils::setupLogger(mainCommands.getLogPath(),
114+
mainCommands.getVerbosity());
115+
113116
if (app.got_subcommand(mainCommands.getGenerateCommand())) {
114117
auto sourcePaths =
115118
getSourcePaths(projectGenerateContext, generateCommandsOptions.getSrcPaths());
@@ -244,8 +247,6 @@ void CLIUtils::parse(int argc, char **argv, CLI::App &app) {
244247

245248
LOG_S(INFO) << "Successfully finished.";
246249
} else {
247-
CLIUtils::setupLogger(serverCommandOptions.getLogPath(),
248-
serverCommandOptions.getVerbosity());
249250
Server server;
250251
if (serverCommandOptions.getPort() != 0) {
251252
server.run(serverCommandOptions.getPort());

0 commit comments

Comments
 (0)