diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 33a48b43..c7026e81 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -83,7 +83,8 @@ jobs: pybind11-dev \ libprotobuf-dev \ libpython3-dev \ - python3-pip + python3-pip \ + python3-virtualenv if [ "${{ matrix.compiler }}" = "gcc" ]; then sudo apt-get install -y g++ g++ diff --git a/.gitmodules b/.gitmodules index fab2cfa8..31ddce6f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "externals/box2d"] path = externals/box2d url = https://github.com/erincatto/box2d.git -[submodule "externals/protoletariat"] - path = externals/protoletariat - url = https://github.com/cpcloud/protoletariat.git diff --git a/cmake/apply-protol.cmake.in b/cmake/apply-protol.cmake.in deleted file mode 100644 index 0f6a482a..00000000 --- a/cmake/apply-protol.cmake.in +++ /dev/null @@ -1,15 +0,0 @@ -# Applies the fix for protobuf broken code using the protoletariat package: - -if (NOT "@PROTOL_PKG_DIR@" STREQUAL "") - set(ENV{PYTHONPATH} @PROTOL_PKG_DIR@) -endif() - -execute_process( - COMMAND - @PROTOL_EXECUTABLE@ --create-package --in-place --python-out @MVSIM_PYTHON_BUILD_DIRECTORY@/mvsim_msgs/ protoc --proto-path=@CMAKE_CURRENT_SOURCE_DIR@/proto @PROTOBUF_DEFINITION_FILES@ - RESULT_VARIABLE CMD_RES -) - -if (NOT CMD_RES EQUAL 0) - message(FATAL_ERROR "Error invoking protol (see above)") -endif() diff --git a/cmake/apply-protol.sh.in b/cmake/apply-protol.sh.in new file mode 100755 index 00000000..dd5fb924 --- /dev/null +++ b/cmake/apply-protol.sh.in @@ -0,0 +1,14 @@ +#!/bin/bash + +#set -x +set -e + +cd @MVSIM_PYTHON_BUILD_DIRECTORY@ +source @MVSIM_PYTHON_BUILD_DIRECTORY@/venv/bin/activate + +protol --create-package \ + --in-place \ + --python-out @MVSIM_PYTHON_BUILD_DIRECTORY@/mvsim_msgs/ \ + protoc --proto-path=@CMAKE_CURRENT_SOURCE_DIR@/proto \ + @PROTOBUF_DEFINITION_FILES_FOR_BASH@ + diff --git a/cmake/create-venv.sh.in b/cmake/create-venv.sh.in new file mode 100755 index 00000000..4148df9a --- /dev/null +++ b/cmake/create-venv.sh.in @@ -0,0 +1,11 @@ +#!/bin/bash + +#set -x +set -e + +cd @MVSIM_PYTHON_BUILD_DIRECTORY@ + +virtualenv -p @Python3_EXECUTABLE@ venv +source venv/bin/activate + +pip install protoletariat diff --git a/debian/control b/debian/control index 56ea2155..4a9ca924 100644 --- a/debian/control +++ b/debian/control @@ -20,6 +20,7 @@ Build-Depends: python3-dev, python3-setuptools, python3-pip, + python3-virtualenv, Standards-Version: 4.5.0 Package: libmvsim-comms0.4 diff --git a/externals/protoletariat b/externals/protoletariat deleted file mode 160000 index 732771e2..00000000 --- a/externals/protoletariat +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 732771e23717886b1998fa24f3ee390090792ed3 diff --git a/modules/msgs/CMakeLists.txt b/modules/msgs/CMakeLists.txt index 2f22cca1..72b18543 100644 --- a/modules/msgs/CMakeLists.txt +++ b/modules/msgs/CMakeLists.txt @@ -10,6 +10,9 @@ file(GLOB PROTOBUF_DEFINITION_FILES "${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto") protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTOBUF_DEFINITION_FILES}) protobuf_generate_python(PROTO_PY_FILES ${PROTOBUF_DEFINITION_FILES}) +# Space-separated list for bash scripts: +string (REPLACE ";" " " PROTOBUF_DEFINITION_FILES_FOR_BASH "${PROTOBUF_DEFINITION_FILES}") + # Declare the target (a library) add_library(${PROJECT_NAME} ${PROTO_SRCS} ${PROTO_HDRS} @@ -46,61 +49,29 @@ if (MVSIM_WITH_PROTOBUF) # We must fix protobuf broken code: # Read https://github.com/cpcloud/protoletariat # and https://github.com/protocolbuffers/protobuf/issues/1491 - find_program(PROTOL_EXECUTABLE NAMES protol) - - if (NOT PROTOL_EXECUTABLE) - message(STATUS "======================================================") - message(STATUS "protol not found, installing it now with pip3... ") - message(STATUS " If pip3 is not installed or another error is found, ") - message(STATUS " you can still build MVSIM without Python support ") - message(STATUS " setting the CMake variable MVSIM_WITH_PYTHON=Off ") - message(STATUS "======================================================") - - - set(PROTOL_INSTALL_DIR ${MVSIM_PYTHON_BUILD_DIRECTORY}/protol-install/) - - # And add pkg to PYTHONPATH: - set(PROTOL_PKG_DIR ${PROTOL_INSTALL_DIR}/usr/lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/ CACHE PATH "Path to installed protoletariat pkg") - message(STATUS "PROTOL_PKG_DIR: ${PROTOL_PKG_DIR}") - - set(ENV{PYTHONPATH} ${PROTOL_PKG_DIR}) - - execute_process( - COMMAND python3 -m pip install --root ${PROTOL_INSTALL_DIR} --prefix /usr/ . - WORKING_DIRECTORY ${mvsim_SOURCE_DIR}/externals/protoletariat/ - RESULT_VARIABLE PIP3_INSTALL_RESULT - OUTPUT_VARIABLE PIP3_OUTPUT - ERROR_VARIABLE PIP3_OUTPUT - ) - message(STATUS "PIP3_INSTALL_RESULT: ${PIP3_INSTALL_RESULT}.\nOutput:\n${PIP3_OUTPUT}") - - execute_process( - COMMAND python3 -m pip show -f protoletariat - WORKING_DIRECTORY ${mvsim_SOURCE_DIR}/externals/protoletariat/ - RESULT_VARIABLE PIP3_LIST_RESULT - OUTPUT_VARIABLE PIP3_OUTPUT - ERROR_VARIABLE PIP3_OUTPUT - ) - message(STATUS "PIP3_LIST_RESULT: ${PIP3_LIST_RESULT}.\nOutput:\n${PIP3_OUTPUT}") - - - # Hint to find protol executable: - set(PROTOL_DESTDIR ${PROTOL_INSTALL_DIR}/usr/bin) - - unset(PROTOL_EXECUTABLE CACHE) - endif() + + configure_file( + ${mvsim_SOURCE_DIR}/cmake/create-venv.sh.in + ${MVSIM_PYTHON_BUILD_DIRECTORY}/create-venv.sh + @ONLY + ) - find_program(PROTOL_EXECUTABLE NAMES protol REQUIRED HINTS ${PROTOL_DESTDIR}) - message(STATUS "PROTOL_EXECUTABLE: ${PROTOL_EXECUTABLE}") + execute_process( + COMMAND ${MVSIM_PYTHON_BUILD_DIRECTORY}/create-venv.sh + RESULT_VARIABLE VENV_RESULT + OUTPUT_VARIABLE VENV_OUTPUT + ERROR_VARIABLE VENV_OUTPUT + ) + message(STATUS "Python3 virtualenv creation: ${VENV_RESULT}.\nOutput:\n${VENV_OUTPUT}") configure_file( - ${mvsim_SOURCE_DIR}/cmake/apply-protol.cmake.in - ${MVSIM_PYTHON_BUILD_DIRECTORY}/apply-protol.cmake + ${mvsim_SOURCE_DIR}/cmake/apply-protol.sh.in + ${MVSIM_PYTHON_BUILD_DIRECTORY}/apply-protol.sh @ONLY ) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -P ${MVSIM_PYTHON_BUILD_DIRECTORY}/apply-protol.cmake + COMMAND ${MVSIM_PYTHON_BUILD_DIRECTORY}/apply-protol.sh COMMENT "Applying protoletariat protobuf broken code fix..." )