Skip to content

Commit

Permalink
Merge pull request #287 from lasp/feature/allow-build-module-symlink-…
Browse files Browse the repository at this point in the history
…overwrite

Fix message package __init__.py symlink overwrite
  • Loading branch information
patkenneally authored Jul 25, 2024
2 parents 8a258b0 + 0af142d commit 3b7cf5b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 38 deletions.
33 changes: 17 additions & 16 deletions src/architecture/messaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,24 @@ function(generate_messages searchDir generateCCode)
endforeach()
endfunction(generate_messages)

set(message_directory_paths
"${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/"
"../../msgPayloadDefC/"
"../../msgPayloadDefCpp/"
)
if(NOT "${EXTERNAL_MODULES_PATH}" STREQUAL "")
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/__init__.py
COMMAND
${PYTHON_EXECUTABLE} generatePackageInit.py "${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/"
"../../msgPayloadDefC/" "../../msgPayloadDefCpp/" "${EXTERNAL_MODULES_PATH}/msgPayloadDefC/"
"${EXTERNAL_MODULES_PATH}/msgPayloadDefCpp/"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msgAutoSource
VERBATIM)
else()
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/__init__.py
COMMAND ${PYTHON_EXECUTABLE} generatePackageInit.py "${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/"
"../../msgPayloadDefC/" "../../msgPayloadDefCpp/"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msgAutoSource
VERBATIM)
endif(NOT "${EXTERNAL_MODULES_PATH}" STREQUAL "")
list(APPEND message_directory_paths
"${EXTERNAL_MODULES_PATH}/msgPayloadDefC/"
"${EXTERNAL_MODULES_PATH}/msgPayloadDefCpp/")
endif (NOT "${EXTERNAL_MODULES_PATH}" STREQUAL "")

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/__init__.py
COMMAND
${PYTHON_EXECUTABLE} generateMessagePackageInit.py ${message_directory_paths}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msgAutoSource
VERBATIM
)

# Custom target for establishing dependency
add_custom_target(swigtrick DEPENDS ${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/__init__.py)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import pathlib
import sys

path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(path + '/../../../../../Basilisk/src/architecture/messaging/msgAutoSource')

if __name__ == "__main__":
"""
In the message package directory create an __init__.py file
containing all the message packages. If the file exists, overwrite it.
"""
modulePath = sys.argv[1]
isExist = os.path.exists(modulePath)
os.makedirs(modulePath, exist_ok=True)
mainImportFid = open(modulePath + '/__init__.py', 'w')
for i in range(2, len(sys.argv)):
headerInputPath = sys.argv[i]
for fileName in os.listdir(headerInputPath):
if fileName.endswith(".h") or fileName.endswith(".hpp"):
className = os.path.splitext(fileName)[0]
msgName = className.split('Payload')[0]
mainImportFid.write('from Basilisk.architecture.messaging.' + className + ' import *\n')
mainImportFid.close()
oldModulePath = modulePath.split('messaging')[0] + 'cMsgCInterfacePy'
pathlib.Path(oldModulePath).unlink(missing_ok=True)
os.symlink(modulePath, oldModulePath)
22 changes: 0 additions & 22 deletions src/architecture/messaging/msgAutoSource/generatePackageInit.py

This file was deleted.

0 comments on commit 3b7cf5b

Please sign in to comment.