Introduce Debug::println()

This commit is contained in:
Alexander Karatarakis 2017-05-05 14:37:58 -07:00
parent e8c23168fa
commit 22848e4b7e
3 changed files with 49 additions and 13 deletions

View File

@ -40,25 +40,25 @@ namespace vcpkg::System
template<class Arg1, class... Args> template<class Arg1, class... Args>
void print(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) void print(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
{ {
return print(Strings::format(messageTemplate, messageArg1, messageArgs...)); return System::print(Strings::format(messageTemplate, messageArg1, messageArgs...));
} }
template<class Arg1, class... Args> template<class Arg1, class... Args>
void print(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) void print(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
{ {
return print(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); return System::print(c, Strings::format(messageTemplate, messageArg1, messageArgs...));
} }
template<class Arg1, class... Args> template<class Arg1, class... Args>
void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
{ {
return println(Strings::format(messageTemplate, messageArg1, messageArgs...)); return System::println(Strings::format(messageTemplate, messageArg1, messageArgs...));
} }
template<class Arg1, class... Args> template<class Arg1, class... Args>
void println(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs) void println(const Color c, const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
{ {
return println(c, Strings::format(messageTemplate, messageArg1, messageArgs...)); return System::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...));
} }
Optional<std::wstring> get_environment_variable(const CWStringView varname) noexcept; Optional<std::wstring> get_environment_variable(const CWStringView varname) noexcept;
@ -81,3 +81,24 @@ namespace vcpkg::System
const fs::path& get_ProgramFiles_platform_bitness(); const fs::path& get_ProgramFiles_platform_bitness();
} }
namespace vcpkg::Debug
{
void println(const CStringView message);
void println(const System::Color c, const CStringView message);
template<class Arg1, class... Args>
void println(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
{
return Debug::println(Strings::format(messageTemplate, messageArg1, messageArgs...));
}
template<class Arg1, class... Args>
void println(const System::Color c,
const char* messageTemplate,
const Arg1& messageArg1,
const Args&... messageArgs)
{
return Debug::println(c, Strings::format(messageTemplate, messageArg1, messageArgs...));
}
}

View File

@ -19,11 +19,7 @@ namespace vcpkg::Checks
[[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code) [[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code)
{ {
if (g_debugging) Debug::println(System::Color::error, line_info.to_string());
{
System::println(System::Color::error, line_info.to_string());
}
::exit(exit_code); ::exit(exit_code);
} }

View File

@ -115,10 +115,10 @@ namespace vcpkg::System
// Basically we are wrapping it in quotes // Basically we are wrapping it in quotes
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
if (g_debugging) System::println("[DEBUG] _wspawnlpe(cmd.exe /c %s)", Strings::to_utf8(actual_cmd_line)); Debug::println("_wspawnlpe(cmd.exe /c %s)", Strings::to_utf8(actual_cmd_line));
auto exit_code = auto exit_code =
_wspawnlpe(_P_WAIT, L"cmd.exe", L"cmd.exe", L"/c", actual_cmd_line.c_str(), nullptr, env_cstr.data()); _wspawnlpe(_P_WAIT, L"cmd.exe", L"cmd.exe", L"/c", actual_cmd_line.c_str(), nullptr, env_cstr.data());
if (g_debugging) System::println("[DEBUG] _wspawnlpe() returned %d", exit_code); Debug::println("_wspawnlpe() returned %d", exit_code);
return static_cast<int>(exit_code); return static_cast<int>(exit_code);
} }
@ -129,9 +129,9 @@ namespace vcpkg::System
// Basically we are wrapping it in quotes // Basically we are wrapping it in quotes
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
if (g_debugging) System::println("[DEBUG] _wsystem(%s)", Strings::to_utf8(actual_cmd_line)); Debug::println("_wsystem(%s)", Strings::to_utf8(actual_cmd_line));
int exit_code = _wsystem(actual_cmd_line.c_str()); int exit_code = _wsystem(actual_cmd_line.c_str());
if (g_debugging) System::println("[DEBUG] _wsystem() returned %d", exit_code); Debug::println("_wsystem() returned %d", exit_code);
return exit_code; return exit_code;
} }
@ -269,3 +269,22 @@ namespace vcpkg::System
return p; return p;
} }
} }
namespace vcpkg::Debug
{
void println(const CStringView message)
{
if (g_debugging)
{
System::println("[DEBUG] %s", message);
}
}
void println(const System::Color c, const CStringView message)
{
if (g_debugging)
{
System::println(c, "[DEBUG] %s", message);
}
}
}