Skip to content

Commit 7ffdfeb

Browse files
Merge pull request #22 from Neko-Box-Coder/RuntimeLogLevelAndWarnings
Runtime log level and warnings
2 parents 019983c + 72678a8 commit 7ffdfeb

File tree

9 files changed

+93
-18
lines changed

9 files changed

+93
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Builds/
4343
Build/
4444
v0.*/
4545
*.bak
46+
*.runcpp2/
4647
Releases/
4748
Resources/embed
4849
Resources/embed.exe

DefaultYAMLs/DefaultUserConfig.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# List of anchors that will be aliased later
22
Templates:
33
MSVC_CompileFlags: &MSVC_CompileFlags
4-
Flags: "/NOLOGO /W3 /WX /diagnostics:caret /D NDEBUG /utf-8 /Gm- /MD /EHa /TP /std:c++17 /GR /TP"
4+
Flags: "/NOLOGO /W4 /diagnostics:caret /D NDEBUG /utf-8 /Gm- /MD /EHa /TP /std:c++17 /GR /TP"
55

66
"g++_CompileRunParts": &g++_CompileRunParts
77
- Type: Once
@@ -164,7 +164,7 @@ Profiles:
164164
CompileTypes:
165165
Executable:
166166
Default:
167-
Flags: "-std=c++17 -Wall -Werror"
167+
Flags: "-std=c++17 -Wall"
168168
Executable: "g++"
169169
RunParts: *g++_CompileRunParts
170170
# (Optional) The commands to run in **shell** BEFORE compiling
@@ -175,14 +175,14 @@ Profiles:
175175
# Cleanup: []
176176
Static:
177177
Default:
178-
Flags: "-std=c++17 -Wall -Werror"
178+
Flags: "-std=c++17 -Wall"
179179
Executable: "g++"
180180
RunParts: *g++_CompileRunParts
181181
# Setup: []
182182
# Cleanup: []
183183
Shared:
184184
Default:
185-
Flags: "-std=c++17 -Wall -Werror -fpic"
185+
Flags: "-std=c++17 -Wall -fpic"
186186
Executable: "g++"
187187
RunParts: *g++_CompileRunParts
188188
# Setup: []

Examples/test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,26 @@
4545
Default:
4646
"Default":
4747
- "./Include/ssLogger/ssLog.hpp"
48+
49+
- Name: System2.cpp
50+
Platforms: [Default]
51+
Source:
52+
Type: Git
53+
Value: "https://github.com/Neko-Box-Coder/System2.cpp.git"
54+
LibraryType: Header
55+
IncludePaths: ["./", "./External/System2"]
56+
Setup:
57+
Default:
58+
"Default":
59+
- "git submodule update --init --recursive"
4860
*/
4961

5062

5163
//#include "ssLogger/ssLogInit.hpp"
5264

5365
#define ssLOG_DLL 1
5466
#include "ssLogger/ssLog.hpp"
67+
#include "System2.hpp"
5568

5669
#if defined(__GNUC__)
5770
#include "./OtherSources/AnotherSourceFileGcc.hpp"
@@ -69,6 +82,16 @@ int main(int argc, char* argv[])
6982
std::cout << "Hello World" << std::endl;
7083
std::cout << TEST_DEF << std::endl;
7184

85+
System2CommandInfo commandInfo = {};
86+
int returnCode = 0;
87+
88+
#if defined(_WIN32)
89+
System2CppRun("dir", commandInfo);
90+
#else
91+
auto re = System2CppRun("ls -lah", commandInfo);
92+
#endif
93+
System2CppGetCommandReturnValueSync(commandInfo, returnCode);
94+
7295
for(int i = 0; i < argc; ++i)
7396
std::cout << "Arg" << i << ": " << argv[i] << std::endl;
7497

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace runcpp2
2323
WATCH,
2424
BUILD,
2525
VERSION,
26+
LOG_LEVEL,
2627
COUNT
2728
};
2829

Src/runcpp2/CompilingLinking.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ namespace
292292
ssLOG_ERROR("Compile output: \n" << commandOutput);
293293
return false;
294294
}
295+
else
296+
{
297+
//TODO: Make this configurable
298+
//Attempt to capture warnings
299+
if(commandOutput.find(" warning") != std::string::npos)
300+
ssLOG_WARNING("Warning detected:\n" << commandOutput);
301+
else
302+
ssLOG_INFO("Compile output:\n" << commandOutput);
303+
}
295304
}
296305

297306
//Run cleanup if any
@@ -581,6 +590,8 @@ namespace
581590
ssLOG_ERROR("Link output: \n" << linkOutput);
582591
return false;
583592
}
593+
else
594+
ssLOG_INFO("Link output:\n" << linkOutput);
584595
}
585596

586597
//Run cleanup if any

Src/runcpp2/Data/StageInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ bool runcpp2::Data::StageInfo::ConstructCommand(const SubstitutionMap& substitut
326326

327327
for(int i = 0; i < currentRunParts.size(); ++i)
328328
{
329-
ssLOG_INFO("Parsing run part at index: " << i);
330-
ssLOG_INFO("Which is: \"" << currentRunParts.at(i).CommandPart << "\"");
329+
ssLOG_DEBUG("Parsing run part at index: " << i);
330+
ssLOG_DEBUG("Which is: \"" << currentRunParts.at(i).CommandPart << "\"");
331331

332332
std::string currentEscapedPart;
333333
std::vector<std::string> substitutionsInCurrentPart;

Src/runcpp2/PlatformUtil.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
118118
return false;
119119
}
120120

121+
ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());
122+
121123
if(outReturnCode != 0)
122124
{
123-
ssLOG_DEBUG("Failed when running command");
124-
ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());
125+
ssLOG_DEBUG("Failed when running command with return code: " << outReturnCode);
125126
return false;
126127
}
127128

Src/runcpp2/main.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ bool GenerateScriptTemplate(const std::string& outputFilePathStr)
169169

170170
int main(int argc, char* argv[])
171171
{
172+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING);
173+
172174
//Parse command line options
173175
int currentArgIndex = 0;
174176
std::unordered_map<runcpp2::CmdOptions, std::string> currentOptions;
175-
176177
{
177-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
178+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
178179
std::unordered_map<std::string, runcpp2::OptionInfo> longOptionsMap =
179180
{
180181
{
@@ -220,10 +221,14 @@ int main(int argc, char* argv[])
220221
{
221222
"--version",
222223
runcpp2::OptionInfo(runcpp2::CmdOptions::VERSION, false)
224+
},
225+
{
226+
"--log-level",
227+
runcpp2::OptionInfo(runcpp2::CmdOptions::LOG_LEVEL, true)
223228
}
224229
};
225230

226-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
231+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
227232
std::unordered_map<std::string, const runcpp2::OptionInfo&> shortOptionsMap =
228233
{
229234
{"-r", longOptionsMap.at("--reset-cache")},
@@ -253,7 +258,7 @@ int main(int argc, char* argv[])
253258
//Help message
254259
if(currentOptions.count(runcpp2::CmdOptions::HELP))
255260
{
256-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
261+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
257262
ssLOG_BASE("Usage: runcpp2 [options] [input_file]");
258263
ssLOG_BASE("Options:");
259264
ssLOG_BASE(" -r, --[r]eset-cache Deletes all cache and build everything from scratch");
@@ -266,11 +271,33 @@ int main(int argc, char* argv[])
266271
ssLOG_BASE(" -t, --create-script-[t]emplate <file> Creates/prepend runcpp2 script info template");
267272
ssLOG_BASE(" -w, --[w]atch Watch script changes and output any compiling errors");
268273
ssLOG_BASE(" -b, --[b]uild Build the script and copy output files to the working directory");
269-
ssLOG_BASE(" -v, --[v]ersion Show the version of runcpp2");
274+
ssLOG_BASE(" -v, --[v]ersion Show the version of runcpp2");
275+
ssLOG_BASE(" --log-level <level> Sets the log level (Normal, Info, Debug) for runcpp2.");
270276

271277
return 0;
272278
}
273279

280+
//Set Log level
281+
if(currentOptions.count(runcpp2::CmdOptions::LOG_LEVEL))
282+
{
283+
std::string level = currentOptions.at(runcpp2::CmdOptions::LOG_LEVEL);
284+
runcpp2::Trim(level);
285+
for(int i = 0; i < level.size(); ++i)
286+
level[i] = std::tolower(level[i]);
287+
288+
if(level == "info")
289+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_INFO);
290+
else if(level == "debug")
291+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_DEBUG);
292+
else if(level == "normal")
293+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING);
294+
else
295+
{
296+
ssLOG_ERROR("Invalid level: " << level);
297+
return -1;
298+
}
299+
}
300+
274301
//Show user config path
275302
if(currentOptions.count(runcpp2::CmdOptions::SHOW_USER_CONFIG))
276303
{
@@ -294,7 +321,7 @@ int main(int argc, char* argv[])
294321
ssLOG_ERROR("Failed reset user config");
295322
return -1;
296323
}
297-
324+
ssLOG_BASE("User config reset successful");
298325
return 0;
299326
}
300327

@@ -304,7 +331,10 @@ int main(int argc, char* argv[])
304331
if(!GenerateScriptTemplate(currentOptions.at(runcpp2::CmdOptions::SCRIPT_TEMPLATE)))
305332
return -1;
306333
else
334+
{
335+
ssLOG_BASE("Script template generated");
307336
return 0;
337+
}
308338
}
309339

310340
std::vector<runcpp2::Data::Profile> profiles;
@@ -388,17 +418,19 @@ int main(int argc, char* argv[])
388418
return -1;
389419

390420
case runcpp2::PipelineResult::UNEXPECTED_FAILURE:
391-
case runcpp2::PipelineResult::SUCCESS:
392421
case runcpp2::PipelineResult::INVALID_BUILD_DIR:
393422
case runcpp2::PipelineResult::INVALID_SCRIPT_INFO:
394423
case runcpp2::PipelineResult::NO_AVAILABLE_PROFILE:
395424
case runcpp2::PipelineResult::DEPENDENCIES_FAILED:
396425
case runcpp2::PipelineResult::COMPILE_LINK_FAILED:
397426
case runcpp2::PipelineResult::INVALID_PROFILE:
398427
case runcpp2::PipelineResult::RUN_SCRIPT_FAILED:
428+
ssLOG_BASE("Watching...");
429+
break;
430+
case runcpp2::PipelineResult::SUCCESS:
431+
ssLOG_BASE("No error. Watching...");
399432
break;
400433
}
401-
ssLOG_BASE("No error. Watching...");
402434
}
403435

404436
lastScriptWriteTime = ghc::filesystem::last_write_time(script, e);

Src/runcpp2/runcpp2.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,14 @@ namespace
264264

265265
if(compileFiles == nullptr)
266266
{
267-
ssLOG_ERROR("Failed to get compile files for current platform");
268-
return false;
267+
ssLOG_INFO("No other files to be compiled files current platform");
268+
269+
if(!scriptInfo.OtherFilesToBeCompiled.empty())
270+
{
271+
ssLOG_WARNING( "Other source files are present, "
272+
"but none are included for current configuration. Is this intended?");
273+
}
274+
return true;
269275
}
270276

271277
std::string foundProfileName;

0 commit comments

Comments
 (0)