Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ign tool support on macOS #477

Merged
merged 5 commits into from
Jan 11, 2021

Conversation

scpeters
Copy link
Member

@scpeters scpeters commented Dec 9, 2020

The ign gazebo command does not have full support on macOS (see #25 and #44). If System Integrity Protection is not disabled, the system version of ruby at /usr/bin/ruby cannot be used, though the brew version of ruby can be used as a workaround. Additionally, the GUI interface window does not work on macOS. This pull request enables UNIT_ign_TEST on macOS and fixes it to use the brew version of ruby (which was added as a dependency to the homebrew formulae in osrf/homebrew-simulation#1221). It also moves the configuration of environment variables from the test to the cmake code.

I've also added some extra console error messages when macOS is detected (from the .dylib suffix on library files):

$ ign gazebo
Library error for [/Users/ignition/ws/install/ignition-gazebo4/lib/libignition-gazebo4-ign.4.0.0.dylib]: can't load /Users/ignition/ws/install/ignition-gazebo4/lib/libignition-gazebo4-ign.4.0.0.dylib

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.
# explicitly invoking with brew's ruby and without -g or -s
$ /usr/local/opt/ruby/bin/ruby $(which ign) gazebo
`ign gazebo` currently only works with the -s argument on macOS.
# explicitly invoking with brew's ruby and with -g
$ /usr/local/opt/ruby/bin/ruby $(which ign) gazebo -g
`ign gazebo` currently only works with the -s argument 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 <[email protected]>
Recommend using brew ruby and ensuring that colcon
setup scripts have been sourced.

Signed-off-by: Steve Peters <[email protected]>
@scpeters
Copy link
Member Author

scpeters commented Dec 9, 2020

@chapulina chapulina added the macOS macOS support label Dec 9, 2020
@chapulina chapulina added the tests Broken or missing tests / testing infra label Dec 9, 2020
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to give more direction to macOS users!

CMakeLists.txt Outdated Show resolved Hide resolved
src/cmd/cmdgazebo.rb.in Outdated Show resolved Hide resolved
list(APPEND _env_vars "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:TestModelSystem>")

set_tests_properties(UNIT_ign_TEST PROPERTIES
ENVIRONMENT "${_env_vars}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I don't think we've been setting environment variables for tests from CMake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned it from Dirk; it's not universal, but we have done it in a few places:

I think it's a bit cleaner to set them from cmake. One drawback is that executing the binaries directly (like ./UNIT_ign_TEST) may not work, but it's easy enough to use ctest -R UNIT_ign_TEST -VV once you know to do so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One drawback is that executing the binaries directly (like ./UNIT_ign_TEST) may not work

Oh no, that sounds like a regression. We have that workflow documented in a few places, it would be unfortunate not to support it anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned during the meeting, I don't see the advantage of moving the environment variables to CMake.

It prevents a common workflow, and it hides the environment configuration from anyone who's debugging the tests or looking into them to understand how the code works. Especially for variables like IGN_GAZEBO_SYSTEM_PLUGIN_PATH, which are set by the user at runtime, I think it's valuable to explicitly set them during the tests.

But I'm not going to block this PR on this, I'll leave it up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pointed to 3 examples in our code where it's already being used, so this isn't a completely new thing, but you're right that the docs need to be updated to handle this case. I'll merge this then open a pull request to update the docs

src/CMakeLists.txt Show resolved Hide resolved
list(APPEND _env_vars "IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:TestModelSystem>")

set_tests_properties(UNIT_ign_TEST PROPERTIES
ENVIRONMENT "${_env_vars}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned during the meeting, I don't see the advantage of moving the environment variables to CMake.

It prevents a common workflow, and it hides the environment configuration from anyone who's debugging the tests or looking into them to understand how the code works. Especially for variables like IGN_GAZEBO_SYSTEM_PLUGIN_PATH, which are set by the user at runtime, I think it's valuable to explicitly set them during the tests.

But I'm not going to block this PR on this, I'll leave it up to you.

@chapulina
Copy link
Contributor

@scpeters , I think you moved this back to "In Progress" because a resolution to gazebosim/gz-tools#7 may help here, right? I think we could get this in as is, and make those improvements later if we can. Let me know if I misunderstood something. I think this is a good intermediate state and better than the current state without it.

@scpeters scpeters merged commit eded758 into gazebosim:ign-gazebo4 Jan 11, 2021
@scpeters scpeters deleted the macos_ign_test branch January 11, 2021 18:48
chapulina pushed a commit that referenced this pull request Mar 9, 2021
chapulina pushed a commit that referenced this pull request Mar 10, 2021
chapulina pushed a commit that referenced this pull request Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 dome Ignition Dome macOS macOS support tests Broken or missing tests / testing infra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants