Skip to content

Commit

Permalink
Improve ign tool support on macOS (#477)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
scpeters authored and chapulina committed Mar 9, 2021
1 parent 6f0e45a commit 6699762
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<TARGET_FILE_DIR:TestModelSystem>")

set_tests_properties(UNIT_ign_TEST PROPERTIES
ENVIRONMENT "${_env_vars}")
endif()

if(NOT WIN32)
add_subdirectory(cmd)
endif()
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/cmdgazebo.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
}

0 comments on commit 6699762

Please sign in to comment.