Repository navigation
fix up warnings and use definition to specialize _rclpy.c - #2
Conversation
| include_directories(include) | ||
|
|
||
| if(NOT WIN32) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") |
There was a problem hiding this comment.
If this package doesn't do any C++ stuff project(...) should explicitly list only C to avoid searching for a C++ compiler.
| file( | ||
| COPY "${PROJECT_NAME}" | ||
| DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" | ||
| ) |
There was a problem hiding this comment.
I still don't see why this should be done. Copying files like this should be avoided at all cost. Can someone argue why this is absolutely necessary?
There was a problem hiding this comment.
Copying files like this should be avoided at all cost.
Why? That seems to be an absolute assertion without an obvious reason (as if it should be clear to everyone that this is always implicitly true).
Can someone argue why this is absolutely necessary?
It is necessary because in order to import rclpy you need a folder which contains both the Python code (which starts in the source space) and the generated C extensions (.so's) which are generated into the build space. So this copies the Python source into the build space so that there can be a folder in the build space which contains both the Python source and the C extensions. This is needed so that the tests can import rclpy as if it were installed, and the tests do so by importing rclpy from the build space.
I'd suggest you look into why it is that way by trying to change it (as I did), if you don't believe me. Maybe you can come up with an improvement.
There was a problem hiding this comment.
Copying files like this should be avoided at all cost.
Why? That seems to be an absolute assertion without an obvious reason (as if it should be clear to everyone that this is always implicitly true).
Updated: The reasons are:
- when files get copied the developer might unintentionally change the wrong file
- changes to the source files won't have any effect on future builds since the files are only copied once at configure time
- either CMake needs to be reinvoked every time (which is time consuming during the development) or the developer edits the copied files in the build space for faster iteration and then has to copy back his changes (always potentially overwriting them accidentally when reconfiguring)
Can someone argue why this is absolutely necessary?
It is necessary because in order to import
rclpyyou need a folder which contains both the Python code (which starts in the source space) and the generated C extensions (.so's) which are generated into the build space. So this copies the Python source into the build space so that there can be a folder in the build space which contains both the Python source and the C extensions. This is needed so that the tests can importrclpyas if it were installed, and the tests do so by importingrclpyfrom the build space.I'd suggest you look into why it is that way by trying to change it (as I did), if you don't believe me. Maybe you can come up with an improvement.
See PR #3 which achieves the described goal.
|
@wjwwood thanks for the improvements! Yeah, the explanation you added as a comment is why I copied the files from the source tree to the build tree so that a single call to |
fix up warnings and use definition to specialize _rclpy.c
The big change here is that I renamed
_rclpy.c.into_rclpy.cand changed to using a preprocessor definition instead of the CMake template that was being used before. I thought this was better so that editors could more easily detect and color the file, and for me it allowed me to add a definition to my C++ checker and then it could parse and check for warnings/errors in my editor, which is obviously harder when it's a CMake template.I also addressed the style stuff in
_rclpy.caccording to uncrusfity and cpplint, added a copyright header, and changed it so that rcl errors are propagated up to Python asRuntimeError's.@esteve I made this as a pull request so you could consider the changes before merging it into your pull request.