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

Only perform backquote substitution when needed #34

Closed
wants to merge 2 commits into from

Conversation

po1
Copy link

@po1 po1 commented Feb 15, 2014

This pull request has several goals.

  1. fix an issue when using pluginlib in a Xenomai environment, for example through ros_control. In such an environment, calling popen can have disastrous consequences. While not preventing the call, the proposed fix removes unnecessary calls.
  2. Improve speed of pluginlib. A call to createInstance() has been benchmarked to drop from around 2 seconds to 50 milliseconds with this fix on our local setup with a near-complete ROS hydro install + extra local packages.
  3. Improve compatibility with non-POSIX systems, which have no bourne-compatible shell and thus cannot perform the substitution. This point should be further addressed by redesigning the substitution to match that of other components, e.g. launch files.

It is proposed against groovy-devel because it is very small and does not break API or ABI compatibility.

@@ -2151,7 +2151,12 @@ bool cmpDirectoryCrawlRecord(DirectoryCrawlRecord* i,
outstring.replace(i, std::string(MANIFEST_PREFIX).length(),
stackage->path_);
}


if (outstring.find_first_of("$`") == std::string::npos)
Copy link
Member

Choose a reason for hiding this comment

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

Why is it searching for $`` and not only for ```? And if it should search for backtick only it might better use .find()`.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know exactly what the intention was, but you can use the alternative syntax $(command)
Because I didn't know exactly who is using this feature, I just preferred not taking chances.

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to search for ``` as well as $(?

Copy link
Author

Choose a reason for hiding this comment

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

This is what find_first_of is doing. It is searching for ``` and $

Copy link
Author

Choose a reason for hiding this comment

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

Ow, sorry, I think I got what you meant. You mean that we should look specifically for $( and not just $, right?
Well, that would also break the previous behavior. I don't know if anybody actually relies on this, but again, not taking chances.

Copy link
Member

Choose a reason for hiding this comment

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

So it should process:

  • commands wrapped in backticks (...)
  • commands wrapped in $(...)
  • environment variables accessed with $name

Then the patch makes sense as it is.

Copy link
Member

Choose a reason for hiding this comment

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

To clarify that in the patch can you please insert the following comment above the if line:

// skip substitution attempt when the string neither contains
// a dollar sign for $(command) and $envvar nor
// a backtick wrapping a command

@po1
Copy link
Author

po1 commented Feb 15, 2014

@dirk-thomas the comment has been added.
Sorry for the extra commit, my editor gets crazy (and so do I) with trailing spaces.

@dirk-thomas
Copy link
Member

As long as it gets applied to all active branch and is in a separate commit I am fine with code style clean up. Can you please squash the first two commit into one?

Paul Mathieu added 2 commits February 15, 2014 20:10
Spawning shells is an expensive operation.
In a lot of cases, there is no need for any substitution.
Besides, this does not work on Windows.
@po1
Copy link
Author

po1 commented Feb 15, 2014

Here you go

@dirk-thomas
Copy link
Member

+1 form me.

@tfoote @wjwwood Please review and consider that it will be applied to Groovy, Hydro and Indigo.

@tfoote
Copy link
Member

tfoote commented Feb 16, 2014

+1 with backport . The improvements are backwards compatible and provide support for more platforms. If we're backporting to hydro we might as well go to groovy too.

@dirk-thomas
Copy link
Member

Thank you for the patch.

I have applied your changes to the indigo-devel branch (27ed245, ac74cfe). I will merge it to Groovy and Hydro once I am going to do new releases for them.

@wjwwood
Copy link
Member

wjwwood commented Feb 17, 2014

+1

@adolfo-rt
Copy link

+1, yay!

  1. Improve compatibility with non-POSIX systems, which have no bourne-compatible shell and thus cannot perform the substitution.

This seems like legacy from the rosbuild era. As an indication, a search over all 418 package.xml files in my current system yields that:

  • $ is only used in the context of ${prefix}
  • Backticks are only used in non-comments by three packages: map_server, laser_filters and diagnostic_aggregator for rosboost-cfg --cflags or rosboost-config --lflags. Setting these flags in the CMakeLists.txt should bring the count to zero.

This point should be further addressed by redesigning the substitution to match that of other components, e.g. launch files.

+1 for $(find package_name) syntax support, if there are usecases for it. The call to popen will have to remain there until rosbuild is phased out, though.

I have applied your changes to the indigo-devel branch (27ed245, ac74cfe). I will merge it to Groovy and Hydro once I am going to do new releases for them.

Nitpick: Please cherry-pick the changesets next time, so attribution is preserved ;-).

@dirk-thomas
Copy link
Member

@adolfo-rt Despite what is actively being used in a very small subset of packages we can simply not change behavior. What has worked before and was valid code should continue to work.

All patch always go to the latest development branch and then get backported when they have proven stable. But these changes did not at all apply to indigo-devel - please try a cherry-pick - both branches have divered significantly. Therefore I just replicated the patch instead of waiting for the pull request to be modified to apply to indigo-devel. Usually I will always either cherry-pick or merge the incoming if they are good as they are. Especially the trailing white space part was also extended to cover all sources but a single file.

@adolfo-rt
Copy link

@adolfo-rt Despite what is actively being used in a very small subset of packages we can simply not change behavior. What has worked before and was valid code should continue to work.

I'm not suggesting breaking existing behavior in the short or medium term. Still, if platform-independence becomes important enough at some point to be addressed, this would definitely imply changing behavior. That being said, I find it a good sign that most catkin packages out there are not relying on platform-dependent behavior :).

@dirk-thomas
Copy link
Member

Cherry-picked the change (without the whitespaces) into groovy-devel. Will be released as 2.1.23.

@po1 po1 deleted the expand-when-needed branch February 25, 2014 22:40
@adolfo-rt
Copy link

Thanks!

severin-lemaignan referenced this pull request in severin-lemaignan/robotpkg Aug 18, 2014
Drop patch-aa for tinyxml location, this is now handled by
devel/ros-cmake-modules.

Changes since 2.1.19:

2.2.4 (2014-07-10)
------------------
* fix find_package(PythonLibs ...) with CMake 3 (`#42
<https://github.com/ros/rospack/issues/42>`_)

2.2.3 (2014-05-07)
------------------
* find library for exact Python version (even if not in CMake provided list of
version numbers) (`#40 <https://github.com/ros/rospack/issues/40>`_)
* find TinyXML using cmake_modules (`#24
<https://github.com/ros/rospack/issues/24>`_)
* make error messages tool specific (rospack vs. rosstack) (`#38
<https://github.com/ros/rospack/issues/38>`_)

2.2.2 (2014-02-25)
------------------
* python 3 compatibility (`#35 <https://github.com/ros/rospack/issues/35>`_)

2.2.1 (2014-02-24)
------------------
* only perform backquote substitution when needed (`#34
<https://github.com/ros/rospack/issues/34>`_)

2.2.0 (2014-01-30)
------------------
* add hash of ROS_PACKAGE_PATH to rospack/rosstack cache filename, remove
ROS_ROOT from cache (`#28 <https://github.com/ros/rospack/issues/28>`_)

2.1.22 (2014-01-07)
-------------------
* use specific python version catkin has decided on (`#29
<https://github.com/ros/rospack/issues/29>`_)
* python 3 compatibility (`#25 <https://github.com/ros/rospack/issues/25>`_,
`#27 <https://github.com/ros/rospack/issues/27>`_)
* fall back gracefully whe gtest is not available
* update package urls

2.1.21 (2013-07-05)
-------------------
* honor CATKIN_IGNORE marker file when crawling for packages (`#21
<https://github.com/ros/rospack/issues/21>`_)

2.1.20 (2013-07-03)
-------------------
* improve error message to include package names when circular dependency is
detected (`#18 <https://github.com/ros/rospack/issues/18>`_)
* check for CATKIN_ENABLE_TESTING to enable configure without tests
* add '-h' option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants