mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 08:27:05 +00:00
Set default CRTReportMode for the flatc target (#5336)
* Set default CRTReportMode for the `flatc` target * Add util.cpp to GRPC test target * Fix path to util.h
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
f9ebfcb9c4
commit
107c08988a
1
BUILD
1
BUILD
@@ -96,6 +96,7 @@ cc_binary(
|
|||||||
"src/idl_gen_python.cpp",
|
"src/idl_gen_python.cpp",
|
||||||
"src/idl_gen_rust.cpp",
|
"src/idl_gen_rust.cpp",
|
||||||
"src/idl_gen_text.cpp",
|
"src/idl_gen_text.cpp",
|
||||||
|
"src/util.cpp",
|
||||||
],
|
],
|
||||||
includes = [
|
includes = [
|
||||||
"grpc/",
|
"grpc/",
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ set(FlatBuffers_Sample_BFBS_SRCS
|
|||||||
set(FlatBuffers_GRPCTest_SRCS
|
set(FlatBuffers_GRPCTest_SRCS
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
include/flatbuffers/grpc.h
|
include/flatbuffers/grpc.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
src/util.cpp
|
||||||
tests/monster_test.grpc.fb.h
|
tests/monster_test.grpc.fb.h
|
||||||
tests/test_assert.h
|
tests/test_assert.h
|
||||||
tests/test_builder.h
|
tests/test_builder.h
|
||||||
|
|||||||
@@ -649,6 +649,9 @@ bool SetGlobalTestLocale(const char *locale_name,
|
|||||||
bool ReadEnvironmentVariable(const char *var_name,
|
bool ReadEnvironmentVariable(const char *var_name,
|
||||||
std::string *_value = nullptr);
|
std::string *_value = nullptr);
|
||||||
|
|
||||||
|
// MSVC specific: Send all assert reports to STDOUT to prevent CI hangs.
|
||||||
|
void SetupDefaultCRTReportMode();
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
#endif // FLATBUFFERS_UTIL_H_
|
#endif // FLATBUFFERS_UTIL_H_
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "flatbuffers/flatc.h"
|
#include "flatbuffers/flatc.h"
|
||||||
|
#include "flatbuffers/util.h"
|
||||||
|
|
||||||
static const char *g_program_name = nullptr;
|
static const char *g_program_name = nullptr;
|
||||||
|
|
||||||
@@ -34,6 +35,9 @@ static void Error(const flatbuffers::FlatCompiler *flatc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
|
// Prevent Appveyor-CI hangs.
|
||||||
|
flatbuffers::SetupDefaultCRTReportMode();
|
||||||
|
|
||||||
g_program_name = argv[0];
|
g_program_name = argv[0];
|
||||||
|
|
||||||
const flatbuffers::FlatCompiler::Generator generators[] = {
|
const flatbuffers::FlatCompiler::Generator generators[] = {
|
||||||
|
|||||||
25
src/util.cpp
25
src/util.cpp
@@ -23,6 +23,7 @@
|
|||||||
# ifndef NOMINMAX
|
# ifndef NOMINMAX
|
||||||
# define NOMINMAX
|
# define NOMINMAX
|
||||||
# endif
|
# endif
|
||||||
|
# include <crtdbg.h>
|
||||||
# include <windows.h> // Must be included before <direct.h>
|
# include <windows.h> // Must be included before <direct.h>
|
||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
# include <winbase.h>
|
# include <winbase.h>
|
||||||
@@ -235,6 +236,7 @@ bool SetGlobalTestLocale(const char *locale_name, std::string *_value) {
|
|||||||
if (_value) *_value = std::string(the_locale);
|
if (_value) *_value = std::string(the_locale);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadEnvironmentVariable(const char *var_name, std::string *_value) {
|
bool ReadEnvironmentVariable(const char *var_name, std::string *_value) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
__pragma(warning(disable : 4996)); // _CRT_SECURE_NO_WARNINGS
|
__pragma(warning(disable : 4996)); // _CRT_SECURE_NO_WARNINGS
|
||||||
@@ -245,4 +247,27 @@ bool ReadEnvironmentVariable(const char *var_name, std::string *_value) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupDefaultCRTReportMode() {
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
// By default, send all reports to STDOUT to prevent CI hangs.
|
||||||
|
// Enable assert report box [Abort|Retry|Ignore] if a debugger is present.
|
||||||
|
const int dbg_mode = (_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG) |
|
||||||
|
(IsDebuggerPresent() ? _CRTDBG_MODE_WNDW : 0);
|
||||||
|
(void)dbg_mode; // release mode fix
|
||||||
|
// CrtDebug reports to _CRT_WARN channel.
|
||||||
|
_CrtSetReportMode(_CRT_WARN, dbg_mode);
|
||||||
|
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
|
||||||
|
// The assert from <assert.h> reports to _CRT_ERROR channel
|
||||||
|
_CrtSetReportMode(_CRT_ERROR, dbg_mode);
|
||||||
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
|
||||||
|
// Internal CRT assert channel?
|
||||||
|
_CrtSetReportMode(_CRT_ASSERT, dbg_mode);
|
||||||
|
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|||||||
@@ -41,24 +41,9 @@ void InitTestEngine(TestFailEventListener listener) {
|
|||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
|
||||||
// clang-format off
|
flatbuffers::SetupDefaultCRTReportMode();
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
// clang-format off
|
||||||
// By default, send all reports to STDOUT to prevent CI hangs.
|
|
||||||
// Enable assert report box [Abort|Retry|Ignore] if a debugger is present.
|
|
||||||
const int dbg_mode = (_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG) |
|
|
||||||
(IsDebuggerPresent() ? _CRTDBG_MODE_WNDW : 0);
|
|
||||||
(void)dbg_mode; // release mode fix
|
|
||||||
// CrtDebug reports to _CRT_WARN channel.
|
|
||||||
_CrtSetReportMode(_CRT_WARN, dbg_mode);
|
|
||||||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
|
|
||||||
// The assert from <assert.h> reports to _CRT_ERROR channel
|
|
||||||
_CrtSetReportMode(_CRT_ERROR, dbg_mode);
|
|
||||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
|
|
||||||
// Internal CRT assert channel?
|
|
||||||
_CrtSetReportMode(_CRT_ASSERT, dbg_mode);
|
|
||||||
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
||||||
// For more thorough checking:
|
// For more thorough checking:
|
||||||
|
|||||||
Reference in New Issue
Block a user