diff --git a/CMakeLists.txt b/CMakeLists.txt index 719d8b1784..6d2934362e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,12 @@ 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 + REQUIRED + PKGCONFIG "ignition-tools") + #-------------------------------------- # 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/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index 594e360763..079bfeae19 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 @@ -435,6 +446,12 @@ class Cmd # 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. +See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." + exit(-1) + end + serverPid = Process.fork do ENV['RMT_PORT'] = '1500' Process.setpgid(0, 0) @@ -484,6 +501,12 @@ class Cmd 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. +See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." + exit(-1) + end + ENV['RMT_PORT'] = '1501' Importer.runGui(options['gui_config']) end 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(); -}