From b2ae75acd8a3e7e7f573a5010b27e9cd1a96fde2 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 6 Dec 2019 20:55:36 -0800 Subject: [PATCH] Add way to disable "no extensions found" message (#2134) We want it enabled by default, but there have been requests for a way to disable it. --- hal/src/main/native/include/hal/Extensions.h | 18 +++++++++++++++++- hal/src/main/native/sim/Extensions.cpp | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/hal/src/main/native/include/hal/Extensions.h b/hal/src/main/native/include/hal/Extensions.h index 0fcbcba509..3a435c08da 100644 --- a/hal/src/main/native/include/hal/Extensions.h +++ b/hal/src/main/native/include/hal/Extensions.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,6 +7,8 @@ #pragma once +#include "hal/Types.h" + /** * @defgroup hal_extensions Simulator Extensions * @ingroup hal_capi @@ -41,5 +43,19 @@ int HAL_LoadOneExtension(const char* library); * @return the succes state of the initialization */ int HAL_LoadExtensions(void); + +/** + * Enables or disables the message saying no HAL extensions were found. + * + * Some apps don't care, and the message create clutter. For general team code, + * we want it. + * + * This must be called before HAL_Initialize is called. + * + * This defaults to true. + * + * @param showMessage true to show message, false to not. + */ +void HAL_SetShowExtensionsNotFoundMessages(HAL_Bool showMessage); } // extern "C" /** @} */ diff --git a/hal/src/main/native/sim/Extensions.cpp b/hal/src/main/native/sim/Extensions.cpp index e84c354c27..951ad10426 100644 --- a/hal/src/main/native/sim/Extensions.cpp +++ b/hal/src/main/native/sim/Extensions.cpp @@ -41,6 +41,11 @@ void InitializeExtensions() {} } // namespace init } // namespace hal +static bool& GetShowNotFoundMessage() { + static bool showMsg = true; + return showMsg; +} + extern "C" { int HAL_LoadOneExtension(const char* library) { @@ -91,8 +96,10 @@ int HAL_LoadExtensions(void) { wpi::SmallVector libraries; const char* e = std::getenv("HALSIM_EXTENSIONS"); if (!e) { - wpi::outs() << "HAL Extensions: No extensions found\n"; - wpi::outs().flush(); + if (GetShowNotFoundMessage()) { + wpi::outs() << "HAL Extensions: No extensions found\n"; + wpi::outs().flush(); + } return rc; } wpi::StringRef env{e}; @@ -105,4 +112,8 @@ int HAL_LoadExtensions(void) { return rc; } +void HAL_SetShowExtensionsNotFoundMessages(HAL_Bool showMessage) { + GetShowNotFoundMessage() = showMessage; +} + } // extern "C"