2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
#include "vcpkg_Checks.h"
|
|
|
|
#include "vcpkg_System.h"
|
2017-03-14 07:59:21 +08:00
|
|
|
#include "vcpkglib.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-01-06 04:47:08 +08:00
|
|
|
namespace vcpkg::Checks
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
static void print_line_info_if_debug(const LineInfo& line_info)
|
|
|
|
{
|
|
|
|
if (g_debugging)
|
|
|
|
{
|
|
|
|
System::println(System::color::error, line_info.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 07:59:21 +08:00
|
|
|
__declspec(noreturn) void unreachable(const LineInfo& line_info)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
System::println(System::color::error, "Error: Unreachable code was reached");
|
2017-03-14 07:59:21 +08:00
|
|
|
System::println(System::color::error, line_info.toString()); // Always print line_info here
|
2016-11-05 16:02:15 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
std::abort();
|
2016-11-16 09:54:44 +08:00
|
|
|
#else
|
2016-09-19 11:50:08 +08:00
|
|
|
exit(EXIT_FAILURE);
|
2016-11-16 09:54:44 +08:00
|
|
|
#endif
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 08:08:59 +08:00
|
|
|
void exit_with_code(const LineInfo& line_info, const int exit_code)
|
|
|
|
{
|
|
|
|
print_line_info_if_debug(line_info);
|
|
|
|
exit(exit_code);
|
|
|
|
}
|
|
|
|
|
2017-03-14 08:38:04 +08:00
|
|
|
__declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessage)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
System::println(System::color::error, errorMessage);
|
2017-03-23 08:34:17 +08:00
|
|
|
exit_fail(line_info);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-03-14 08:38:04 +08:00
|
|
|
__declspec(noreturn) void throw_with_message(const LineInfo& line_info, const char* errorMessage)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
print_line_info_if_debug(line_info);
|
2016-09-19 11:50:08 +08:00
|
|
|
throw std::runtime_error(errorMessage);
|
|
|
|
}
|
|
|
|
|
2017-03-14 08:38:04 +08:00
|
|
|
void check_throw(const LineInfo& line_info, bool expression, const char* errorMessage)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
throw_with_message(line_info, errorMessage);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 08:38:04 +08:00
|
|
|
void check_exit(const LineInfo& line_info, bool expression)
|
2017-02-11 08:51:36 +08:00
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
exit_with_message(line_info, "");
|
2017-02-11 08:51:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-14 08:38:04 +08:00
|
|
|
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessage)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
2017-03-14 08:38:04 +08:00
|
|
|
exit_with_message(line_info, errorMessage);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
2017-01-06 04:47:08 +08:00
|
|
|
}
|