diff options
author | Julien Marrec <julien.marrec@gmail.com> | 2020-03-23 12:16:39 (GMT) |
---|---|---|
committer | Julien Marrec <julien.marrec@gmail.com> | 2020-03-23 12:22:23 (GMT) |
commit | 905d5667e8b49a931078a1bcea26deffe703453b (patch) | |
tree | c42c663aaca77453350c5aac602ef0a4d3407995 /Tests/FindRuby | |
parent | e6699b9b59a12f6fda8f535d370453bb41f3acce (diff) | |
download | CMake-905d5667e8b49a931078a1bcea26deffe703453b.zip CMake-905d5667e8b49a931078a1bcea26deffe703453b.tar.gz CMake-905d5667e8b49a931078a1bcea26deffe703453b.tar.bz2 |
FindRuby: Add support for RVM installations
Diffstat (limited to 'Tests/FindRuby')
-rw-r--r-- | Tests/FindRuby/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/CMakeLists.txt | 75 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmDefault.cmake | 17 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmOnly.cmake | 41 | ||||
-rw-r--r-- | Tests/FindRuby/Rvm/RvmStandard.cmake | 9 |
5 files changed, 155 insertions, 0 deletions
diff --git a/Tests/FindRuby/CMakeLists.txt b/Tests/FindRuby/CMakeLists.txt index aaab839..3f4807c 100644 --- a/Tests/FindRuby/CMakeLists.txt +++ b/Tests/FindRuby/CMakeLists.txt @@ -41,4 +41,17 @@ if(CMake_TEST_FindRuby) set_tests_properties(FindRuby.FailExact PROPERTIES PASS_REGULAR_EXPRESSION "Could NOT find Ruby: Found unsuitable version \".*\", but required is.*exact version \"[0-9]+\\.[0-9]+\\.[0-9]+\" \\(found .*\\)") + # RVM specific test + if(CMake_TEST_FindRuby_RVM) + add_test(NAME FindRuby.Rvm COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindRuby/Rvm" + "${CMake_BINARY_DIR}/Tests/FindRuby/Rvm" + ${build_generator_args} + --build-project TestRVM + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) + endif() endif() diff --git a/Tests/FindRuby/Rvm/CMakeLists.txt b/Tests/FindRuby/Rvm/CMakeLists.txt new file mode 100644 index 0000000..545fc94 --- /dev/null +++ b/Tests/FindRuby/Rvm/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.17) +project(TestRVM LANGUAGES NONE) + +include(CTest) + +# To run this test, you need to have at least one RVM ruby installed +# and to ensure that the env variable 'MY_RUBY_HOME' is set to a valid RVM ruby when you run the test +# (which is the case if you have done `rvm use x.y.z`, but could be manually set too) + +# Properly using rvm would require sourcing a shell script, eg `source "$HOME/.rvm/scripts/rvm"` +# Instead, I'll just rely on the env variable MY_RUBY_HOME +set(MY_RUBY_HOME "$ENV{MY_RUBY_HOME}") +if(NOT MY_RUBY_HOME) + message(FATAL_ERROR "Env variable MY_RUBY_HOME should be set to a valid RVM ruby location, or you should call `rvm use x.y.z` before") +endif() +execute_process (COMMAND "${MY_RUBY_HOME}/bin/ruby" -e "puts RUBY_VERSION" + RESULT_VARIABLE result + OUTPUT_VARIABLE RVM_RUBY_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (result) + message (FATAL_ERROR "Unable to detect RVM ruby version from `${MY_RUBY_HOME}/bin/ruby`: ${RVM_RUBY_VERSION}") +endif() + +execute_process(COMMAND "${CMAKE_COMMAND}" -E env --unset=MY_RUBY_HOME --unset=PATH + "which" "ruby" + RESULT_VARIABLE result + OUTPUT_VARIABLE SYSTEM_RUBY + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (SYSTEM_RUBY MATCHES "^${MY_RUBY_HOME}/.+") + message(FATAL_ERROR "Unable to find system ruby, found ${SYSTEM_RUBY} which is part of MY_RUBY_HOME=${MY_RUBY_HOME}") +endif() + +# Check version of the system ruby executable. +execute_process (COMMAND "${SYSTEM_RUBY}" -e "puts RUBY_VERSION" + RESULT_VARIABLE result + OUTPUT_VARIABLE SYSTEM_RUBY_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (result) + message (FATAL_ERROR "Unable to detect system ruby version from '${SYSTEM_RUBY}': ${SYSTEM_RUBY_VERSION}") +endif() + +if(SYSTEM_RUBY_VERSION VERSION_EQUAL RVM_RUBY_VERSION) + message(FATAL_ERROR "Your RVM Ruby Version and your System ruby version are the same (${RVM_RUBY_VERSION}).") +endif() + +message("Found System Ruby (${SYSTEM_RUBY_VERSION}): ${SYSTEM_RUBY}") +message("Found RVM Ruby (${RVM_RUBY_VERSION}): ${MY_RUBY_HOME}/bin/ruby") + +add_test(NAME FindRuby.RvmDefault + COMMAND "${CMAKE_COMMAND}" -E env "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmDefault.cmake") + +add_test(NAME FindRuby.RvmOnly + COMMAND "${CMAKE_COMMAND}" -E env --unset=PATH + "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + "-DRVM_RUBY_VERSION=${RVM_RUBY_VERSION}" "-DSYSTEM_RUBY_VERSION=${SYSTEM_RUBY_VERSION}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmOnly.cmake") +add_test(NAME FindRuby.UnsetRvmOnly + COMMAND "${CMAKE_COMMAND}" -E env --unset=MY_RUBY_HOME "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" + "${CMAKE_COMMAND}" "-DRVM_RUBY_VERSION=${RVM_RUBY_VERSION}" "-DSYSTEM_RUBY_VERSION=${SYSTEM_RUBY_VERSION}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmOnly.cmake") + +add_test(NAME FindRuby.RvmStandard + COMMAND "${CMAKE_COMMAND}" -E env "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" + "MY_RUBY_HOME=${MY_RUBY_HOME}" + "${CMAKE_COMMAND}" "-DRUBY_HOME=${MY_RUBY_HOME}" + -P "${CMAKE_CURRENT_LIST_DIR}/RvmStandard.cmake") diff --git a/Tests/FindRuby/Rvm/RvmDefault.cmake b/Tests/FindRuby/Rvm/RvmDefault.cmake new file mode 100644 index 0000000..a66b911 --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmDefault.cmake @@ -0,0 +1,17 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +find_package (Ruby 2.1.1 REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() + +find_package (Ruby 2.1 REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() + +find_package (Ruby REQUIRED) +if (NOT RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "Failed to use RVM environment: ${RUBY_EXECUTABLE}, ${RUBY_HOME}") +endif() diff --git a/Tests/FindRuby/Rvm/RvmOnly.cmake b/Tests/FindRuby/Rvm/RvmOnly.cmake new file mode 100644 index 0000000..3851a7c --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmOnly.cmake @@ -0,0 +1,41 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +set(Ruby_FIND_VIRTUALENV ONLY) + +# Test: FindRuby.RvmOnly +if (RUBY_HOME) + # => Trying to find exactly system ruby using ONLY virtual environment should fail + find_package (Ruby ${SYSTEM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message (FATAL_ERROR "Ruby unexpectedly found.") + endif() + # And should work to find the rvm version + find_package (Ruby ${RVM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message (FATAL_ERROR "Ruby unexpectedly found.") + endif() +endif() + + +# Test: FindRuby.UnsetRvmOnly +if (NOT RUBY_HOME) + + # If ENV{MY_RUBY_HOME} isn't defined, it should default back to "STANDARD" + # At which point: + + # It shouldn't find the RVM ruby + find_package (Ruby ${RVM_RUBY_VERSION} EXACT QUIET) + if(Ruby_FOUND) + message(FATAL_ERROR "Found RVM ruby when expecting system") + endif() + + # it should find the system ruby + find_package (Ruby ${SYSTEM_RUBY_VERSION} EXACT QUIET) + if(NOT Ruby_FOUND) + message (FATAL_ERROR "Ruby not found.") + endif() + if (Ruby_FOUND MATCHES "^${RUBY_HOME}/.+") + message(FATAL_ERROR "Failed to find system ruby") + endif() +endif() diff --git a/Tests/FindRuby/Rvm/RvmStandard.cmake b/Tests/FindRuby/Rvm/RvmStandard.cmake new file mode 100644 index 0000000..26befdb7 --- /dev/null +++ b/Tests/FindRuby/Rvm/RvmStandard.cmake @@ -0,0 +1,9 @@ +set(CMAKE_FIND_LIBRARY_PREFIXES "") +set(CMAKE_FIND_LIBRARY_SUFFIXES "") + +set (Ruby_FIND_VIRTUALENV STANDARD) +find_package (Ruby REQUIRED) + +if (RUBY_EXECUTABLE MATCHES "^${RUBY_HOME}/.+") + message (FATAL_ERROR "RVM ruby unexpectedly found at ${RUBY_EXECUTABLE}, matches ${RUBY_HOME}") +endif() |