The official way of applying custom patches is to work with overlays. Check what is overlay question as starting point.
For hackers knowing what they are doing (especially for non-Ubuntu users):
Ros packages always come with the source code. Only if you work on Ubuntu and install via apt-get you receive both source code and precompiled modules.
To install a patch, you have to:
- apply the patch to the source code (usually subdirectory src/ in package directory)
- delete ROS_NO_BUILD file from the package top directory
- run "rosmake" from the package top directory, or "rosmake package_name" from anywhere
As the ROS distro is usually installed in /opt/ros directory, you need to sudo all the above tasks.
Be aware, that whenever you upgrade your ROS distro with apt-get upgrade all your patches will be lost, as new version of precompiled modules will be installed.
To avoid that, the best practice is to work with overlay as described at the beginning of the answer.
Could you please be more specific by giving an example?
Well, https://code.ros.org/trac/ros/ticket/3949 here there are some patches to use ROS with Python 3 , but how I use them?