diff --git a/src/architecture/messaging/CMakeLists.txt b/src/architecture/messaging/CMakeLists.txt index 3d990fb3cf..bb925c56d7 100644 --- a/src/architecture/messaging/CMakeLists.txt +++ b/src/architecture/messaging/CMakeLists.txt @@ -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) diff --git a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py new file mode 100644 index 0000000000..cd266f1b85 --- /dev/null +++ b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py @@ -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) diff --git a/src/architecture/messaging/msgAutoSource/generatePackageInit.py b/src/architecture/messaging/msgAutoSource/generatePackageInit.py deleted file mode 100644 index bc825be62b..0000000000 --- a/src/architecture/messaging/msgAutoSource/generatePackageInit.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -import sys - -path = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(path + '/../../../../../Basilisk/src/architecture/messaging/msgAutoSource') - -if __name__ == "__main__": - moduleOutputPath = sys.argv[1] - isExist = os.path.exists(moduleOutputPath) - if not isExist: - os.makedirs(moduleOutputPath, exist_ok=True) - mainImportFid = open(moduleOutputPath + '/__init__.py', 'w') - for i in range(2, len(sys.argv)): - headerInputPath = sys.argv[i] - for filePre in os.listdir(headerInputPath): - if(filePre.endswith(".h") or filePre.endswith(".hpp")): - className = os.path.splitext(filePre)[0] - msgName = className.split('Payload')[0] - mainImportFid.write('from Basilisk.architecture.messaging.' + className + ' import *\n') - mainImportFid.close() - setOldPath = moduleOutputPath.split('messaging')[0] + '/cMsgCInterfacePy' - os.symlink(moduleOutputPath, setOldPath)