Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1604 #2625

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmake/autocoder/fpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
LeStarch marked this conversation as resolved.
Show resolved Hide resolved
string(REGEX REPLACE ";" "," FPRIME_BUILD_LOCATIONS_COMMA_SEP "${FPRIME_BUILD_LOCATIONS}")
string(REGEX REPLACE ";" "," FPP_IMPORTS_COMMA_SEP "${FPP_IMPORTS}")
set(IMPORTS)
Expand All @@ -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}
)
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion cmake/autocoder/packets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}"
)
Expand Down
13 changes: 12 additions & 1 deletion cmake/settings/ini-to-stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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)


Expand Down Expand Up @@ -58,14 +64,19 @@ 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
)
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:
Expand Down
40 changes: 40 additions & 0 deletions cmake/test/src/test_symlink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
####
# 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)
25 changes: 25 additions & 0 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
LeStarch marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Loading