From 27d605c9a254c02c91c90213f1af6bf5bdac8a1d Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 18 Mar 2024 10:11:02 -0700 Subject: [PATCH 01/27] Adding dictionary generation --- cmake/autocoder/fpp.cmake | 27 ++++++++++++++++++++++++--- cmake/target/install.cmake | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index d3d8fcc096..fc76969950 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -17,7 +17,7 @@ autocoder_setup_for_multiple_sources() #### function(locate_fpp_tools) # Loop through each tool, looking if it was found and check the version - foreach(TOOL FPP_DEPEND FPP_TO_XML FPP_TO_CPP FPP_LOCATE_DEFS) + foreach(TOOL FPP_DEPEND FPP_TO_XML FPP_TO_CPP FPP_LOCATE_DEFS FPP_TO_DICT) # Skipped already defined tools if (${TOOL}) continue() @@ -207,8 +207,11 @@ function(fpp_setup_autocode AC_INPUT_FILES) # Separate the source files into the CPP and XML steps set(GENERATED_AI) set(GENERATED_CPP) + set(GENERATED_DICT) foreach(GENERATED IN LISTS GENERATED_FILES) - if (GENERATED MATCHES ".*\\.xml") + if (GENERATED MATCHES ".*TopologyDictionary\.json") + list(APPEND GENERATED_DICT "${GENERATED}") + elseif (GENERATED MATCHES ".*\\.xml") list(APPEND GENERATED_AI "${GENERATED}") else() list(APPEND GENERATED_CPP "${GENERATED}") @@ -234,7 +237,25 @@ function(fpp_setup_autocode AC_INPUT_FILES) DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ) endif() - set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP}) + # Add in dictionary generation + if (GENERATED_DICT) + set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) + set(LIBRABRY_FLAG) + if (FPRIME_LIBRARY_LOCATIONS) + # TODO: add version number + set(LIBRABRY_FLAG "-l" "${FPRIME_LIBRARY_LOCATIONS}") + endif() + add_custom_command( + OUTPUT ${GENERATED_DICT} + COMMAND ${FPP_TO_DICT} + "-d" "${CMAKE_CURRENT_BINARY_DIR}" + "-p" "${CMAKE_PROJECT_VERSION}" # cmake project version is not git version - should get that instead? + ${LIBRABRY_FLAG} + ${IMPORTS} ${AC_INPUT_FILES} + DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} + ) +endif() + set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP} ${GENERATED_DICT}) set(AUTOCODER_GENERATED "${AUTOCODER_GENERATED}" PARENT_SCOPE) set(AUTOCODER_DEPENDENCIES "${MODULE_DEPENDENCIES}" PARENT_SCOPE) set(AUTOCODER_INCLUDES "${FILE_DEPENDENCIES}" PARENT_SCOPE) diff --git a/cmake/target/install.cmake b/cmake/target/install.cmake index 0b3df79e49..e42f2c44e7 100644 --- a/cmake/target/install.cmake +++ b/cmake/target/install.cmake @@ -50,7 +50,7 @@ function(install_add_deployment_target MODULE TARGET SOURCES DEPENDENCIES FULL_D ARCHIVE DESTINATION ${TOOLCHAIN_NAME}/${MODULE}/lib/static COMPONENT ${MODULE} ) - install(FILES ${FPRIME_CURRENT_DICTIONARY_FILE} DESTINATION ${TOOLCHAIN_NAME}/${MODULE}/dict COMPONENT ${MODULE}) + install(FILES ${FPRIME_CURRENT_DICTIONARY_FILE} ${FPRIME_CURRENT_DICTIONARY_FILE_JSON} DESTINATION ${TOOLCHAIN_NAME}/${MODULE}/dict COMPONENT ${MODULE}) add_custom_command(TARGET "${MODULE}" POST_BUILD COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=${MODULE} -P ${CMAKE_BINARY_DIR}/cmake_install.cmake) endfunction() From 8cb6ad6d34271332ff09a1cc60463d28bcae1cc0 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 18 Mar 2024 10:20:56 -0700 Subject: [PATCH 02/27] fix typo --- cmake/autocoder/fpp.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index fc76969950..42724d7b3a 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -240,17 +240,17 @@ function(fpp_setup_autocode AC_INPUT_FILES) # Add in dictionary generation if (GENERATED_DICT) set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) - set(LIBRABRY_FLAG) + set(LIBRARY_FLAG) if (FPRIME_LIBRARY_LOCATIONS) # TODO: add version number - set(LIBRABRY_FLAG "-l" "${FPRIME_LIBRARY_LOCATIONS}") + set(LIBRARY_FLAG "-l" "${FPRIME_LIBRARY_LOCATIONS}") endif() add_custom_command( OUTPUT ${GENERATED_DICT} COMMAND ${FPP_TO_DICT} "-d" "${CMAKE_CURRENT_BINARY_DIR}" "-p" "${CMAKE_PROJECT_VERSION}" # cmake project version is not git version - should get that instead? - ${LIBRABRY_FLAG} + ${LIBRARY_FLAG} ${IMPORTS} ${AC_INPUT_FILES} DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ) From d18d8dafede08203c82ed9e15ebf22be6230c8c8 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 18 Mar 2024 11:12:07 -0700 Subject: [PATCH 03/27] add UT --- cmake/test/src/test_ref_shared.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/test/src/test_ref_shared.py b/cmake/test/src/test_ref_shared.py index 3376b756fc..b4ab825d54 100644 --- a/cmake/test/src/test_ref_shared.py +++ b/cmake/test/src/test_ref_shared.py @@ -69,6 +69,19 @@ def test_ref_dictionary(REF_BUILD): assert output_path.exists(), "Failed to locate Ref in build output" +def test_ref_dictionary_json(REF_BUILD): + """Run reference and assert reference targets exit""" + cmake.assert_process_success(REF_BUILD) + output_path = ( + REF_BUILD["install"] + / platform.system() + / "Ref" + / "dict" + / "RefTopologyDictionary.json" + ) + assert output_path.exists(), "Failed to locate Ref JSON Dictionary in build output" + + def test_ref_module_info(REF_BUILD): """Run reference and assert module-info.txt was created""" cmake.assert_process_success(REF_BUILD) From 104b97ac648641e320f1196e86c2fc6aaaefda1e Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 11:37:19 -0700 Subject: [PATCH 04/27] Refacto versions handling and add libraryVersion --- .../Python/src/fprime_ac/utils/version.py | 16 ++++ Svc/SystemResources/SystemResources.cpp | 2 +- .../test/ut/SystemResourcesTester.cpp | 2 +- cmake/autocoder/fpp.cmake | 18 ++-- .../autocoder/scripts/fpp_to_dict_wrapper.py | 89 +++++++++++++++++++ cmake/required.cmake | 1 + cmake/target/version.cmake | 16 +++- .../target/version/generate_version_header.py | 68 +++++++++----- 8 files changed, 176 insertions(+), 36 deletions(-) create mode 100755 cmake/autocoder/scripts/fpp_to_dict_wrapper.py diff --git a/Autocoders/Python/src/fprime_ac/utils/version.py b/Autocoders/Python/src/fprime_ac/utils/version.py index 6fe5104d30..afa856e2ff 100644 --- a/Autocoders/Python/src/fprime_ac/utils/version.py +++ b/Autocoders/Python/src/fprime_ac/utils/version.py @@ -54,3 +54,19 @@ def get_project_version(fallback=FALLBACK_VERSION): """ fprime_directory = os.environ.get("FPRIME_PROJECT_ROOT", os.path.dirname(__file__)) return get_version_str(working_dir=fprime_directory, fallback=fallback) + + +def get_library_versions(fallback=FALLBACK_VERSION): + """Calculate the versions of each libraries. + Return a dictionary with the library name as key and the version as value + """ + fprime_libraries = os.environ.get("FPRIME_LIBRARY_LOCATIONS", None) + if fprime_libraries is None: + return {} + + lib_versions = {} + for library in fprime_libraries.split(":"): + library_name = os.path.basename(library) + lib_versions[library_name] = get_version_str(working_dir=library, fallback=fallback) + + return lib_versions diff --git a/Svc/SystemResources/SystemResources.cpp b/Svc/SystemResources/SystemResources.cpp index 23c1c5701d..8f972a3f7f 100644 --- a/Svc/SystemResources/SystemResources.cpp +++ b/Svc/SystemResources/SystemResources.cpp @@ -12,7 +12,7 @@ #include //isnan() #include -#include +#include #include namespace Svc { diff --git a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp index c970f2f84c..05d5ee8e08 100644 --- a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp +++ b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp @@ -11,7 +11,7 @@ // ====================================================================== #include "SystemResourcesTester.hpp" -#include "version.hpp" +#include "versions/version.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 100 diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 42724d7b3a..3468d9f38f 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -7,6 +7,7 @@ include_guard() include(utilities) include(autocoder/helpers) +set(FPRIME_FPP_TO_DICT_WRAPPER "${CMAKE_CURRENT_LIST_DIR}/scripts/fpp_to_dict_wrapper.py" CACHE PATH "Wrapper script to call fpp-to-dict with complex inputs") autocoder_setup_for_multiple_sources() #### @@ -241,16 +242,17 @@ function(fpp_setup_autocode AC_INPUT_FILES) if (GENERATED_DICT) set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) set(LIBRARY_FLAG) - if (FPRIME_LIBRARY_LOCATIONS) - # TODO: add version number - set(LIBRARY_FLAG "-l" "${FPRIME_LIBRARY_LOCATIONS}") - endif() + set(FPRIME_PROJECT_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.project") + set(FPRIME_FRAMEWORK_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.framework") + set(FPRIME_LIBRARIES_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.libraries") add_custom_command( OUTPUT ${GENERATED_DICT} - COMMAND ${FPP_TO_DICT} - "-d" "${CMAKE_CURRENT_BINARY_DIR}" - "-p" "${CMAKE_PROJECT_VERSION}" # cmake project version is not git version - should get that instead? - ${LIBRARY_FLAG} + COMMAND ${FPRIME_FPP_TO_DICT_WRAPPER} + "--executable" "${FPP_TO_DICT}" + "--cmake-bin-dir" "${CMAKE_CURRENT_BINARY_DIR}" + "--projectVersionFile" "${FPRIME_PROJECT_VERSION_FILE}" + "--frameworkVersionFile" "${FPRIME_FRAMEWORK_VERSION_FILE}" + "--libraryVersionFile" "${FPRIME_LIBRARIES_VERSION_FILE}" ${IMPORTS} ${AC_INPUT_FILES} DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py new file mode 100755 index 0000000000..cd50e7ee3f --- /dev/null +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +""" +fpp_to_dict_wrapper.py: + +Wrapper script to run fpp-to-dict within the build process. +This is required to be able to read the version files and pass them to the fpp-to-dict executable. + +@author thomas-bc +""" + +import subprocess +import argparse + + +def main(): + """ + Main program entry point + """ + parser = argparse.ArgumentParser(description="Create version header") + parser.add_argument( + "--executable", + required=True, + help="Path to the fpp-to-dict executable", + ) + parser.add_argument( + "sources", + nargs="+", + help="Source files", + ) + parser.add_argument( + "--projectVersionFile", + default=False, + help="Path to file containing Project version number", + ) + parser.add_argument( + "--frameworkVersionFile", + default=False, + help="Path to file containing Framework version number", + ) + parser.add_argument( + "--libraryVersionFile", + default=False, + help="Library version string", + ) + parser.add_argument( + "--cmake-bin-dir", + default=False, + help="Library version string", + ) + parser.add_argument( + "-i", + default=False, + help="Imports", + ) + args = parser.parse_args() + + with open(args.projectVersionFile, "r") as file: + project_version = file.read().strip() + with open(args.frameworkVersionFile, "r") as file: + framework_version = file.read().strip() + with open(args.libraryVersionFile, "r") as file: + libraries_version = file.read().strip() + + cmd_args = [ + args.executable, + "--directory", + args.cmake_bin_dir, + "--projectVersion", + project_version, + "--frameworkVersion", + framework_version, + "--libraryVersions", + libraries_version, + "--imports", + args.i, + *args.sources + ] + + subprocess.Popen( + args=cmd_args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + return 0 + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/cmake/required.cmake b/cmake/required.cmake index 015932ad53..5aaa29618b 100644 --- a/cmake/required.cmake +++ b/cmake/required.cmake @@ -35,4 +35,5 @@ message(STATUS "[python3] python3 found at: ${PYTHON}") message(STATUS "[fpp-tools] fpp-depend found at: ${FPP_DEPEND}") message(STATUS "[fpp-tools] fpp-to-xml found at: ${FPP_TO_XML}") message(STATUS "[fpp-tools] fpp-to-cpp found at: ${FPP_TO_CPP}") +message(STATUS "[fpp-tools] fpp-to-dict found at: ${FPP_TO_DICT}") message(STATUS "[fpp-tools] fpp-locate-defs found at: ${FPP_LOCATE_DEFS}") diff --git a/cmake/target/version.cmake b/cmake/target/version.cmake index 6d21cfd325..c9a7a6b9c9 100644 --- a/cmake/target/version.cmake +++ b/cmake/target/version.cmake @@ -1,20 +1,28 @@ #### # cmake/target/version.cmake: # -# A basic versioning target which will produce the version.hpp file. +# A basic versioning target which will produce the version files. #### set(FPRIME_VERSION_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_header.py" CACHE PATH "Script used to generate version.hpp") function(version_add_global_target TARGET) - set(OUTPUT_FILE "${CMAKE_BINARY_DIR}/version.hpp") + set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/versions") + file(MAKE_DIRECTORY ${OUTPUT_DIR}) + # TODO: change output file thing + set(OUTPUT_FILE "${OUTPUT_DIR}/version.hpp") # Add check argument when requested set(OPTIONAL_CHECK_ARG) + string(REGEX REPLACE ";" ":" FPRIME_LIBRARY_LOCATIONS_CSV "${FPRIME_LIBRARY_LOCATIONS}") if (FPRIME_CHECK_FRAMEWORK_VERSION) set(OPTIONAL_CHECK_ARG "--check") endif() add_custom_target("${TARGET}" ALL BYPRODUCTS "${OUTPUT_FILE}" - COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${PYTHONPATH}:${FPRIME_FRAMEWORK_PATH}/Autocoders/Python/src" - "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_FILE}.tmp" "${OPTIONAL_CHECK_ARG}" + COMMAND "${CMAKE_COMMAND}" + -E env "PYTHONPATH=${PYTHONPATH}:${FPRIME_FRAMEWORK_PATH}/Autocoders/Python/src" + "FPRIME_PROJECT_ROOT=${FPRIME_PROJECT_ROOT}" + "FPRIME_FRAMEWORK_PATH=${FPRIME_FRAMEWORK_PATH}" + "FPRIME_LIBRARY_LOCATIONS=${FPRIME_LIBRARY_LOCATIONS_CSV}" + "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_FILE}.tmp" "${OUTPUT_FILE}" WORKING_DIRECTORY "${FPRIME_PROJECT_ROOT}" ) diff --git a/cmake/target/version/generate_version_header.py b/cmake/target/version/generate_version_header.py index 9ed5bafe1c..5cc339a0b7 100755 --- a/cmake/target/version/generate_version_header.py +++ b/cmake/target/version/generate_version_header.py @@ -20,37 +20,60 @@ import argparse import os import sys +from pathlib import Path from fprime_ac.utils.version import ( FALLBACK_VERSION, get_fprime_version, get_project_version, + get_library_versions, ) -def create_version_file(fid, framework_version, project_version): +def create_version_file(output_dir, framework_version, project_version): """ Create the version file using the provided name and path. """ + version_hpp = Path(output_dir) / "version.hpp.tmp" # Open file for writing - fid.write("/*\n") - fid.write( - " This file has been autogenerated using [{}].\n".format( - os.path.basename(__file__) + with open(version_hpp, "w") as fid: + fid.write("/*\n") + fid.write( + " This file has been autogenerated using [{}].\n".format( + os.path.basename(__file__) + ) ) - ) - fid.write(" This file may be overwritten.\n") - fid.write("*/\n") - fid.write("#ifndef _VERSION_HPP_\n") - fid.write("#define _VERSION_HPP_\n") - fid.write("\n") - fid.write( - 'static const char* FRAMEWORK_VERSION = "{}";\n'.format(framework_version) - ) - fid.write('static const char* PROJECT_VERSION = "{}";\n'.format(framework_version)) - fid.write("\n") - fid.write("#endif\n") - fid.write("\n") + fid.write(" This file may be overwritten.\n") + fid.write("*/\n") + fid.write("#ifndef _VERSION_HPP_\n") + fid.write("#define _VERSION_HPP_\n") + fid.write("\n") + fid.write( + 'static const char* FRAMEWORK_VERSION = "{}";\n'.format(framework_version) + ) + fid.write('static const char* PROJECT_VERSION = "{}";\n'.format(project_version)) + fid.write("\n") + fid.write("#endif\n") + fid.write("\n") + # TODO: add library versions to this file + + +def create_version_files_raw_txt(output_dir, framework_version, project_version, lib_versions): + """ + Create the version files using the provided name and path. + """ + framework_file = Path(output_dir) / "version.framework" + project_file = Path(output_dir) / "version.project" + lib_file = Path(output_dir) / "version.libraries" + print(str(framework_file)) + + with open(framework_file, "w") as file: + file.write(framework_version) + with open(project_file, "w") as file: + file.write(project_version) + with open(lib_file, "w") as file: + for lib, version in lib_versions.items(): + file.write(f"{lib}@{version},") def main(): @@ -59,10 +82,9 @@ def main(): """ parser = argparse.ArgumentParser(description="Create version header") parser.add_argument( - "output", + "output_dir", nargs="?", - type=argparse.FileType("w"), - default=sys.stdout, + default=".", help="Path to write version header into", ) parser.add_argument( @@ -76,7 +98,9 @@ def main(): # Build the version output fprime_version = get_fprime_version() project_version = get_project_version() - create_version_file(args.output, fprime_version, project_version) + lib_versions = get_library_versions() + create_version_file(args.output_dir, fprime_version, project_version) + create_version_files_raw_txt(args.output_dir, fprime_version, project_version, lib_versions) # Check version if asked to do so if args.check and not fprime_version.startswith(FALLBACK_VERSION): From 8cc966e27a38bfdbc28a8940b18da136236beb9c Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 11:38:54 -0700 Subject: [PATCH 05/27] Python format --- Autocoders/Python/src/fprime_ac/utils/version.py | 7 +++++-- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 4 ++-- cmake/target/version/generate_version_header.py | 12 +++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Autocoders/Python/src/fprime_ac/utils/version.py b/Autocoders/Python/src/fprime_ac/utils/version.py index afa856e2ff..e33e33b36f 100644 --- a/Autocoders/Python/src/fprime_ac/utils/version.py +++ b/Autocoders/Python/src/fprime_ac/utils/version.py @@ -1,4 +1,5 @@ """ fprime version handling and reporting """ + import os import subprocess @@ -57,7 +58,7 @@ def get_project_version(fallback=FALLBACK_VERSION): def get_library_versions(fallback=FALLBACK_VERSION): - """Calculate the versions of each libraries. + """Calculate the versions of each libraries. Return a dictionary with the library name as key and the version as value """ fprime_libraries = os.environ.get("FPRIME_LIBRARY_LOCATIONS", None) @@ -67,6 +68,8 @@ def get_library_versions(fallback=FALLBACK_VERSION): lib_versions = {} for library in fprime_libraries.split(":"): library_name = os.path.basename(library) - lib_versions[library_name] = get_version_str(working_dir=library, fallback=fallback) + lib_versions[library_name] = get_version_str( + working_dir=library, fallback=fallback + ) return lib_versions diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index cd50e7ee3f..ff8b006e88 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -73,7 +73,7 @@ def main(): libraries_version, "--imports", args.i, - *args.sources + *args.sources, ] subprocess.Popen( @@ -86,4 +86,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/cmake/target/version/generate_version_header.py b/cmake/target/version/generate_version_header.py index 5cc339a0b7..372ab552c1 100755 --- a/cmake/target/version/generate_version_header.py +++ b/cmake/target/version/generate_version_header.py @@ -51,14 +51,18 @@ def create_version_file(output_dir, framework_version, project_version): fid.write( 'static const char* FRAMEWORK_VERSION = "{}";\n'.format(framework_version) ) - fid.write('static const char* PROJECT_VERSION = "{}";\n'.format(project_version)) + fid.write( + 'static const char* PROJECT_VERSION = "{}";\n'.format(project_version) + ) fid.write("\n") fid.write("#endif\n") fid.write("\n") # TODO: add library versions to this file -def create_version_files_raw_txt(output_dir, framework_version, project_version, lib_versions): +def create_version_files_raw_txt( + output_dir, framework_version, project_version, lib_versions +): """ Create the version files using the provided name and path. """ @@ -100,7 +104,9 @@ def main(): project_version = get_project_version() lib_versions = get_library_versions() create_version_file(args.output_dir, fprime_version, project_version) - create_version_files_raw_txt(args.output_dir, fprime_version, project_version, lib_versions) + create_version_files_raw_txt( + args.output_dir, fprime_version, project_version, lib_versions + ) # Check version if asked to do so if args.check and not fprime_version.startswith(FALLBACK_VERSION): From 21a117c320e19b0009a0d3291fe29b14c798c71b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 12:18:46 -0700 Subject: [PATCH 06/27] Pass in libraries only if not empty --- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index ff8b006e88..e2fbed67a0 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -54,6 +54,7 @@ def main(): ) args = parser.parse_args() + # Read versions from files with open(args.projectVersionFile, "r") as file: project_version = file.read().strip() with open(args.frameworkVersionFile, "r") as file: @@ -69,8 +70,7 @@ def main(): project_version, "--frameworkVersion", framework_version, - "--libraryVersions", - libraries_version, + *(["--libraryVersions", libraries_version] if libraries_version else []), "--imports", args.i, *args.sources, From 01541fcfd5f75b8c12fcea01231eb22af9311412 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 12:19:59 -0700 Subject: [PATCH 07/27] Fix logic --- Autocoders/Python/src/fprime_ac/utils/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Autocoders/Python/src/fprime_ac/utils/version.py b/Autocoders/Python/src/fprime_ac/utils/version.py index e33e33b36f..70a12cfb9e 100644 --- a/Autocoders/Python/src/fprime_ac/utils/version.py +++ b/Autocoders/Python/src/fprime_ac/utils/version.py @@ -61,8 +61,8 @@ def get_library_versions(fallback=FALLBACK_VERSION): """Calculate the versions of each libraries. Return a dictionary with the library name as key and the version as value """ - fprime_libraries = os.environ.get("FPRIME_LIBRARY_LOCATIONS", None) - if fprime_libraries is None: + fprime_libraries = os.environ.get("FPRIME_LIBRARY_LOCATIONS", "") + if fprime_libraries == "": return {} lib_versions = {} From d40d41055ffb63585b9289d53fde317c056df058 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 16:42:15 -0700 Subject: [PATCH 08/27] debug stuff --- cmake/autocoder/fpp.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 3468d9f38f..a6f2b02aee 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -241,6 +241,9 @@ function(fpp_setup_autocode AC_INPUT_FILES) # Add in dictionary generation if (GENERATED_DICT) set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) + message(STATUS "[DEBUG] Dictionary file: ${FPRIME_CURRENT_DICTIONARY_FILE_JSON}") + message(STATUS "[DEBUG] Install prefix : ${CMAKE_INSTALL_PREFIX}") + message(STATUS "[DEBUG] CMake bin dir: ${CMAKE_CURRENT_BINARY_DIR}") set(LIBRARY_FLAG) set(FPRIME_PROJECT_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.project") set(FPRIME_FRAMEWORK_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.framework") From 8332abd2a1faea518eb7d6049faea02f089de2c5 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 17:38:00 -0700 Subject: [PATCH 09/27] Add correct dependencies --- Autocoders/Python/src/fprime_ac/utils/version.py | 1 - cmake/autocoder/fpp.cmake | 2 +- cmake/target/version/generate_version_header.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Autocoders/Python/src/fprime_ac/utils/version.py b/Autocoders/Python/src/fprime_ac/utils/version.py index 70a12cfb9e..67bb3eeecb 100644 --- a/Autocoders/Python/src/fprime_ac/utils/version.py +++ b/Autocoders/Python/src/fprime_ac/utils/version.py @@ -71,5 +71,4 @@ def get_library_versions(fallback=FALLBACK_VERSION): lib_versions[library_name] = get_version_str( working_dir=library, fallback=fallback ) - return lib_versions diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index a6f2b02aee..97459bd63f 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -257,7 +257,7 @@ function(fpp_setup_autocode AC_INPUT_FILES) "--frameworkVersionFile" "${FPRIME_FRAMEWORK_VERSION_FILE}" "--libraryVersionFile" "${FPRIME_LIBRARIES_VERSION_FILE}" ${IMPORTS} ${AC_INPUT_FILES} - DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} + DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ${FPRIME_PROJECT_VERSION_FILE} ${FPRIME_FRAMEWORK_VERSION_FILE} ${FPRIME_LIBRARIES_VERSION_FILE} ) endif() set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP} ${GENERATED_DICT}) diff --git a/cmake/target/version/generate_version_header.py b/cmake/target/version/generate_version_header.py index 372ab552c1..cef06110ab 100755 --- a/cmake/target/version/generate_version_header.py +++ b/cmake/target/version/generate_version_header.py @@ -69,7 +69,6 @@ def create_version_files_raw_txt( framework_file = Path(output_dir) / "version.framework" project_file = Path(output_dir) / "version.project" lib_file = Path(output_dir) / "version.libraries" - print(str(framework_file)) with open(framework_file, "w") as file: file.write(framework_version) From a689516f21431768f0fd0de95a1dd5b91cbcbf76 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 17:55:06 -0700 Subject: [PATCH 10/27] More debugging --- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index e2fbed67a0..58802ad80a 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -75,11 +75,10 @@ def main(): args.i, *args.sources, ] + print(cmd_args) subprocess.Popen( - args=cmd_args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + args=cmd_args ) return 0 From 172d09f30b10624a83ac07c56e3009340726f133 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 18:10:21 -0700 Subject: [PATCH 11/27] Fix output files --- cmake/target/version.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/target/version.cmake b/cmake/target/version.cmake index c9a7a6b9c9..f72d05565f 100644 --- a/cmake/target/version.cmake +++ b/cmake/target/version.cmake @@ -7,9 +7,9 @@ set(FPRIME_VERSION_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_he function(version_add_global_target TARGET) set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/versions") + set(OUTPUT_HPP "${OUTPUT_DIR}/version.hpp") + set(OUTPUT_FILES "${OUTPUT_HPP}" "${OUTPUT_DIR}/version.project" "${OUTPUT_DIR}/version.framework" "${OUTPUT_DIR}/version.libraries") file(MAKE_DIRECTORY ${OUTPUT_DIR}) - # TODO: change output file thing - set(OUTPUT_FILE "${OUTPUT_DIR}/version.hpp") # Add check argument when requested set(OPTIONAL_CHECK_ARG) string(REGEX REPLACE ";" ":" FPRIME_LIBRARY_LOCATIONS_CSV "${FPRIME_LIBRARY_LOCATIONS}") @@ -23,7 +23,7 @@ function(version_add_global_target TARGET) "FPRIME_FRAMEWORK_PATH=${FPRIME_FRAMEWORK_PATH}" "FPRIME_LIBRARY_LOCATIONS=${FPRIME_LIBRARY_LOCATIONS_CSV}" "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" - COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_FILE}.tmp" "${OUTPUT_FILE}" + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_HPP}.tmp" "${OUTPUT_FILES}" WORKING_DIRECTORY "${FPRIME_PROJECT_ROOT}" ) endfunction() From bdccec26fc867298e68dd560ed67be913bdcc7f4 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 18:12:54 -0700 Subject: [PATCH 12/27] oops --- cmake/target/version.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/target/version.cmake b/cmake/target/version.cmake index f72d05565f..fc2def0a2d 100644 --- a/cmake/target/version.cmake +++ b/cmake/target/version.cmake @@ -16,14 +16,14 @@ function(version_add_global_target TARGET) if (FPRIME_CHECK_FRAMEWORK_VERSION) set(OPTIONAL_CHECK_ARG "--check") endif() - add_custom_target("${TARGET}" ALL BYPRODUCTS "${OUTPUT_FILE}" + add_custom_target("${TARGET}" ALL BYPRODUCTS "${OUTPUT_FILES}" COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${PYTHONPATH}:${FPRIME_FRAMEWORK_PATH}/Autocoders/Python/src" "FPRIME_PROJECT_ROOT=${FPRIME_PROJECT_ROOT}" "FPRIME_FRAMEWORK_PATH=${FPRIME_FRAMEWORK_PATH}" "FPRIME_LIBRARY_LOCATIONS=${FPRIME_LIBRARY_LOCATIONS_CSV}" "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" - COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_HPP}.tmp" "${OUTPUT_FILES}" + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_HPP}.tmp" "${OUTPUT_HPP}" WORKING_DIRECTORY "${FPRIME_PROJECT_ROOT}" ) endfunction() From 95e2ec9e4151ab49c26acc94432e550ca14523f9 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 17 Apr 2024 18:28:28 -0700 Subject: [PATCH 13/27] Call synchronously --- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index 58802ad80a..fc050ee928 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -77,11 +77,10 @@ def main(): ] print(cmd_args) - subprocess.Popen( + return subprocess.call( args=cmd_args ) - return 0 if __name__ == "__main__": From bf49c69bb646b1ba79185247ba5a6ed4469cd70c Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Thu, 18 Apr 2024 16:11:08 -0700 Subject: [PATCH 14/27] Explicitely add `version` target to dependency list --- cmake/autocoder/fpp.cmake | 9 +++++---- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 97459bd63f..c175723af0 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -241,9 +241,6 @@ function(fpp_setup_autocode AC_INPUT_FILES) # Add in dictionary generation if (GENERATED_DICT) set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) - message(STATUS "[DEBUG] Dictionary file: ${FPRIME_CURRENT_DICTIONARY_FILE_JSON}") - message(STATUS "[DEBUG] Install prefix : ${CMAKE_INSTALL_PREFIX}") - message(STATUS "[DEBUG] CMake bin dir: ${CMAKE_CURRENT_BINARY_DIR}") set(LIBRARY_FLAG) set(FPRIME_PROJECT_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.project") set(FPRIME_FRAMEWORK_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.framework") @@ -257,7 +254,11 @@ function(fpp_setup_autocode AC_INPUT_FILES) "--frameworkVersionFile" "${FPRIME_FRAMEWORK_VERSION_FILE}" "--libraryVersionFile" "${FPRIME_LIBRARIES_VERSION_FILE}" ${IMPORTS} ${AC_INPUT_FILES} - DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ${FPRIME_PROJECT_VERSION_FILE} ${FPRIME_FRAMEWORK_VERSION_FILE} ${FPRIME_LIBRARIES_VERSION_FILE} + DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} + ${FPRIME_PROJECT_VERSION_FILE} + ${FPRIME_FRAMEWORK_VERSION_FILE} + ${FPRIME_LIBRARIES_VERSION_FILE} + version ) endif() set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP} ${GENERATED_DICT}) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index fc050ee928..db2c8b2334 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -77,10 +77,7 @@ def main(): ] print(cmd_args) - return subprocess.call( - args=cmd_args - ) - + return subprocess.call(args=cmd_args) if __name__ == "__main__": From 8578ae092245a5800b6eddbd098ad788cc1b1bac Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Apr 2024 17:09:30 -0700 Subject: [PATCH 15/27] Add libVersions in HPP and some refactoring --- .../Python/src/fprime_ac/utils/version.py | 2 +- cmake/autocoder/fpp.cmake | 13 ++---- .../autocoder/scripts/fpp_to_dict_wrapper.py | 35 ++++++--------- cmake/target/version.cmake | 7 +-- ...ion_header.py => generate_version_info.py} | 43 +++++++++---------- 5 files changed, 42 insertions(+), 58 deletions(-) rename cmake/target/version/{generate_version_header.py => generate_version_info.py} (70%) diff --git a/Autocoders/Python/src/fprime_ac/utils/version.py b/Autocoders/Python/src/fprime_ac/utils/version.py index 67bb3eeecb..b332790b4c 100644 --- a/Autocoders/Python/src/fprime_ac/utils/version.py +++ b/Autocoders/Python/src/fprime_ac/utils/version.py @@ -57,7 +57,7 @@ def get_project_version(fallback=FALLBACK_VERSION): return get_version_str(working_dir=fprime_directory, fallback=fallback) -def get_library_versions(fallback=FALLBACK_VERSION): +def get_library_versions(fallback=FALLBACK_VERSION) -> dict: """Calculate the versions of each libraries. Return a dictionary with the library name as key and the version as value """ diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index c175723af0..8cde3454ab 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -241,23 +241,16 @@ function(fpp_setup_autocode AC_INPUT_FILES) # Add in dictionary generation if (GENERATED_DICT) set(FPRIME_CURRENT_DICTIONARY_FILE_JSON "${GENERATED_DICT}" CACHE INTERNAL "" FORCE) - set(LIBRARY_FLAG) - set(FPRIME_PROJECT_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.project") - set(FPRIME_FRAMEWORK_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.framework") - set(FPRIME_LIBRARIES_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.libraries") + set(FPRIME_JSON_VERSION_FILE "${CMAKE_BINARY_DIR}/versions/version.json") add_custom_command( OUTPUT ${GENERATED_DICT} COMMAND ${FPRIME_FPP_TO_DICT_WRAPPER} "--executable" "${FPP_TO_DICT}" "--cmake-bin-dir" "${CMAKE_CURRENT_BINARY_DIR}" - "--projectVersionFile" "${FPRIME_PROJECT_VERSION_FILE}" - "--frameworkVersionFile" "${FPRIME_FRAMEWORK_VERSION_FILE}" - "--libraryVersionFile" "${FPRIME_LIBRARIES_VERSION_FILE}" + "--jsonVersionFile" "${FPRIME_JSON_VERSION_FILE}" ${IMPORTS} ${AC_INPUT_FILES} DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} - ${FPRIME_PROJECT_VERSION_FILE} - ${FPRIME_FRAMEWORK_VERSION_FILE} - ${FPRIME_LIBRARIES_VERSION_FILE} + ${FPRIME_JSON_VERSION_FILE} version ) endif() diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index db2c8b2334..a60780bfb9 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -10,6 +10,7 @@ import subprocess import argparse +import json def main(): @@ -28,19 +29,9 @@ def main(): help="Source files", ) parser.add_argument( - "--projectVersionFile", + "--jsonVersionFile", default=False, - help="Path to file containing Project version number", - ) - parser.add_argument( - "--frameworkVersionFile", - default=False, - help="Path to file containing Framework version number", - ) - parser.add_argument( - "--libraryVersionFile", - default=False, - help="Library version string", + help="Path to file containing versions in JSON format", ) parser.add_argument( "--cmake-bin-dir", @@ -54,23 +45,23 @@ def main(): ) args = parser.parse_args() - # Read versions from files - with open(args.projectVersionFile, "r") as file: - project_version = file.read().strip() - with open(args.frameworkVersionFile, "r") as file: - framework_version = file.read().strip() - with open(args.libraryVersionFile, "r") as file: - libraries_version = file.read().strip() + # Read versions from file + with open(args.jsonVersionFile, "r") as file: + json_version = json.load(file) + # Parses library versions into a string to input to fpp-to-dict + libs_str = ",".join( + f"{lib}@{version}" for lib, version in json_version.get("libraries", {}).items() + ) cmd_args = [ args.executable, "--directory", args.cmake_bin_dir, "--projectVersion", - project_version, + json_version.get("project", "0.0.0"), "--frameworkVersion", - framework_version, - *(["--libraryVersions", libraries_version] if libraries_version else []), + json_version.get("framework", "0.0.0"), + *(["--libraryVersions", libs_str] if libs_str else []), # "" unpacks nothing "--imports", args.i, *args.sources, diff --git a/cmake/target/version.cmake b/cmake/target/version.cmake index fc2def0a2d..5498a31aee 100644 --- a/cmake/target/version.cmake +++ b/cmake/target/version.cmake @@ -3,12 +3,12 @@ # # A basic versioning target which will produce the version files. #### -set(FPRIME_VERSION_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_header.py" CACHE PATH "Script used to generate version.hpp") +set(FPRIME_VERSION_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_info.py" CACHE PATH "Script used to generate version files") function(version_add_global_target TARGET) set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/versions") set(OUTPUT_HPP "${OUTPUT_DIR}/version.hpp") - set(OUTPUT_FILES "${OUTPUT_HPP}" "${OUTPUT_DIR}/version.project" "${OUTPUT_DIR}/version.framework" "${OUTPUT_DIR}/version.libraries") + set(OUTPUT_JSON "${OUTPUT_DIR}/version.json") file(MAKE_DIRECTORY ${OUTPUT_DIR}) # Add check argument when requested set(OPTIONAL_CHECK_ARG) @@ -16,7 +16,7 @@ function(version_add_global_target TARGET) if (FPRIME_CHECK_FRAMEWORK_VERSION) set(OPTIONAL_CHECK_ARG "--check") endif() - add_custom_target("${TARGET}" ALL BYPRODUCTS "${OUTPUT_FILES}" + add_custom_target("${TARGET}" ALL BYPRODUCTS "${OUTPUT_HPP}" "${OUTPUT_JSON}" COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${PYTHONPATH}:${FPRIME_FRAMEWORK_PATH}/Autocoders/Python/src" "FPRIME_PROJECT_ROOT=${FPRIME_PROJECT_ROOT}" @@ -24,6 +24,7 @@ function(version_add_global_target TARGET) "FPRIME_LIBRARY_LOCATIONS=${FPRIME_LIBRARY_LOCATIONS_CSV}" "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_HPP}.tmp" "${OUTPUT_HPP}" + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_JSON}.tmp" "${OUTPUT_JSON}" WORKING_DIRECTORY "${FPRIME_PROJECT_ROOT}" ) endfunction() diff --git a/cmake/target/version/generate_version_header.py b/cmake/target/version/generate_version_info.py similarity index 70% rename from cmake/target/version/generate_version_header.py rename to cmake/target/version/generate_version_info.py index cef06110ab..830717bcb6 100755 --- a/cmake/target/version/generate_version_header.py +++ b/cmake/target/version/generate_version_info.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 """ # =============================================================================== -# NAME: generate_version_header.py +# NAME: generate_version_info.py # -# DESCRIPTION: Creates a version header file of specified name. -# It takes as input a filename and creates a header file -# with a constant string which is the git hash of the current version +# DESCRIPTION: Creates a version.hpp and version.json file with version informations # -# USAGE: ./generate_version_header.py /path/tofile/version.hpp +# USAGE: ./generate_version_info.py /path/to/outdir/ # # AUTHOR: sfregoso # EMAIL: sfregoso@jpl.nasa.gov @@ -20,6 +18,7 @@ import argparse import os import sys +import json from pathlib import Path from fprime_ac.utils.version import ( @@ -30,7 +29,7 @@ ) -def create_version_file(output_dir, framework_version, project_version): +def create_version_file_hpp(output_dir, framework_version, project_version): """ Create the version file using the provided name and path. """ @@ -54,29 +53,29 @@ def create_version_file(output_dir, framework_version, project_version): fid.write( 'static const char* PROJECT_VERSION = "{}";\n'.format(project_version) ) + fid.write("static const char* LIBRARY_VERSIONS[] = {\n") + for lib, version in get_library_versions().items(): + fid.write(f' "{lib}@{version}",\n') + fid.write("};\n") fid.write("\n") fid.write("#endif\n") fid.write("\n") - # TODO: add library versions to this file -def create_version_files_raw_txt( - output_dir, framework_version, project_version, lib_versions +def create_version_file_json( + output_dir: str, framework_version: str, project_version: str, lib_versions: dict ): """ Create the version files using the provided name and path. """ - framework_file = Path(output_dir) / "version.framework" - project_file = Path(output_dir) / "version.project" - lib_file = Path(output_dir) / "version.libraries" - - with open(framework_file, "w") as file: - file.write(framework_version) - with open(project_file, "w") as file: - file.write(project_version) - with open(lib_file, "w") as file: - for lib, version in lib_versions.items(): - file.write(f"{lib}@{version},") + json_file = Path(output_dir) / "version.json.tmp" + json_obj = { + "framework": framework_version, + "project": project_version, + "libraries": lib_versions, + } + with open(json_file, "w") as file: + json.dump(json_obj, file) def main(): @@ -102,8 +101,8 @@ def main(): fprime_version = get_fprime_version() project_version = get_project_version() lib_versions = get_library_versions() - create_version_file(args.output_dir, fprime_version, project_version) - create_version_files_raw_txt( + create_version_file_hpp(args.output_dir, fprime_version, project_version) + create_version_file_json( args.output_dir, fprime_version, project_version, lib_versions ) From 9c38ec451804c7e3448eaa90e3f93c143da73c8b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Apr 2024 17:53:59 -0700 Subject: [PATCH 16/27] remove LIBRARY_VERSIONS if empty --- .../autocoder/scripts/fpp_to_dict_wrapper.py | 18 ++++++++----- cmake/target/version/generate_version_info.py | 27 ++++++++----------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index a60780bfb9..98c4f8e30c 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -45,28 +45,34 @@ def main(): ) args = parser.parse_args() - # Read versions from file with open(args.jsonVersionFile, "r") as file: - json_version = json.load(file) + versions = json.load(file) + # Parses library versions into a string to input to fpp-to-dict libs_str = ",".join( - f"{lib}@{version}" for lib, version in json_version.get("libraries", {}).items() + f"{lib}@{version}" for lib, version in versions.get("libraries", {}).items() ) + if ( + versions.get("framework_version", None) is None + or versions.get("project_version", None) is None + ): + raise ValueError( + f"{args.jsonVersionFile} is missing 'framework_version' or 'project_version'" + ) cmd_args = [ args.executable, "--directory", args.cmake_bin_dir, "--projectVersion", - json_version.get("project", "0.0.0"), + versions.get("project_version"), "--frameworkVersion", - json_version.get("framework", "0.0.0"), + versions.get("framework_version"), *(["--libraryVersions", libs_str] if libs_str else []), # "" unpacks nothing "--imports", args.i, *args.sources, ] - print(cmd_args) return subprocess.call(args=cmd_args) diff --git a/cmake/target/version/generate_version_info.py b/cmake/target/version/generate_version_info.py index 830717bcb6..c5afcf0ce4 100755 --- a/cmake/target/version/generate_version_info.py +++ b/cmake/target/version/generate_version_info.py @@ -38,25 +38,20 @@ def create_version_file_hpp(output_dir, framework_version, project_version): with open(version_hpp, "w") as fid: fid.write("/*\n") fid.write( - " This file has been autogenerated using [{}].\n".format( - os.path.basename(__file__) - ) + f" This file has been autogenerated using [{os.path.basename(__file__)}].\n" ) fid.write(" This file may be overwritten.\n") fid.write("*/\n") fid.write("#ifndef _VERSION_HPP_\n") fid.write("#define _VERSION_HPP_\n") fid.write("\n") - fid.write( - 'static const char* FRAMEWORK_VERSION = "{}";\n'.format(framework_version) - ) - fid.write( - 'static const char* PROJECT_VERSION = "{}";\n'.format(project_version) - ) - fid.write("static const char* LIBRARY_VERSIONS[] = {\n") - for lib, version in get_library_versions().items(): - fid.write(f' "{lib}@{version}",\n') - fid.write("};\n") + fid.write(f'static const char* FRAMEWORK_VERSION = "{framework_version}";\n') + fid.write(f'static const char* PROJECT_VERSION = "{project_version}";\n') + if len(get_library_versions()) > 0: + fid.write("static const char* LIBRARY_VERSIONS[] = {\n") + for lib, version in get_library_versions().items(): + fid.write(f' "{lib}@{version}",\n') + fid.write("};\n") fid.write("\n") fid.write("#endif\n") fid.write("\n") @@ -70,9 +65,9 @@ def create_version_file_json( """ json_file = Path(output_dir) / "version.json.tmp" json_obj = { - "framework": framework_version, - "project": project_version, - "libraries": lib_versions, + "framework_version": framework_version, + "project_version": project_version, + "library_versions": lib_versions, } with open(json_file, "w") as file: json.dump(json_obj, file) From d19355d41e900506f2d544e550c9f0c37576a87f Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Apr 2024 18:18:00 -0700 Subject: [PATCH 17/27] Add CMake test for version target --- cmake/test/src/test_ref_shared.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/test/src/test_ref_shared.py b/cmake/test/src/test_ref_shared.py index b4ab825d54..b7e68480f3 100644 --- a/cmake/test/src/test_ref_shared.py +++ b/cmake/test/src/test_ref_shared.py @@ -11,6 +11,7 @@ import cmake +import json from pathlib import Path _ = cmake.get_build( @@ -70,7 +71,7 @@ def test_ref_dictionary(REF_BUILD): def test_ref_dictionary_json(REF_BUILD): - """Run reference and assert reference targets exit""" + """Build Ref and assert JSON dictionary exists""" cmake.assert_process_success(REF_BUILD) output_path = ( REF_BUILD["install"] @@ -81,6 +82,16 @@ def test_ref_dictionary_json(REF_BUILD): ) assert output_path.exists(), "Failed to locate Ref JSON Dictionary in build output" +def test_ref_version_info(REF_BUILD): + """Build Ref and assert version files exist""" + cmake.assert_process_success(REF_BUILD) + version_hpp = REF_BUILD["build"] / "versions" / "version.hpp" + version_json = REF_BUILD["build"] / "versions" / "version.json" + assert version_hpp.exists(), "Failed to locate version.hpp in build output" + assert version_json.exists(), "Failed to locate version.json in build output" + versions_dict = json.loads(version_json.read_text()) + for key in ["framework_version", "project_version", "library_versions"]: + assert key in versions_dict, f"Failed to locate key: {key} in version.json" def test_ref_module_info(REF_BUILD): """Run reference and assert module-info.txt was created""" From f51058aa5f4873171f7ed89d9453c1f915b21b6f Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Apr 2024 18:21:11 -0700 Subject: [PATCH 18/27] formatting --- cmake/test/src/test_ref_shared.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/test/src/test_ref_shared.py b/cmake/test/src/test_ref_shared.py index b7e68480f3..71d9c0f9a1 100644 --- a/cmake/test/src/test_ref_shared.py +++ b/cmake/test/src/test_ref_shared.py @@ -82,10 +82,11 @@ def test_ref_dictionary_json(REF_BUILD): ) assert output_path.exists(), "Failed to locate Ref JSON Dictionary in build output" + def test_ref_version_info(REF_BUILD): """Build Ref and assert version files exist""" cmake.assert_process_success(REF_BUILD) - version_hpp = REF_BUILD["build"] / "versions" / "version.hpp" + version_hpp = REF_BUILD["build"] / "versions" / "version.hpp" version_json = REF_BUILD["build"] / "versions" / "version.json" assert version_hpp.exists(), "Failed to locate version.hpp in build output" assert version_json.exists(), "Failed to locate version.json in build output" @@ -93,6 +94,7 @@ def test_ref_version_info(REF_BUILD): for key in ["framework_version", "project_version", "library_versions"]: assert key in versions_dict, f"Failed to locate key: {key} in version.json" + def test_ref_module_info(REF_BUILD): """Run reference and assert module-info.txt was created""" cmake.assert_process_success(REF_BUILD) From 772c727ea47805d33e2af282d100eedd4d4a980d Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Tue, 23 Apr 2024 18:23:06 -0700 Subject: [PATCH 19/27] Generate empty string when no libraries are present --- cmake/target/version/generate_version_info.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/target/version/generate_version_info.py b/cmake/target/version/generate_version_info.py index c5afcf0ce4..11bfe97611 100755 --- a/cmake/target/version/generate_version_info.py +++ b/cmake/target/version/generate_version_info.py @@ -47,10 +47,14 @@ def create_version_file_hpp(output_dir, framework_version, project_version): fid.write("\n") fid.write(f'static const char* FRAMEWORK_VERSION = "{framework_version}";\n') fid.write(f'static const char* PROJECT_VERSION = "{project_version}";\n') - if len(get_library_versions()) > 0: - fid.write("static const char* LIBRARY_VERSIONS[] = {\n") - for lib, version in get_library_versions().items(): - fid.write(f' "{lib}@{version}",\n') + lib_versions = get_library_versions() + fid.write("static const char* LIBRARY_VERSIONS[] = {") + if len(lib_versions) == 0: + fid.write(" \"\" };\n") # Empty string when no libraries are present + else: + fid.write("\n") + for lib_name, version in lib_versions.items(): + fid.write(f' "{lib_name}@{version}",\n') fid.write("};\n") fid.write("\n") fid.write("#endif\n") From 59739e4fc97ef3d62f40259ed94f41758126cc7f Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Tue, 23 Apr 2024 18:24:29 -0700 Subject: [PATCH 20/27] Fix lirary_versions key name mismatch --- cmake/autocoder/scripts/fpp_to_dict_wrapper.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py index 98c4f8e30c..987442bf7a 100755 --- a/cmake/autocoder/scripts/fpp_to_dict_wrapper.py +++ b/cmake/autocoder/scripts/fpp_to_dict_wrapper.py @@ -50,12 +50,12 @@ def main(): # Parses library versions into a string to input to fpp-to-dict libs_str = ",".join( - f"{lib}@{version}" for lib, version in versions.get("libraries", {}).items() + f"{lib}@{version}" + for lib, version in versions.get("library_versions", {}).items() ) - if ( - versions.get("framework_version", None) is None - or versions.get("project_version", None) is None - ): + framework_version = versions.get("framework_version") + project_version = versions.get("project_version") + if framework_version is None or project_version is None: raise ValueError( f"{args.jsonVersionFile} is missing 'framework_version' or 'project_version'" ) @@ -65,9 +65,9 @@ def main(): "--directory", args.cmake_bin_dir, "--projectVersion", - versions.get("project_version"), + project_version, "--frameworkVersion", - versions.get("framework_version"), + framework_version, *(["--libraryVersions", libs_str] if libs_str else []), # "" unpacks nothing "--imports", args.i, From 98016fc3aa2895dc726abb2a6b4ae36547f8a994 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Tue, 23 Apr 2024 18:24:42 -0700 Subject: [PATCH 21/27] Add more tests --- cmake/test/src/test_feature.py | 18 ++++++++++++++++++ cmake/test/src/test_ref_shared.py | 20 ++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cmake/test/src/test_feature.py b/cmake/test/src/test_feature.py index ed6610aad2..6095c5f991 100644 --- a/cmake/test/src/test_feature.py +++ b/cmake/test/src/test_feature.py @@ -5,6 +5,7 @@ # #### import platform +import json import settings @@ -28,6 +29,7 @@ "test", "TestDeployment_test", "TestLibrary_TestComponent_test", + "version" ], ) @@ -84,6 +86,22 @@ def test_feature_targets(FEATURE_BUILD): assert output_path.exists(), f"Failed to locate {output_file} in build output" +def test_feature_version_info(FEATURE_BUILD): + """Build and assert version files validity""" + cmake.assert_process_success(FEATURE_BUILD) + version_hpp = FEATURE_BUILD["build"] / "versions" / "version.hpp" + version_json = FEATURE_BUILD["build"] / "versions" / "version.json" + assert version_hpp.exists(), "Failed to locate version.hpp in build output" + assert version_json.exists(), "Failed to locate version.json in build output" + versions_dict = json.loads(version_json.read_text()) + for key in ["framework_version", "project_version", "library_versions"]: + assert key in versions_dict, f"Failed to locate key: {key} in version.json" + assert "test-fprime-library" in versions_dict["library_versions"], "Library version missing" + assert "test-fprime-library2" in versions_dict["library_versions"], "Library version missing" + assert versions_dict["library_versions"]["test-fprime-library"] == versions_dict["framework_version"], "Library version mismatch" + assert versions_dict["library_versions"]["test-fprime-library2"] == versions_dict["framework_version"], "Library version mismatch" + + def test_feature_installation(FEATURE_BUILD): """Run reference and assert reference targets exit""" cmake.assert_process_success(FEATURE_BUILD) diff --git a/cmake/test/src/test_ref_shared.py b/cmake/test/src/test_ref_shared.py index 71d9c0f9a1..8c1bba6acc 100644 --- a/cmake/test/src/test_ref_shared.py +++ b/cmake/test/src/test_ref_shared.py @@ -81,18 +81,14 @@ def test_ref_dictionary_json(REF_BUILD): / "RefTopologyDictionary.json" ) assert output_path.exists(), "Failed to locate Ref JSON Dictionary in build output" - - -def test_ref_version_info(REF_BUILD): - """Build Ref and assert version files exist""" - cmake.assert_process_success(REF_BUILD) - version_hpp = REF_BUILD["build"] / "versions" / "version.hpp" - version_json = REF_BUILD["build"] / "versions" / "version.json" - assert version_hpp.exists(), "Failed to locate version.hpp in build output" - assert version_json.exists(), "Failed to locate version.json in build output" - versions_dict = json.loads(version_json.read_text()) - for key in ["framework_version", "project_version", "library_versions"]: - assert key in versions_dict, f"Failed to locate key: {key} in version.json" + dict_metadata = json.loads(output_path.read_text()).get("metadata") + assert ( + dict_metadata.get("projectVersion") is not None + ), "Project version missing in JSON Dictionary" + # For Ref, versions should match since it's the same Git repo + assert dict_metadata.get("frameworkVersion") == dict_metadata.get( + "projectVersion" + ), "Version mismatch in JSON Dictionary" def test_ref_module_info(REF_BUILD): From 936f97a77b8331a597906622fc9c92af696ed3e3 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Tue, 23 Apr 2024 18:34:31 -0700 Subject: [PATCH 22/27] Add __attribute__((unused)) to appease CI --- cmake/target/version/generate_version_info.py | 5 +++-- cmake/test/src/test_feature.py | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmake/target/version/generate_version_info.py b/cmake/target/version/generate_version_info.py index 11bfe97611..212cb0bf8b 100755 --- a/cmake/target/version/generate_version_info.py +++ b/cmake/target/version/generate_version_info.py @@ -48,9 +48,10 @@ def create_version_file_hpp(output_dir, framework_version, project_version): fid.write(f'static const char* FRAMEWORK_VERSION = "{framework_version}";\n') fid.write(f'static const char* PROJECT_VERSION = "{project_version}";\n') lib_versions = get_library_versions() - fid.write("static const char* LIBRARY_VERSIONS[] = {") + # TODO: LIBRARY_VERSIONS is unused for now - remove the unused attribute when used in Version component + fid.write("static const char* LIBRARY_VERSIONS[] __attribute__((unused)) = {") if len(lib_versions) == 0: - fid.write(" \"\" };\n") # Empty string when no libraries are present + fid.write(' "" };\n') # Empty string when no libraries are present else: fid.write("\n") for lib_name, version in lib_versions.items(): diff --git a/cmake/test/src/test_feature.py b/cmake/test/src/test_feature.py index 6095c5f991..1ff6fbc575 100644 --- a/cmake/test/src/test_feature.py +++ b/cmake/test/src/test_feature.py @@ -29,7 +29,7 @@ "test", "TestDeployment_test", "TestLibrary_TestComponent_test", - "version" + "version", ], ) @@ -96,10 +96,20 @@ def test_feature_version_info(FEATURE_BUILD): versions_dict = json.loads(version_json.read_text()) for key in ["framework_version", "project_version", "library_versions"]: assert key in versions_dict, f"Failed to locate key: {key} in version.json" - assert "test-fprime-library" in versions_dict["library_versions"], "Library version missing" - assert "test-fprime-library2" in versions_dict["library_versions"], "Library version missing" - assert versions_dict["library_versions"]["test-fprime-library"] == versions_dict["framework_version"], "Library version mismatch" - assert versions_dict["library_versions"]["test-fprime-library2"] == versions_dict["framework_version"], "Library version mismatch" + assert ( + "test-fprime-library" in versions_dict["library_versions"] + ), "Library version missing " + assert ( + "test-fprime-library2" in versions_dict["library_versions"] + ), "Library version missing" + assert ( + versions_dict["library_versions"]["test-fprime-library"] + == versions_dict["framework_version"] + ), "Library version mismatch" + assert ( + versions_dict["library_versions"]["test-fprime-library2"] + == versions_dict["framework_version"] + ), "Library version mismatch" def test_feature_installation(FEATURE_BUILD): From b45902e761d3135191ca6640f00ddffa866862b1 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 24 Apr 2024 11:10:25 -0700 Subject: [PATCH 23/27] Use LIBRARY_VERSIONS with TODO in SystemResources.cpp --- Svc/SystemResources/SystemResources.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Svc/SystemResources/SystemResources.cpp b/Svc/SystemResources/SystemResources.cpp index 8f972a3f7f..59ba08c86c 100644 --- a/Svc/SystemResources/SystemResources.cpp +++ b/Svc/SystemResources/SystemResources.cpp @@ -157,5 +157,9 @@ void SystemResources::Version() { version_string= PROJECT_VERSION; this->tlmWrite_PROJECT_VERSION(version_string); + + if (LIBRARY_VERSIONS[0] != nullptr) { + // TODO: telemeter library versions down + } } } // end namespace Svc From 24c2a4fd5b25c3224e56f78727d3a89645f3cd5a Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 24 Apr 2024 11:10:42 -0700 Subject: [PATCH 24/27] Use nullptr instead of "" when no library present --- cmake/target/version/generate_version_info.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmake/target/version/generate_version_info.py b/cmake/target/version/generate_version_info.py index 212cb0bf8b..07d18c3e4c 100755 --- a/cmake/target/version/generate_version_info.py +++ b/cmake/target/version/generate_version_info.py @@ -48,16 +48,13 @@ def create_version_file_hpp(output_dir, framework_version, project_version): fid.write(f'static const char* FRAMEWORK_VERSION = "{framework_version}";\n') fid.write(f'static const char* PROJECT_VERSION = "{project_version}";\n') lib_versions = get_library_versions() - # TODO: LIBRARY_VERSIONS is unused for now - remove the unused attribute when used in Version component - fid.write("static const char* LIBRARY_VERSIONS[] __attribute__((unused)) = {") + fid.write("static const char* LIBRARY_VERSIONS[] = {\n") if len(lib_versions) == 0: - fid.write(' "" };\n') # Empty string when no libraries are present + fid.write(" nullptr\n") # nullptr when no libraries are present else: - fid.write("\n") for lib_name, version in lib_versions.items(): fid.write(f' "{lib_name}@{version}",\n') - fid.write("};\n") - fid.write("\n") + fid.write("};\n") fid.write("#endif\n") fid.write("\n") From e67a59b1992927b5971d06cc407e077c40e03a67 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Wed, 24 Apr 2024 11:21:14 -0700 Subject: [PATCH 25/27] Use LIBRARY_VERSIONS in SystemResourcesTester --- Svc/SystemResources/test/ut/SystemResourcesTester.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp index 05d5ee8e08..a9f839174f 100644 --- a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp +++ b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp @@ -116,6 +116,9 @@ void SystemResourcesTester ::test_tlm(bool enabled) { if (enabled) { ASSERT_TLM_FRAMEWORK_VERSION(0, FRAMEWORK_VERSION); ASSERT_TLM_PROJECT_VERSION(0, PROJECT_VERSION); + if (LIBRARY_VERSIONS[0] != nullptr) { + // TODO: test library versions tlm + } } ASSERT_TLM_SIZE((enabled) ? (count + 3) : 0); // CPU count channels + avg + 2 ver break; From ed7ffe37b947e7b102079a3828e686ded04b61bc Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Thu, 25 Apr 2024 09:08:59 -0700 Subject: [PATCH 26/27] Make script variables local --- cmake/autocoder/fpp.cmake | 2 +- cmake/target/version.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 8cde3454ab..424cd15d71 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -7,7 +7,7 @@ include_guard() include(utilities) include(autocoder/helpers) -set(FPRIME_FPP_TO_DICT_WRAPPER "${CMAKE_CURRENT_LIST_DIR}/scripts/fpp_to_dict_wrapper.py" CACHE PATH "Wrapper script to call fpp-to-dict with complex inputs") +set(FPRIME_FPP_TO_DICT_WRAPPER "${CMAKE_CURRENT_LIST_DIR}/scripts/fpp_to_dict_wrapper.py") autocoder_setup_for_multiple_sources() #### diff --git a/cmake/target/version.cmake b/cmake/target/version.cmake index 5498a31aee..8945e35d35 100644 --- a/cmake/target/version.cmake +++ b/cmake/target/version.cmake @@ -3,7 +3,7 @@ # # A basic versioning target which will produce the version files. #### -set(FPRIME_VERSION_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_info.py" CACHE PATH "Script used to generate version files") +set(FPRIME_VERSION_INFO_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/version/generate_version_info.py") function(version_add_global_target TARGET) set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/versions") @@ -22,7 +22,7 @@ function(version_add_global_target TARGET) "FPRIME_PROJECT_ROOT=${FPRIME_PROJECT_ROOT}" "FPRIME_FRAMEWORK_PATH=${FPRIME_FRAMEWORK_PATH}" "FPRIME_LIBRARY_LOCATIONS=${FPRIME_LIBRARY_LOCATIONS_CSV}" - "${FPRIME_VERSION_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" + "${FPRIME_VERSION_INFO_SCRIPT}" "${OUTPUT_DIR}" "${OPTIONAL_CHECK_ARG}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_HPP}.tmp" "${OUTPUT_HPP}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${OUTPUT_JSON}.tmp" "${OUTPUT_JSON}" WORKING_DIRECTORY "${FPRIME_PROJECT_ROOT}" From 5b15298fda59f911db5ada997586cd49f9040a2b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Thu, 25 Apr 2024 09:09:54 -0700 Subject: [PATCH 27/27] Switch to namespaced struct with constexpr --- Svc/SystemResources/SystemResources.cpp | 12 ++++------- .../test/ut/SystemResourcesTester.cpp | 11 ++++------ cmake/target/version/generate_version_info.py | 20 +++++++++++++------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Svc/SystemResources/SystemResources.cpp b/Svc/SystemResources/SystemResources.cpp index 59ba08c86c..1c2bd04299 100644 --- a/Svc/SystemResources/SystemResources.cpp +++ b/Svc/SystemResources/SystemResources.cpp @@ -89,10 +89,10 @@ void SystemResources ::ENABLE_cmdHandler(const FwOpcodeType opCode, } void SystemResources ::VERSION_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq) { - Fw::LogStringArg version_string(FRAMEWORK_VERSION); + Fw::LogStringArg version_string(Project::Version::FRAMEWORK_VERSION); this->log_ACTIVITY_LO_FRAMEWORK_VERSION(version_string); - version_string = PROJECT_VERSION; + version_string = Project::Version::PROJECT_VERSION; this->log_ACTIVITY_LO_PROJECT_VERSION(version_string); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } @@ -152,14 +152,10 @@ void SystemResources::PhysMem() { } void SystemResources::Version() { - Fw::TlmString version_string(FRAMEWORK_VERSION); + Fw::TlmString version_string(Project::Version::FRAMEWORK_VERSION); this->tlmWrite_FRAMEWORK_VERSION(version_string); - version_string= PROJECT_VERSION; + version_string= Project::Version::PROJECT_VERSION; this->tlmWrite_PROJECT_VERSION(version_string); - - if (LIBRARY_VERSIONS[0] != nullptr) { - // TODO: telemeter library versions down - } } } // end namespace Svc diff --git a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp index a9f839174f..476a66d6a6 100644 --- a/Svc/SystemResources/test/ut/SystemResourcesTester.cpp +++ b/Svc/SystemResources/test/ut/SystemResourcesTester.cpp @@ -114,11 +114,8 @@ void SystemResourcesTester ::test_tlm(bool enabled) { ASSERT_TLM_FRAMEWORK_VERSION_SIZE((enabled) ? 1 : 0); ASSERT_TLM_PROJECT_VERSION_SIZE((enabled) ? 1 : 0); if (enabled) { - ASSERT_TLM_FRAMEWORK_VERSION(0, FRAMEWORK_VERSION); - ASSERT_TLM_PROJECT_VERSION(0, PROJECT_VERSION); - if (LIBRARY_VERSIONS[0] != nullptr) { - // TODO: test library versions tlm - } + ASSERT_TLM_FRAMEWORK_VERSION(0, Project::Version::FRAMEWORK_VERSION); + ASSERT_TLM_PROJECT_VERSION(0, Project::Version::PROJECT_VERSION); } ASSERT_TLM_SIZE((enabled) ? (count + 3) : 0); // CPU count channels + avg + 2 ver break; @@ -136,9 +133,9 @@ void SystemResourcesTester ::test_disable_enable() { void SystemResourcesTester ::test_version_evr() { this->sendCmd_VERSION(0, 0); ASSERT_EVENTS_FRAMEWORK_VERSION_SIZE(1); - ASSERT_EVENTS_FRAMEWORK_VERSION(0, FRAMEWORK_VERSION); + ASSERT_EVENTS_FRAMEWORK_VERSION(0, Project::Version::FRAMEWORK_VERSION); ASSERT_EVENTS_PROJECT_VERSION_SIZE(1); - ASSERT_EVENTS_PROJECT_VERSION(0, FRAMEWORK_VERSION); + ASSERT_EVENTS_PROJECT_VERSION(0, Project::Version::FRAMEWORK_VERSION); } // ---------------------------------------------------------------------- diff --git a/cmake/target/version/generate_version_info.py b/cmake/target/version/generate_version_info.py index 07d18c3e4c..b2d79033c8 100755 --- a/cmake/target/version/generate_version_info.py +++ b/cmake/target/version/generate_version_info.py @@ -45,18 +45,26 @@ def create_version_file_hpp(output_dir, framework_version, project_version): fid.write("#ifndef _VERSION_HPP_\n") fid.write("#define _VERSION_HPP_\n") fid.write("\n") - fid.write(f'static const char* FRAMEWORK_VERSION = "{framework_version}";\n') - fid.write(f'static const char* PROJECT_VERSION = "{project_version}";\n') + + fid.write("namespace Project {\n\n") + fid.write("struct Version {\n") + fid.write( + f' static constexpr const char* const FRAMEWORK_VERSION = "{framework_version}";\n' + ) + fid.write( + f' static constexpr const char* const PROJECT_VERSION = "{project_version}";\n' + ) lib_versions = get_library_versions() - fid.write("static const char* LIBRARY_VERSIONS[] = {\n") + fid.write(" static constexpr const char* const LIBRARY_VERSIONS[] = {\n") if len(lib_versions) == 0: fid.write(" nullptr\n") # nullptr when no libraries are present else: for lib_name, version in lib_versions.items(): - fid.write(f' "{lib_name}@{version}",\n') - fid.write("};\n") + fid.write(f' "{lib_name}@{version}",\n') + fid.write(" };\n") + fid.write("};\n\n") + fid.write("} // namespace Project\n") fid.write("#endif\n") - fid.write("\n") def create_version_file_json(