Skip to content

build: made environment access a separate feature#26331

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
mshabunin:fix-unified-getenv
Nov 5, 2024
Merged

build: made environment access a separate feature#26331
asmorkalov merged 1 commit intoopencv:4.xfrom
mshabunin:fix-unified-getenv

Conversation

@mshabunin
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin commented Oct 17, 2024

  • changed second argument of the getConfigurationParameterString to std::string from const char*, technically this breaks the ABI, but the function is private
  • added cvtest::addDataSearchEnv function to replace repetative blocks with getenv + addDataSearchPath
  • added call to getConfigurationParameterString to the gapi module, this change presumably conflicts with standalone build, but can be fixed if needed
  • in some cases "unset" and empty environment variables could be treated differently, but I haven't found where it is really useful. Both paths essentially produced the same effect, so I beleive processing them as a single case var.isEmpty() should be OK.
  • in some cases we just checked environment variables for non-null (i.e. set), this has changed to bool processing (e.g. 1, true - turn ON, 0, false - turn OFF). This is also changed beokhavior.
  • changed videoio plugin code for loading FFmpeg on Windows (OPENCV_FFMPEG_DLL_DIR) - it used _wgetenv with wchar_t* result, but I've changed it to our function returning std::string, I'm not sure if it affects unicode paths support (they might use UTF-8)
  • when new option OPENCV_DISABLE_ENV_SUPPORT is set to ON, just one file will be compiled with NO_GETENV macro enabled, all 3rdparty libraries will not be affected, I'm not sure if it is OK behavior or not.

@mshabunin mshabunin marked this pull request as ready for review October 30, 2024 15:37
static int use_legacy = -1;
if (use_legacy < 0)
{
use_legacy = getenv("OPENCV_LEGACY_WAITKEY") != NULL ? 1 : 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to drop it in 5.x

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but this PR is for 4.x, so we'll need to remove it after these changes make their way to 5.x.

}


static const bool gs_verbose = utils::getConfigurationParameterBool("OPENCV_DSHOW_DEBUG");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use generic logging here with default environment variables.

Comment on lines +931 to +932
const bool debug_option = utils::getConfigurationParameterBool("OPENCV_FFMPEG_DEBUG");
std::string level_option = utils::getConfigurationParameterString("OPENCV_FFMPEG_LOGLEVEL");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use generic logging here with default environment variables.

OCV_OPTION(OPENCV_ENABLE_MEMALIGN "Enable posix_memalign or memalign usage" ON)
OCV_OPTION(OPENCV_DISABLE_FILESYSTEM_SUPPORT "Disable filesystem support" OFF)
OCV_OPTION(OPENCV_DISABLE_THREAD_SUPPORT "Build the library without multi-threaded code." OFF)
OCV_OPTION(OPENCV_DISABLE_ENV_SUPPORT "Disable environment variables access (getenv)" (CMAKE_SYSTEM_NAME MATCHES "Windows(CE|Phone|Store)"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS and derivatives?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, it seems that we have no any specific handling for iOS. Perhaps this platform supports environment variables. If Apple compiler defines NO_GETENV, then it would automatically disable our getenv support even if cmake option is turned OFF.

@asmorkalov asmorkalov added this to the 4.11.0 milestone Nov 2, 2024
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thank you!

@asmorkalov asmorkalov merged commit c287423 into opencv:4.x Nov 5, 2024
@mshabunin mshabunin deleted the fix-unified-getenv branch November 5, 2024 09:35
@asmorkalov asmorkalov mentioned this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants