2016-09-18 20:50:08 -07:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-13 18:37:41 -07:00
|
|
|
#include <vcpkg/base/cstringview.h>
|
|
|
|
#include <vcpkg/base/lineinfo.h>
|
|
|
|
#include <vcpkg/base/strings.h>
|
2017-03-13 16:04:29 -07:00
|
|
|
|
2017-01-05 12:47:08 -08:00
|
|
|
namespace vcpkg::Checks
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
2017-08-23 16:47:54 -07:00
|
|
|
void register_console_ctrl_handler();
|
|
|
|
|
2017-08-18 20:32:35 -07:00
|
|
|
// Indicate that an internal error has occurred and exit the tool. This should be used when invariants have been
|
|
|
|
// broken.
|
2017-04-27 17:56:06 -07:00
|
|
|
[[noreturn]] void unreachable(const LineInfo& line_info);
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2017-04-27 17:56:06 -07:00
|
|
|
[[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code);
|
2017-03-22 17:08:59 -07:00
|
|
|
|
2017-08-18 20:32:35 -07:00
|
|
|
// Exit the tool without an error message.
|
2017-04-27 17:56:06 -07:00
|
|
|
[[noreturn]] inline void exit_fail(const LineInfo& line_info) { exit_with_code(line_info, EXIT_FAILURE); }
|
2017-03-22 17:08:59 -07:00
|
|
|
|
2017-08-18 20:32:35 -07:00
|
|
|
// Exit the tool successfully.
|
2017-04-27 17:56:06 -07:00
|
|
|
[[noreturn]] inline void exit_success(const LineInfo& line_info) { exit_with_code(line_info, EXIT_SUCCESS); }
|
2017-03-22 17:08:59 -07:00
|
|
|
|
2017-08-18 20:32:35 -07:00
|
|
|
// Display an error message to the user and exit the tool.
|
2017-09-01 17:05:22 -07:00
|
|
|
[[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView error_message);
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2017-04-27 17:56:06 -07:00
|
|
|
template<class Arg1, class... Args>
|
2017-08-18 20:32:35 -07:00
|
|
|
// Display an error message to the user and exit the tool.
|
2017-04-27 17:56:06 -07:00
|
|
|
[[noreturn]] void exit_with_message(const LineInfo& line_info,
|
2017-09-01 17:05:22 -07:00
|
|
|
const char* error_message_template,
|
|
|
|
const Arg1 error_message_arg1,
|
|
|
|
const Args&... error_message_args)
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
2017-09-01 17:05:22 -07:00
|
|
|
exit_with_message(line_info,
|
|
|
|
Strings::format(error_message_template, error_message_arg1, error_message_args...));
|
2016-09-18 20:50:08 -07:00
|
|
|
}
|
|
|
|
|
2017-03-13 17:38:04 -07:00
|
|
|
void check_exit(const LineInfo& line_info, bool expression);
|
2017-02-10 16:51:36 -08:00
|
|
|
|
2017-09-01 17:05:22 -07:00
|
|
|
void check_exit(const LineInfo& line_info, bool expression, const CStringView error_message);
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2017-04-28 17:27:07 -07:00
|
|
|
template<class Conditional, class Arg1, class... Args>
|
2017-04-27 17:56:06 -07:00
|
|
|
void check_exit(const LineInfo& line_info,
|
2017-04-28 17:27:07 -07:00
|
|
|
Conditional&& expression,
|
2017-09-01 17:05:22 -07:00
|
|
|
const char* error_message_template,
|
|
|
|
const Arg1 error_message_arg1,
|
|
|
|
const Args&... error_message_args)
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
|
|
|
// Only create the string if the expression is false
|
2017-09-01 17:05:22 -07:00
|
|
|
exit_with_message(line_info,
|
|
|
|
Strings::format(error_message_template, error_message_arg1, error_message_args...));
|
2016-09-18 20:50:08 -07:00
|
|
|
}
|
|
|
|
}
|
2017-01-05 12:47:08 -08:00
|
|
|
}
|