From 3c096620dd697ded59d002ee97193dfc75bb7d0b Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Mon, 11 Jan 2021 10:48:06 -0800 Subject: [PATCH] Improve ign tool support on macOS (#477) Signed-off-by: Louise Poubel --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ src/cmd/cmdgazebo.rb.in | 23 +++++++++++++++++++++++ src/ign_TEST.cc | 22 ++-------------------- 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4b9575c9..75e6370f28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,12 @@ set(IGN_RENDERING_VER ${ignition-rendering3_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 078c1b4bcf..d529e58d9e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,6 +132,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 0baa713665..30f783c6eb 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -338,6 +338,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 @@ -436,6 +447,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) @@ -485,6 +502,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 0acdb5d496..a1d7e71871 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -27,12 +27,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) @@ -91,8 +87,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"; ignition::common::setenv("IGN_FUEL_CACHE_PATH", projectPath.c_str()); @@ -165,16 +160,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. - ignition::common::setenv("IGN_CONFIG_PATH", IGN_CONFIG_PATH); - - ::testing::InitGoogleTest(&_argc, _argv); - return RUN_ALL_TESTS(); -}