From c1bc06b204c277e0ac8a6fdd5ecbe747e0205242 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 8 Dec 2020 14:48:06 -0800 Subject: [PATCH 1/4] Enable ign test on macOS This enables and fixes UNIT_ign_TEST for macOS. * Set environment variables in cmake * Find ign binary location * Try to find brew ruby location to workaround SIP Signed-off-by: Steve Peters --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ src/ign_TEST.cc | 22 ++-------------------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71860c9abe..440d34e077 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,10 @@ set(IGN_RENDERING_VER ${ignition-rendering4_VERSION_MAJOR}) ign_find_package(ignition-math6 REQUIRED COMPONENTS eigen3 VERSION 6.6) set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR}) +#-------------------------------------- +# Find ignition-tools +ign_find_package(ignition-tools QUIET) + #-------------------------------------- # Find protobuf set(REQ_PROTOBUF_VER 3) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c029e2900..9cff6aa9b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,6 +131,36 @@ ign_build_tests(TYPE UNIT ignition-gazebo${PROJECT_VERSION_MAJOR} ) +if(TARGET UNIT_ign_TEST) + + # Running `ign gazebo` on macOS has problems when run with /usr/bin/ruby + # due to System Integrity Protection (SIP). Try to find ruby from + # homebrew as a workaround. + if (APPLE) + find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin) + endif() + + add_dependencies(UNIT_ign_TEST + ${ign_lib_target} + TestModelSystem + TestSensorSystem + TestWorldSystem + ) + + target_compile_definitions(UNIT_ign_TEST PRIVATE + "BREW_RUBY=\"${BREW_RUBY} \"") + + target_compile_definitions(UNIT_ign_TEST PRIVATE + "IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"") + + set(_env_vars) + list(APPEND _env_vars "IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf") + list(APPEND _env_vars "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$") + + set_tests_properties(UNIT_ign_TEST PROPERTIES + ENVIRONMENT "${_env_vars}") +endif() + if(NOT WIN32) add_subdirectory(cmd) endif() diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index c5d0fcdc7f..8bb0986e9d 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -26,12 +26,8 @@ static const std::string kBinPath(PROJECT_BINARY_PATH); -// Command line not working on OSX, see -// https://github.com/ignitionrobotics/ign-gazebo/issues/25/ -#ifndef __APPLE__ static const std::string kIgnCommand( - "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=" + kBinPath + "/lib LD_LIBRARY_PATH=" + - kBinPath + "/lib:/usr/local/lib:${LD_LIBRARY_PATH} ign gazebo -s "); + std::string(BREW_RUBY) + std::string(IGN_PATH) + "/ign gazebo -s "); ///////////////////////////////////////////////// std::string customExecStr(std::string _cmd) @@ -90,8 +86,7 @@ TEST(CmdLine, Server) } ///////////////////////////////////////////////// -// Not supported on Mac's command line tool -TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_MAC(CachedFuelWorld)) +TEST(CmdLine, CachedFuelWorld) { std::string projectPath = std::string(PROJECT_SOURCE_PATH) + "/test/worlds"; setenv("IGN_FUEL_CACHE_PATH", projectPath.c_str(), true); @@ -164,16 +159,3 @@ TEST(CmdLine, ResourcePath) EXPECT_EQ(output.find("Unable to find file plugins.sdf"), std::string::npos) << output; } -#endif - -///////////////////////////////////////////////// -/// Main -int main(int _argc, char **_argv) -{ - // Set IGN_CONFIG_PATH to the directory where the .yaml configuration files - // is located. - setenv("IGN_CONFIG_PATH", IGN_CONFIG_PATH, 1); - - ::testing::InitGoogleTest(&_argc, _argv); - return RUN_ALL_TESTS(); -} From 20331b89c4fa8f78e909e005a3b05e9edf207eac Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 8 Dec 2020 18:04:37 -0800 Subject: [PATCH 2/4] Suggest fixes for ign gazebo failures on macOS Recommend using brew ruby and ensuring that colcon setup scripts have been sourced. Signed-off-by: Steve Peters --- src/cmd/cmdgazebo.rb.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index 594e360763..12cb744884 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -337,6 +337,17 @@ class Cmd Importer.dlload plugin rescue DLError => e puts "Library error for [#{plugin}]: #{e.to_s}" + if plugin.end_with? ".dylib" + puts " +If this script was executed with /usr/bin/ruby, this error may be caused by +macOS System Integrity Protection. One workaround is to use a different +version of ruby, for example: + brew install ruby +and add the following line to your shell profile: + export PATH=/usr/local/opt/ruby/bin:$PATH +If you are using a colcon workspace, please ensure that the setup script +has properly set the DYLD_LIBRARY_PATH environment variables." + end exit(-1) end From 182bee124e6188c4c78eb530d751b1572c61d514 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 8 Dec 2020 22:19:24 -0800 Subject: [PATCH 3/4] Exit `ign gazebo` early on macOS unless -s is used Signed-off-by: Steve Peters --- src/cmd/cmdgazebo.rb.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index 12cb744884..da91c4c2b7 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -446,6 +446,11 @@ has properly set the DYLD_LIBRARY_PATH environment variables." # and gui. if options['server'] == 0 && options['gui'] == 0 + if plugin.end_with? ".dylib" + puts "`ign gazebo` currently only works with the -s argument on macOS." + exit(-1) + end + serverPid = Process.fork do ENV['RMT_PORT'] = '1500' Process.setpgid(0, 0) @@ -495,6 +500,11 @@ has properly set the DYLD_LIBRARY_PATH environment variables." options['file'], options['record-topics'].join(':')) # Otherwise run the gui else options['gui'] + if plugin.end_with? ".dylib" + puts "`ign gazebo` currently only works with the -s argument on macOS." + exit(-1) + end + ENV['RMT_PORT'] = '1501' Importer.runGui(options['gui_config']) end From 0dfa9aa175adf053c068ac087e8311b09e9897ad Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Tue, 15 Dec 2020 00:30:38 -0800 Subject: [PATCH 4/4] Find ign-tools properly and add link to #44 Signed-off-by: Steve Peters --- CMakeLists.txt | 4 +++- src/cmd/cmdgazebo.rb.in | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 440d34e077..fc9f3417ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,9 @@ set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR}) #-------------------------------------- # Find ignition-tools -ign_find_package(ignition-tools QUIET) +ign_find_package(ignition-tools + REQUIRED + PKGCONFIG "ignition-tools") #-------------------------------------- # Find protobuf diff --git a/src/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index da91c4c2b7..079bfeae19 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -447,7 +447,8 @@ has properly set the DYLD_LIBRARY_PATH environment variables." if options['server'] == 0 && options['gui'] == 0 if plugin.end_with? ".dylib" - puts "`ign gazebo` currently only works with the -s argument on macOS." + puts "`ign gazebo` currently only works with the -s argument on macOS. +See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." exit(-1) end @@ -501,7 +502,8 @@ has properly set the DYLD_LIBRARY_PATH environment variables." # Otherwise run the gui else options['gui'] if plugin.end_with? ".dylib" - puts "`ign gazebo` currently only works with the -s argument on macOS." + puts "`ign gazebo` currently only works with the -s argument on macOS. +See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." exit(-1) end