diff options
| author | jasjuang <jasjuang@gmail.com> | 2017-09-22 08:16:32 -0700 |
|---|---|---|
| committer | jasjuang <jasjuang@gmail.com> | 2017-09-22 08:16:32 -0700 |
| commit | f643a8422f87c5a16e3cc77e3e321e34a45f7103 (patch) | |
| tree | 419c9a2e74ab577aab0e868441b9a0e4c15d4919 /toolsrc/src/vcpkg_Checks.cpp | |
| parent | 9989177fed607cdc9e20127ff7c22e3266e7c913 (diff) | |
| parent | fac96eb344a500405ab65b7e7f3755af0ad00b7e (diff) | |
| download | vcpkg-f643a8422f87c5a16e3cc77e3e321e34a45f7103.tar.gz vcpkg-f643a8422f87c5a16e3cc77e3e321e34a45f7103.zip | |
Merge branch 'master' of https://github.com/jasjuang/vcpkg
Diffstat (limited to 'toolsrc/src/vcpkg_Checks.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg_Checks.cpp | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 2674b889a..e7c9046a4 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -1,11 +1,45 @@ #include "pch.h" +#include "metrics.h" #include "vcpkg_Checks.h" +#include "vcpkg_GlobalState.h" #include "vcpkg_System.h" #include "vcpkglib.h" namespace vcpkg::Checks { + [[noreturn]] static void cleanup_and_exit(const int exit_code) + { + const auto elapsed_us = GlobalState::timer.lock()->microseconds(); + + auto metrics = Metrics::g_metrics.lock(); + metrics->track_metric("elapsed_us", elapsed_us); + GlobalState::debugging = false; + metrics->flush(); + + SetConsoleCP(GlobalState::g_init_console_cp); + SetConsoleOutputCP(GlobalState::g_init_console_output_cp); + + fflush(nullptr); + + ::TerminateProcess(::GetCurrentProcess(), exit_code); + } + + static BOOL ctrl_handler(DWORD fdw_ctrl_type) + { + { + auto locked_metrics = Metrics::g_metrics.lock(); + locked_metrics->track_property("CtrlHandler", std::to_string(fdw_ctrl_type)); + locked_metrics->track_property("error", "CtrlHandler was fired."); + } + cleanup_and_exit(EXIT_FAILURE); + } + + void register_console_ctrl_handler() + { + SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(ctrl_handler), TRUE); + } + [[noreturn]] void unreachable(const LineInfo& line_info) { System::println(System::Color::error, "Error: Unreachable code was reached"); @@ -13,19 +47,19 @@ namespace vcpkg::Checks #ifndef NDEBUG std::abort(); #else - ::exit(EXIT_FAILURE); + cleanup_and_exit(EXIT_FAILURE); #endif } [[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code) { Debug::println(System::Color::error, line_info.to_string()); - ::exit(exit_code); + cleanup_and_exit(exit_code); } - [[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView errorMessage) + [[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView error_message) { - System::println(System::Color::error, errorMessage); + System::println(System::Color::error, error_message); exit_fail(line_info); } @@ -33,15 +67,15 @@ namespace vcpkg::Checks { if (!expression) { - exit_with_message(line_info, ""); + exit_with_message(line_info, Strings::EMPTY); } } - void check_exit(const LineInfo& line_info, bool expression, const CStringView errorMessage) + void check_exit(const LineInfo& line_info, bool expression, const CStringView error_message) { if (!expression) { - exit_with_message(line_info, errorMessage); + exit_with_message(line_info, error_message); } } } |
