Convert lines endings of python scripts when colcon build
Hello,
I have a C++ package created with ament_cmake
, that also contains some python nodes.
I work in a mixed environment shared between Linux and Windows, where I edit the files on Windows and run ROS2 on Linux. So the end-of-lines of my python files often get replaced by CRLF, and so my python nodes failed to run on my Linux install of ROS2.
How can I convert automatically the EOL when doing colcon build
?
I tried to execute dos2unix
in the CMakeList.txt but this actually does not convert the .py files, even while there is no dos2unix
error:
# Install Python executables
install(PROGRAMS
scripts/laserscan_adapter.py
DESTINATION lib/${PROJECT_NAME}
)
ament_package()
# This runs without error message but the file is not actually changed
execute_process(COMMAND dos2unix /abs/path/to/workspace/install/leg_detector/lib/laserscan_processor/laserscan_adapter.py)
# This fails with dos2unix: No such file or directory, Skipping: not a regular file
execute_process(COMMAND dos2unix /abs/path/to/workspace/install/leg_detector/lib/laserscan_processor/*.py)
However the same commands copy-pasted in the terminal works as expected.
I note that ament_python
packages works no matter the lines ending.
How can I convert the end of lines or call dos2unix automatically when doing colcon build
?
Is there a better approach for this conversion ?
Thanks,
Colcon is not involved here, it's CMake. So don't restrict yourself to looking for solutions "with Colcon".
A
CMakeLists.txt
is not executed sequentially, it's a tree of dependencies visited in the appropriate order (ie: dependencies first, then dependents).Your two
execute_process(..)
statements don't specify any dependencies, nor are there any dependents, so I'm not sure they are ever executed (they could be, but I wouldn't know when).You'll want to lookup documentation on CMake's
execute_process(..)
, specifically the parts about configuring the targets they are attached to.