Tests/RunCMake/FindRuby: Use environment as of test time, not configure time

Revise commit a9ded64779 (FindRuby: Convert tests to RunCMake, 2026-01-15).
This commit is contained in:
Brad King
2026-01-23 10:22:48 -05:00
parent ebf93da48b
commit a436fbdbc2
2 changed files with 7 additions and 6 deletions

View File

@@ -503,8 +503,7 @@ if(CMake_TEST_FindRuby)
add_RunCMake_test(FindRuby
-DCMake_TEST_FindRuby_RBENV=${CMake_TEST_FindRuby_RBENV}
-DCMake_TEST_FindRuby_RVM=${CMake_TEST_FindRuby_RVM}
-DRBENV_ROOT=$ENV{RBENV_ROOT}
-DMY_RUBY_HOME=$ENV{MY_RUBY_HOME})
)
endif()
add_RunCMake_test(FindOpenGL)
add_RunCMake_test(InitialFlags)

View File

@@ -7,7 +7,10 @@ run_cmake(System/FailExact)
# RBENV specific tests
if(CMake_TEST_FindRuby_RBENV)
set(ENV{RBENV_ROOT} "${RBENV_ROOT}")
set(RBENV_ROOT "$ENV{RBENV_ROOT}")
if(NOT IS_DIRECTORY "${RBENV_ROOT}")
message(FATAL_ERROR "RBENV_ROOT should be set to a valid rbenv ruby location")
endif()
# Test environment has RBENV_ROOT setup
find_program(rbenv
@@ -82,12 +85,11 @@ endif()
if(CMake_TEST_FindRuby_RVM)
# Properly using rvm would require sourcing a shell script, eg `source "$HOME/.rvm/scripts/rvm"`
# Instead, we just rely on the env variable MY_RUBY_HOME
if(NOT MY_RUBY_HOME)
set(MY_RUBY_HOME "$ENV{MY_RUBY_HOME}")
if(NOT IS_DIRECTORY "${MY_RUBY_HOME}")
message(FATAL_ERROR "MY_RUBY_HOME should be set to a valid RVM ruby location, or you should call `rvm use x.y.z` before")
endif()
set(ENV{MY_RUBY_HOME} "${MY_RUBY_HOME}")
execute_process(COMMAND "${MY_RUBY_HOME}/bin/ruby" -e "puts RUBY_VERSION"
RESULT_VARIABLE result
OUTPUT_VARIABLE RVM_RUBY_VERSION