From bb3a35dc71b6b49e50369ba9addb671884036fe1 Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Thu, 25 Jul 2024 13:27:35 -0600 Subject: [PATCH 1/7] Unlink before creating symlink --- src/architecture/messaging/msgAutoSource/generatePackageInit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/architecture/messaging/msgAutoSource/generatePackageInit.py b/src/architecture/messaging/msgAutoSource/generatePackageInit.py index bc825be62b..9745df4bbc 100644 --- a/src/architecture/messaging/msgAutoSource/generatePackageInit.py +++ b/src/architecture/messaging/msgAutoSource/generatePackageInit.py @@ -1,4 +1,5 @@ import os +import pathlib import sys path = os.path.dirname(os.path.abspath(__file__)) @@ -19,4 +20,5 @@ mainImportFid.write('from Basilisk.architecture.messaging.' + className + ' import *\n') mainImportFid.close() setOldPath = moduleOutputPath.split('messaging')[0] + '/cMsgCInterfacePy' + pathlib.Path(setOldPath).unlink(missing_ok=True) os.symlink(moduleOutputPath, setOldPath) From 0bf864a14c730487d97a1ee96a539a2433c0117f Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Tue, 23 Jul 2024 11:15:35 -0600 Subject: [PATCH 2/7] Clarify variable names --- .../msgAutoSource/generatePackageInit.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/architecture/messaging/msgAutoSource/generatePackageInit.py b/src/architecture/messaging/msgAutoSource/generatePackageInit.py index 9745df4bbc..d351aff75b 100644 --- a/src/architecture/messaging/msgAutoSource/generatePackageInit.py +++ b/src/architecture/messaging/msgAutoSource/generatePackageInit.py @@ -6,19 +6,19 @@ sys.path.append(path + '/../../../../../Basilisk/src/architecture/messaging/msgAutoSource') if __name__ == "__main__": - moduleOutputPath = sys.argv[1] - isExist = os.path.exists(moduleOutputPath) + modulePath = sys.argv[1] + isExist = os.path.exists(modulePath) if not isExist: - os.makedirs(moduleOutputPath, exist_ok=True) - mainImportFid = open(moduleOutputPath + '/__init__.py', 'w') + 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 filePre in os.listdir(headerInputPath): - if(filePre.endswith(".h") or filePre.endswith(".hpp")): - className = os.path.splitext(filePre)[0] + 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() - setOldPath = moduleOutputPath.split('messaging')[0] + '/cMsgCInterfacePy' - pathlib.Path(setOldPath).unlink(missing_ok=True) - os.symlink(moduleOutputPath, setOldPath) + oldModulePath = modulePath.split('messaging')[0] + '/cMsgCInterfacePy' + pathlib.Path(oldModulePath).unlink(missing_ok=True) + os.symlink(modulePath, oldModulePath) From c6c17c0df9456b2955d8663713a2a0047340a07b Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Tue, 23 Jul 2024 13:17:28 -0600 Subject: [PATCH 3/7] Rename generatePackageInit.py to generateMessagePackageInit.py --- src/architecture/messaging/CMakeLists.txt | 4 ++-- .../{generatePackageInit.py => generateMessagePackageInit.py} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename src/architecture/messaging/msgAutoSource/{generatePackageInit.py => generateMessagePackageInit.py} (100%) diff --git a/src/architecture/messaging/CMakeLists.txt b/src/architecture/messaging/CMakeLists.txt index 3d990fb3cf..8687d34d52 100644 --- a/src/architecture/messaging/CMakeLists.txt +++ b/src/architecture/messaging/CMakeLists.txt @@ -65,7 +65,7 @@ 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/" + ${PYTHON_EXECUTABLE} generateMessagePackageInit.py "${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/" "../../msgPayloadDefC/" "../../msgPayloadDefCpp/" "${EXTERNAL_MODULES_PATH}/msgPayloadDefC/" "${EXTERNAL_MODULES_PATH}/msgPayloadDefCpp/" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msgAutoSource @@ -73,7 +73,7 @@ if(NOT "${EXTERNAL_MODULES_PATH}" STREQUAL "") else() add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/__init__.py - COMMAND ${PYTHON_EXECUTABLE} generatePackageInit.py "${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/" + COMMAND ${PYTHON_EXECUTABLE} generateMessagePackageInit.py "${CMAKE_BINARY_DIR}/Basilisk/architecture/messaging/" "../../msgPayloadDefC/" "../../msgPayloadDefCpp/" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msgAutoSource VERBATIM) diff --git a/src/architecture/messaging/msgAutoSource/generatePackageInit.py b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py similarity index 100% rename from src/architecture/messaging/msgAutoSource/generatePackageInit.py rename to src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py From 6d2d40badf2ab7ac6e0162f7f65b31648b0de251 Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Thu, 25 Jul 2024 15:21:09 -0600 Subject: [PATCH 4/7] Simplify logic for command construction --- src/architecture/messaging/CMakeLists.txt | 33 ++++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/architecture/messaging/CMakeLists.txt b/src/architecture/messaging/CMakeLists.txt index 8687d34d52..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} generateMessagePackageInit.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} generateMessagePackageInit.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) From 9f9057ada08762163c50f8177b06af2e7a63eb4b Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Tue, 23 Jul 2024 13:19:04 -0600 Subject: [PATCH 5/7] Add file main docstring --- .../messaging/msgAutoSource/generateMessagePackageInit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py index d351aff75b..d976e9c129 100644 --- a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py +++ b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py @@ -6,6 +6,10 @@ 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) if not isExist: From 64fb3ad46fa4ef73e32efbb09cd2d0fc671167d4 Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Tue, 23 Jul 2024 13:21:32 -0600 Subject: [PATCH 6/7] Remove redundant conditional The conditional is redundant because the exist_ok=True is being passed which recreates the directory even if it exists. Recreating it is inline with the rationale that the directory, the __init__ file and its contents should be recreated each build, rather than requiring a -clean which is a much more significant erasure of cached build files. --- .../messaging/msgAutoSource/generateMessagePackageInit.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py index d976e9c129..20de69c326 100644 --- a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py +++ b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py @@ -12,8 +12,7 @@ """ modulePath = sys.argv[1] isExist = os.path.exists(modulePath) - if not isExist: - os.makedirs(modulePath, exist_ok=True) + os.makedirs(modulePath, exist_ok=True) mainImportFid = open(modulePath + '/__init__.py', 'w') for i in range(2, len(sys.argv)): headerInputPath = sys.argv[i] From 0af142dd791ff2e283ccb56f95169a98648398de Mon Sep 17 00:00:00 2001 From: patrick kenneally Date: Tue, 23 Jul 2024 13:22:00 -0600 Subject: [PATCH 7/7] Remove redundant forward slash character --- .../messaging/msgAutoSource/generateMessagePackageInit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py index 20de69c326..cd266f1b85 100644 --- a/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py +++ b/src/architecture/messaging/msgAutoSource/generateMessagePackageInit.py @@ -22,6 +22,6 @@ msgName = className.split('Payload')[0] mainImportFid.write('from Basilisk.architecture.messaging.' + className + ' import *\n') mainImportFid.close() - oldModulePath = modulePath.split('messaging')[0] + '/cMsgCInterfacePy' + oldModulePath = modulePath.split('messaging')[0] + 'cMsgCInterfacePy' pathlib.Path(oldModulePath).unlink(missing_ok=True) os.symlink(modulePath, oldModulePath)