From 3c8853183058f2881c8420a11ee867f7dea102d2 Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Tue, 26 Mar 2024 14:11:37 -0700 Subject: [PATCH 1/6] Make ini-to-stdio return un-resolved paths. Fixes: #2450 --- cmake/settings/ini-to-stdio.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmake/settings/ini-to-stdio.py b/cmake/settings/ini-to-stdio.py index c1bb526f0a..85204cd3ba 100644 --- a/cmake/settings/ini-to-stdio.py +++ b/cmake/settings/ini-to-stdio.py @@ -3,6 +3,7 @@ Loads fprime style ini files into a format CMake can process. """ import argparse +import os.path import sys from functools import partial @@ -12,6 +13,9 @@ from fprime.fbuild.settings import IniSettings +REMAPPING = {} + + def print_setting(setting: str, value: str = "", ending: str = ";"): """Print a setting for CMake @@ -23,6 +27,8 @@ def print_setting(setting: str, value: str = "", ending: str = ";"): ending: ending of the print line """ value = str(value).replace(";", "\\;") + for initial, final in REMAPPING.items(): + value = value.replace(initial, final) print(f"{setting}={value}", end=ending) @@ -58,7 +64,6 @@ def main(): default=Path("native"), help="Path to toolchain file", ) - args_ns = parser.parse_args() loaded_settings = IniSettings.load( args_ns.settings, str(args_ns.toolchain.stem), False @@ -66,6 +71,12 @@ def main(): loaded_settings_ut = IniSettings.load( args_ns.settings, str(args_ns.toolchain.stem), True ) + ini_path = str(args_ns.settings) + ini_real_path = str(args_ns.settings.resolve()) + common_suffix = os.path.commonprefix([ini_path[::-1], ini_real_path[::-1]])[::-1] + REMAPPING[ini_real_path[:-1*len(common_suffix)]] = ini_path[:-1*len(common_suffix)] + + for setting, handler in CMAKE_NEEDED_SETTINGS.items(): try: From 45a9e0acb7ec73a42d6eb68a32ea14efbfab41af Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Tue, 26 Mar 2024 14:50:03 -0700 Subject: [PATCH 2/6] Fixed packet autocoder includes. Fixs #2453 --- cmake/autocoder/packets.cmake | 5 ++++- cmake/utilities.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmake/autocoder/packets.cmake b/cmake/autocoder/packets.cmake index f2d5157b86..d49e86877c 100644 --- a/cmake/autocoder/packets.cmake +++ b/cmake/autocoder/packets.cmake @@ -42,6 +42,9 @@ function(packets_setup_autocode AC_INPUT_FILE) determine_topology_files("${AC_INPUT_FILE}") get_filename_component(AC_INPUT_FILE_NO_PATH "${AC_INPUT_FILE}" NAME) + + set(CMAKE_BINARY_DIR_RESOLVED "${CMAKE_BINARY_DIR}") + resolve_path_variables(FPRIME_BUILD_LOCATIONS PYTHON_AUTOCODER_DIR CMAKE_BINARY_DIR_RESOLVED AC_INPUT_FILE) string(REPLACE ";" ":" FPRIME_BUILD_LOCATIONS_SEP "${FPRIME_BUILD_LOCATIONS}") string(REPLACE "Packets.xml" "PacketsAc.cpp" CPP_FILE "${AC_INPUT_FILE_NO_PATH}") string(REPLACE "Packets.xml" "PacketsAc.hpp" HPP_FILE "${AC_INPUT_FILE_NO_PATH}") @@ -54,7 +57,7 @@ function(packets_setup_autocode AC_INPUT_FILE) OUTPUT ${GENERATED_FILES} COMMAND PYTHONPATH=${PYTHON_AUTOCODER_DIR}/src:${PYTHON_AUTOCODER_DIR}/utils - BUILD_ROOT=${FPRIME_BUILD_LOCATIONS_SEP}:${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/F-Prime + BUILD_ROOT=${FPRIME_BUILD_LOCATIONS_SEP}:${CMAKE_BINARY_DIR_RESOLVED}:${CMAKE_BINARY_DIR_RESOLVED}/F-Prime "${PYTHON}" "${PACKETS_AUTOCODER_SCRIPT}" "${AC_INPUT_FILE}" DEPENDS "${AC_INPUT_FILE}" "${FULL_TOPOLOGY_FILE}" ) diff --git a/cmake/utilities.cmake b/cmake/utilities.cmake index 061a4b237b..0afc2a8152 100644 --- a/cmake/utilities.cmake +++ b/cmake/utilities.cmake @@ -644,3 +644,28 @@ function(get_fprime_library_option_string OUTPUT_VAR LIBRARY_NAME) string(REGEX REPLACE "[^A-Z0-9_]" "_" LIBRARY_OPTION "${LIBRARY_NAME_UPPER}") set("${OUTPUT_VAR}" "${LIBRARY_OPTION}" PARENT_SCOPE) endfunction(get_fprime_library_option_string) + +#### +# Function `resolve_path_variables`: +# +# Resolve paths updating parent scope. ARGN should contain a list of variables to update. +# +# ARGN: list of variables to update +#### +function(resolve_path_variables) + # Loop through all variables + foreach (INPUT_NAME IN LISTS ARGN) + set(NEW_LIST) + # Loop through each item in INPUT_NAME + foreach(UNRESOLVED IN LISTS ${INPUT_NAME}) + # If it is a path, resolve it + if (EXISTS ${UNRESOLVED}) + get_filename_component(RESOLVED "${UNRESOLVED}" REALPATH) + else() + set(RESOLVED "${UNRESOLVED}") + endif() + list(APPEND NEW_LIST "${RESOLVED}") + endforeach() + set("${INPUT_NAME}" "${NEW_LIST}" PARENT_SCOPE) + endforeach() +endfunction(resolve_path_variables) \ No newline at end of file From 77f488804f26c851016b83525c1076776045e9ef Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Tue, 26 Mar 2024 15:37:31 -0700 Subject: [PATCH 3/6] Convert FPP inputs to canonical path. Fixes: #2455 --- cmake/autocoder/fpp.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 3fa243b38e..8cfaa020fb 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -194,6 +194,10 @@ function(fpp_setup_autocode AC_INPUT_FILES) message(FATAL_ERROR "fpp tools not found, please install them onto your system path") endif() fpp_info("${AC_INPUT_FILES}") + set(CMAKE_BINARY_DIR_RESOLVED "${CMAKE_BINARY_DIR}") + set(CMAKE_CURRENT_BINARY_DIR_RESOLVED "${CMAKE_CURRENT_BINARY_DIR}") + resolve_path_variables( + AC_INPUT_FILES FPRIME_BUILD_LOCATIONS FPP_IMPORTS CMAKE_BINARY_DIR_RESOLVED CMAKE_BINARY_DIR_RESOLVED) string(REGEX REPLACE ";" "," FPRIME_BUILD_LOCATIONS_COMMA_SEP "${FPRIME_BUILD_LOCATIONS}") string(REGEX REPLACE ";" "," FPP_IMPORTS_COMMA_SEP "${FPP_IMPORTS}") set(IMPORTS) @@ -216,7 +220,7 @@ function(fpp_setup_autocode AC_INPUT_FILES) if (GENERATED_AI) add_custom_command( OUTPUT ${GENERATED_AI} - COMMAND ${FPP_TO_XML} "-d" "${CMAKE_CURRENT_BINARY_DIR}" ${IMPORTS} ${AC_INPUT_FILES} + COMMAND ${FPP_TO_XML} "-d" "${CMAKE_CURRENT_BINARY_DIR_RESOLVED}" ${IMPORTS} ${AC_INPUT_FILES} "-p" "${FPRIME_BUILD_LOCATIONS_COMMA_SEP}" DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ) @@ -225,8 +229,8 @@ function(fpp_setup_autocode AC_INPUT_FILES) if (GENERATED_CPP) add_custom_command( OUTPUT ${GENERATED_CPP} - COMMAND ${FPP_TO_CPP} "-d" "${CMAKE_CURRENT_BINARY_DIR}" ${IMPORTS} ${AC_INPUT_FILES} - "-p" "${FPRIME_BUILD_LOCATIONS_COMMA_SEP},${CMAKE_BINARY_DIR}" + COMMAND ${FPP_TO_CPP} "-d" "${CMAKE_CURRENT_BINARY_DIR_RESOLVED}" ${IMPORTS} ${AC_INPUT_FILES} + "-p" "${FPRIME_BUILD_LOCATIONS_COMMA_SEP},${CMAKE_BINARY_DIR_RESOLVED}" DEPENDS ${FILE_DEPENDENCIES} ${MODULE_DEPENDENCIES} ) endif() From 601f004e3c56fb2853b23bcb5efeb6468746eb39 Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Tue, 26 Mar 2024 18:38:12 -0700 Subject: [PATCH 4/6] Adding in test for CMake under symlinks. Fixes: #2624 --- cmake/test/src/test_symlink.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 cmake/test/src/test_symlink.py diff --git a/cmake/test/src/test_symlink.py b/cmake/test/src/test_symlink.py new file mode 100644 index 0000000000..84109d3d72 --- /dev/null +++ b/cmake/test/src/test_symlink.py @@ -0,0 +1,39 @@ +#### +# test_symlink.py: +# +# Test that a build from a directory that contains a symlink works correctly. +# +#### +import os +import shutil +import tempfile + +import pytest +import settings + +import cmake +from pathlib import Path + + +SYMLINK_PATH = Path(tempfile.mkdtemp()) / "fprime-link" +os.symlink(settings.REF_APP_PATH.parent, SYMLINK_PATH) + + +_ = cmake.get_build( + "SYMLINKED_UT_BUILD", + SYMLINK_PATH / "Ref", + cmake_arguments={"BUILD_TESTING": "ON"}, + make_targets=["Ref", "ut_exe"], + install_directory=tempfile.mkdtemp(), +) + + +@pytest.fixture(scope="session") +def symlink_maker(): + """ Fixture for symlinked builds """ + yield None + shutil.rmtree(SYMLINK_PATH, ignore_errors=True) + +def test_unittest_run(SYMLINKED_UT_BUILD, symlink_maker): + """Basic run test for ref""" + cmake.assert_process_success(SYMLINKED_UT_BUILD, errors_ok=True) \ No newline at end of file From 5a6190cc2443d7797234689d234675ed2dce4d13 Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Tue, 26 Mar 2024 19:09:10 -0700 Subject: [PATCH 5/6] Formatting --- cmake/settings/ini-to-stdio.py | 6 +++--- cmake/test/src/test_symlink.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmake/settings/ini-to-stdio.py b/cmake/settings/ini-to-stdio.py index 85204cd3ba..258bf5dbf8 100644 --- a/cmake/settings/ini-to-stdio.py +++ b/cmake/settings/ini-to-stdio.py @@ -74,9 +74,9 @@ def main(): ini_path = str(args_ns.settings) ini_real_path = str(args_ns.settings.resolve()) common_suffix = os.path.commonprefix([ini_path[::-1], ini_real_path[::-1]])[::-1] - REMAPPING[ini_real_path[:-1*len(common_suffix)]] = ini_path[:-1*len(common_suffix)] - - + REMAPPING[ini_real_path[: -1 * len(common_suffix)]] = ini_path[ + : -1 * len(common_suffix) + ] for setting, handler in CMAKE_NEEDED_SETTINGS.items(): try: diff --git a/cmake/test/src/test_symlink.py b/cmake/test/src/test_symlink.py index 84109d3d72..fad44c714d 100644 --- a/cmake/test/src/test_symlink.py +++ b/cmake/test/src/test_symlink.py @@ -30,10 +30,11 @@ @pytest.fixture(scope="session") def symlink_maker(): - """ Fixture for symlinked builds """ + """Fixture for symlinked builds""" yield None shutil.rmtree(SYMLINK_PATH, ignore_errors=True) + def test_unittest_run(SYMLINKED_UT_BUILD, symlink_maker): """Basic run test for ref""" - cmake.assert_process_success(SYMLINKED_UT_BUILD, errors_ok=True) \ No newline at end of file + cmake.assert_process_success(SYMLINKED_UT_BUILD, errors_ok=True) From 95bf4ef2bffc52f3503e0f638c163cca205168a2 Mon Sep 17 00:00:00 2001 From: Michael D Starch Date: Mon, 1 Apr 2024 10:28:47 -0700 Subject: [PATCH 6/6] Correcting review suggestions --- cmake/autocoder/fpp.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/autocoder/fpp.cmake b/cmake/autocoder/fpp.cmake index 8cfaa020fb..d3d8fcc096 100644 --- a/cmake/autocoder/fpp.cmake +++ b/cmake/autocoder/fpp.cmake @@ -197,7 +197,7 @@ function(fpp_setup_autocode AC_INPUT_FILES) set(CMAKE_BINARY_DIR_RESOLVED "${CMAKE_BINARY_DIR}") set(CMAKE_CURRENT_BINARY_DIR_RESOLVED "${CMAKE_CURRENT_BINARY_DIR}") resolve_path_variables( - AC_INPUT_FILES FPRIME_BUILD_LOCATIONS FPP_IMPORTS CMAKE_BINARY_DIR_RESOLVED CMAKE_BINARY_DIR_RESOLVED) + AC_INPUT_FILES FPRIME_BUILD_LOCATIONS FPP_IMPORTS CMAKE_BINARY_DIR_RESOLVED CMAKE_CURRENT_BINARY_DIR_RESOLVED) string(REGEX REPLACE ";" "," FPRIME_BUILD_LOCATIONS_COMMA_SEP "${FPRIME_BUILD_LOCATIONS}") string(REGEX REPLACE ";" "," FPP_IMPORTS_COMMA_SEP "${FPP_IMPORTS}") set(IMPORTS)