Skip to content

Commit c9f815a

Browse files
scpeterschapulina
authored andcommitted
Improve ign tool support on macOS (#477)
Signed-off-by: Louise Poubel <louise@openrobotics.org>
1 parent 84c4ce9 commit c9f815a

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ set(IGN_RENDERING_VER ${ignition-rendering3_VERSION_MAJOR})
122122
ign_find_package(ignition-math6 REQUIRED COMPONENTS eigen3 VERSION 6.6)
123123
set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR})
124124

125+
#--------------------------------------
126+
# Find ignition-tools
127+
ign_find_package(ignition-tools
128+
REQUIRED
129+
PKGCONFIG "ignition-tools")
130+
125131
#--------------------------------------
126132
# Find protobuf
127133
set(REQ_PROTOBUF_VER 3)

src/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,36 @@ ign_build_tests(TYPE UNIT
132132
ignition-gazebo${PROJECT_VERSION_MAJOR}
133133
)
134134

135+
if(TARGET UNIT_ign_TEST)
136+
137+
# Running `ign gazebo` on macOS has problems when run with /usr/bin/ruby
138+
# due to System Integrity Protection (SIP). Try to find ruby from
139+
# homebrew as a workaround.
140+
if (APPLE)
141+
find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin)
142+
endif()
143+
144+
add_dependencies(UNIT_ign_TEST
145+
${ign_lib_target}
146+
TestModelSystem
147+
TestSensorSystem
148+
TestWorldSystem
149+
)
150+
151+
target_compile_definitions(UNIT_ign_TEST PRIVATE
152+
"BREW_RUBY=\"${BREW_RUBY} \"")
153+
154+
target_compile_definitions(UNIT_ign_TEST PRIVATE
155+
"IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"")
156+
157+
set(_env_vars)
158+
list(APPEND _env_vars "IGN_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf")
159+
list(APPEND _env_vars "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:TestModelSystem>")
160+
161+
set_tests_properties(UNIT_ign_TEST PROPERTIES
162+
ENVIRONMENT "${_env_vars}")
163+
endif()
164+
135165
if(NOT WIN32)
136166
add_subdirectory(cmd)
137167
endif()

src/cmd/cmdgazebo.rb.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ class Cmd
338338
Importer.dlload plugin
339339
rescue DLError => e
340340
puts "Library error for [#{plugin}]: #{e.to_s}"
341+
if plugin.end_with? ".dylib"
342+
puts "
343+
If this script was executed with /usr/bin/ruby, this error may be caused by
344+
macOS System Integrity Protection. One workaround is to use a different
345+
version of ruby, for example:
346+
brew install ruby
347+
and add the following line to your shell profile:
348+
export PATH=/usr/local/opt/ruby/bin:$PATH
349+
If you are using a colcon workspace, please ensure that the setup script
350+
has properly set the DYLD_LIBRARY_PATH environment variables."
351+
end
341352
exit(-1)
342353
end
343354

@@ -436,6 +447,12 @@ class Cmd
436447
# and gui.
437448
if options['server'] == 0 && options['gui'] == 0
438449

450+
if plugin.end_with? ".dylib"
451+
puts "`ign gazebo` currently only works with the -s argument on macOS.
452+
See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
453+
exit(-1)
454+
end
455+
439456
serverPid = Process.fork do
440457
ENV['RMT_PORT'] = '1500'
441458
Process.setpgid(0, 0)
@@ -485,6 +502,12 @@ class Cmd
485502
options['file'], options['record-topics'].join(':'))
486503
# Otherwise run the gui
487504
else options['gui']
505+
if plugin.end_with? ".dylib"
506+
puts "`ign gazebo` currently only works with the -s argument on macOS.
507+
See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
508+
exit(-1)
509+
end
510+
488511
ENV['RMT_PORT'] = '1501'
489512
Importer.runGui(options['gui_config'])
490513
end

src/ign_TEST.cc

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@
2727

2828
static const std::string kBinPath(PROJECT_BINARY_PATH);
2929

30-
// Command line not working on OSX, see
31-
// https://github.com/ignitionrobotics/ign-gazebo/issues/25/
32-
#ifndef __APPLE__
3330
static const std::string kIgnCommand(
34-
"IGN_GAZEBO_SYSTEM_PLUGIN_PATH=" + kBinPath + "/lib LD_LIBRARY_PATH=" +
35-
kBinPath + "/lib:/usr/local/lib:${LD_LIBRARY_PATH} ign gazebo -s ");
31+
std::string(BREW_RUBY) + std::string(IGN_PATH) + "/ign gazebo -s ");
3632

3733
/////////////////////////////////////////////////
3834
std::string customExecStr(std::string _cmd)
@@ -91,8 +87,7 @@ TEST(CmdLine, Server)
9187
}
9288

9389
/////////////////////////////////////////////////
94-
// Not supported on Mac's command line tool
95-
TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_MAC(CachedFuelWorld))
90+
TEST(CmdLine, CachedFuelWorld)
9691
{
9792
std::string projectPath = std::string(PROJECT_SOURCE_PATH) + "/test/worlds";
9893
ignition::common::setenv("IGN_FUEL_CACHE_PATH", projectPath.c_str());
@@ -165,16 +160,3 @@ TEST(CmdLine, ResourcePath)
165160
EXPECT_EQ(output.find("Unable to find file plugins.sdf"), std::string::npos)
166161
<< output;
167162
}
168-
#endif
169-
170-
/////////////////////////////////////////////////
171-
/// Main
172-
int main(int _argc, char **_argv)
173-
{
174-
// Set IGN_CONFIG_PATH to the directory where the .yaml configuration files
175-
// is located.
176-
ignition::common::setenv("IGN_CONFIG_PATH", IGN_CONFIG_PATH);
177-
178-
::testing::InitGoogleTest(&_argc, _argv);
179-
return RUN_ALL_TESTS();
180-
}

0 commit comments

Comments
 (0)