Skip to content

Commit

Permalink
Simpler with virtualenv
Browse files Browse the repository at this point in the history
Former-commit-id: 0ae87c85597763f34aba13ab51ad43cb647f7e88 [formerly a2d4675]
Former-commit-id: 421a7e832534e786521224931296c646977b0ae5
  • Loading branch information
jlblancoc committed Oct 17, 2022
1 parent c0ca133 commit 5623350
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 68 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions cmake/apply-protol.cmake.in

This file was deleted.

14 changes: 14 additions & 0 deletions cmake/apply-protol.sh.in
Original file line number Diff line number Diff line change
@@ -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@

11 changes: 11 additions & 0 deletions cmake/create-venv.sh.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Build-Depends:
python3-dev,
python3-setuptools,
python3-pip,
python3-virtualenv,
Standards-Version: 4.5.0

Package: libmvsim-comms0.4
Expand Down
1 change: 0 additions & 1 deletion externals/protoletariat
Submodule protoletariat deleted from 732771
67 changes: 19 additions & 48 deletions modules/msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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..."
)

Expand Down

0 comments on commit 5623350

Please sign in to comment.