Skip to content

Commit

Permalink
Update/sloc cache (#2366)
Browse files Browse the repository at this point in the history
* Output sources.txt representing sources of each module - WIP

* Adding in module-ut-info.txt

* Formatting

* sp
  • Loading branch information
LeStarch authored Nov 15, 2023
1 parent 4277591 commit 20997fd
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ fileopen
FILESTUBS
fio
Firefox
FLDP
flist
FNDELAY
fns
Expand Down
15 changes: 6 additions & 9 deletions Ref/SignalGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.fpp"
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.cpp"


)
set(HEADER_FILES
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.hpp"
)

register_fprime_module()









### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/SignalGen.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SignalGenTester.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SignalGenTestMain.cpp"
)
set(UT_HEADER_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SignalGenTester.hpp"
)
set(UT_AUTO_HELPERS ON)
register_fprime_ut()
1 change: 1 addition & 0 deletions cmake/autocoder/ai_ut.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ function(ai_ut_setup_autocode AC_INPUT_FILE)
DEPENDS "${AC_INPUT_FILE}" "${CODEGEN_TARGET}"
)
set(AUTOCODER_GENERATED "${AUTOCODER_GENERATED}" PARENT_SCOPE)
set(AUTOCODER_INCLUDES "${FILE_DEPENDENCIES}" PARENT_SCOPE)
endfunction(ai_ut_setup_autocode)
1 change: 1 addition & 0 deletions cmake/autocoder/ai_xml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ function(ai_xml_setup_autocode AC_INPUT_FILE)
endif()
set(AUTOCODER_GENERATED "${GENERATED_FILES}" PARENT_SCOPE)
set(AUTOCODER_DEPENDENCIES "${MODULE_DEPENDENCIES}" PARENT_SCOPE)
set(AUTOCODER_INCLUDES "${FILE_DEPENDENCIES}" PARENT_SCOPE)
endfunction(ai_xml_setup_autocode)
24 changes: 20 additions & 4 deletions cmake/autocoder/autocoder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ function (run_ac_set SOURCES)
if (ARGN)
set(AC_LIST "${ARGN}")
endif()
init_variables(MODULE_DEPENDENCIES_LIST GENERATED_FILE_LIST CONSUMED_SOURCES_LIST)
init_variables(MODULE_DEPENDENCIES_LIST GENERATED_FILE_LIST CONSUMED_SOURCES_LIST FILE_DEPENDENCY_LIST)
foreach(AC_CMAKE IN LISTS AC_LIST)
init_variables(MODULE_DEPENDENCIES GENERATED_FILES CONSUMED_SOURCES)
run_ac("${AC_CMAKE}" "${SOURCES}" "${GENERATED_FILE_LIST}")
list(APPEND MODULE_DEPENDENCIES_LIST ${MODULE_DEPENDENCIES})
list(APPEND GENERATED_FILE_LIST ${GENERATED_FILES})
list(APPEND CONSUMED_SOURCES_LIST ${CONSUMED_SOURCES})
list(APPEND FILE_DEPENDENCY_LIST ${FILE_DEPENDENCIES})
endforeach()

list(REMOVE_DUPLICATES MODULE_DEPENDENCIES_LIST)
list(REMOVE_DUPLICATES GENERATED_FILE_LIST)
list(REMOVE_DUPLICATES CONSUMED_SOURCES_LIST)
list(REMOVE_DUPLICATES FILE_DEPENDENCY_LIST)

# Return variables
set(AC_DEPENDENCIES "${MODULE_DEPENDENCIES_LIST}" PARENT_SCOPE)
set(AC_GENERATED "${GENERATED_FILE_LIST}" PARENT_SCOPE)
set(AC_SOURCES "${CONSUMED_SOURCES_LIST}" PARENT_SCOPE)
set(AC_FILE_DEPENDENCIES "${FILE_DEPENDENCY_LIST}" PARENT_SCOPE)
endfunction()

####
Expand Down Expand Up @@ -84,18 +91,20 @@ function(run_ac AUTOCODER_CMAKE SOURCES GENERATED_SOURCES)
set(CONSUMED_SOURCES)
# Handles individual/multiple source handling
if (HANDLES_INDIVIDUAL_SOURCES)
init_variables(MODULE_DEPENDENCIES_LIST GENERATED_FILES_LIST)
init_variables(MODULE_DEPENDENCIES_LIST GENERATED_FILES_LIST FILE_DEPENDENCY_LIST)
foreach(SOURCE IN LISTS AC_INPUT_SOURCES)
__ac_process_sources("${SOURCE}")
list(APPEND MODULE_DEPENDENCIES_LIST ${MODULE_DEPENDENCIES})
list(APPEND GENERATED_FILES_LIST ${GENERATED_FILES})
list(APPEND FILE_DEPENDENCY_LIST ${FILE_DEPENDENCIES})
# Check if this would have generated something, if not don't mark the file as used
if (GENERATED_FILES)
list(APPEND CONSUMED_SOURCES "${SOURCE}")
endif()
endforeach()
set(MODULE_DEPENDENCIES "${MODULE_DEPENDENCIES_LIST}")
set(GENERATED_FILES "${GENERATED_FILES_LIST}")
set(FILE_DEPENDENCIES "${FILE_DEPENDENCY_LIST}")
else()
__ac_process_sources("${AC_INPUT_SOURCES}")
set(CONSUMED_SOURCES "${AC_INPUT_SOURCES}")
Expand All @@ -109,11 +118,13 @@ function(run_ac AUTOCODER_CMAKE SOURCES GENERATED_SOURCES)
get_property(DEPS DIRECTORY PROPERTY "${SRCS_HASH}_DEPENDENCIES")
get_property(GENS DIRECTORY PROPERTY "${SRCS_HASH}_GENERATED")
get_property(CONS DIRECTORY PROPERTY "${SRCS_HASH}_CONSUMED")
get_property(FLDP DIRECTORY PROPERTY "${SRCS_HASH}_FILE_DEPENDENCIES")

# Return variables
set(MODULE_DEPENDENCIES "${DEPS}" PARENT_SCOPE)
set(GENERATED_FILES "${GENS}" PARENT_SCOPE)
set(CONSUMED_SOURCES "${CONS}" PARENT_SCOPE)
set(FILE_DEPENDENCIES "${FLDP}" PARENT_SCOPE)
endfunction(run_ac)

####
Expand Down Expand Up @@ -212,21 +223,26 @@ function(__ac_process_sources SOURCES)
message(FATAL_ERROR "AUTOCODER_INPUTS set to ${AUTOCODER_INPUTS} before setup autocoder call.")
elseif(DEFINED AUTOCODER_DEPENDENCIES)
message(FATAL_ERROR "AUTOCODER_DEPENDENCIES set to ${AUTOCODER_DEPENDENCIES} before setup autocoder call.")
elseif(DEFINED AUTOCODER_INCLUDES)
message(FATAL_ERROR "AUTOCODER_INCLUDES set to ${AUTOCODER_INCLUDES} before setup autocoder call.")
endif()

# Run the generation setup when not requesting "info only"
cmake_language(CALL "${AUTOCODER_NAME}_setup_autocode" "${SOURCES}")
set(FILE_DEPENDENCIES ${AUTOCODER_INPUTS})
list(APPEND FILE_DEPENDENCIES ${AUTOCODER_INCLUDES})

if (NOT DEFINED AUTOCODER_GENERATED)
message(FATAL_ERROR "Autocoder ${AUTOCODER_NAME} did not set AUTOCODER_GENERATED to files to be generated")
elseif(DEFINED AUTOCODER_SCRIPT AND NOT DEFINED AUTOCODER_INPUTS)
message(FATAL_ERROR "Autocoder ${AUTOCODER_NAME} did not set both AUTOCODER_INPUTS when using AUTOCODER_SCRIPT")
elseif(DEFINED AUTOCODER_SCRIPT)
add_custom_command(OUTPUT ${AUTOCODER_GENERATED} COMMAND ${AUTOCODER_SCRIPT} ${AUTOCODER_INPUTS} DEPENDS ${AUTOCODER_INPUTS} ${AUTOCODER_DEPENDENCIES})
add_custom_command(OUTPUT ${AUTOCODER_GENERATED} COMMAND ${AUTOCODER_SCRIPT} ${AUTOCODER_INPUTS} DEPENDS ${FILE_DEPENDENCIES} ${AUTOCODER_DEPENDENCIES})
endif()


set(MODULE_DEPENDENCIES "${AUTOCODER_DEPENDENCIES}" PARENT_SCOPE)
set(GENERATED_FILES "${AUTOCODER_GENERATED}" PARENT_SCOPE)
set(FILE_DEPENDENCIES "${AUTOCODER_INPUTS}" PARENT_SCOPE)
set(FILE_DEPENDENCIES "${FILE_DEPENDENCIES}" PARENT_SCOPE)
endfunction()

1 change: 1 addition & 0 deletions cmake/autocoder/fpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function(fpp_setup_autocode AC_INPUT_FILES)
set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP})
set(AUTOCODER_GENERATED "${AUTOCODER_GENERATED}" PARENT_SCOPE)
set(AUTOCODER_DEPENDENCIES "${MODULE_DEPENDENCIES}" PARENT_SCOPE)
set(AUTOCODER_INCLUDES "${FILE_DEPENDENCIES}" PARENT_SCOPE)
endfunction(fpp_setup_autocode)

####
Expand Down
1 change: 1 addition & 0 deletions cmake/autocoder/fpp_ut.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ function(fpp_ut_setup_autocode AC_INPUT_FILES)
set(AUTOCODER_GENERATED ${GENERATED_AI} ${GENERATED_CPP})
set(AUTOCODER_GENERATED "${AUTOCODER_GENERATED}" PARENT_SCOPE)
set(AUTOCODER_DEPENDENCIES "${MODULE_DEPENDENCIES}" PARENT_SCOPE)
set(AUTOCODER_INCLUDES "${FILE_DEPENDENCIES}" PARENT_SCOPE)
endfunction(fpp_ut_setup_autocode)

23 changes: 12 additions & 11 deletions cmake/target/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ endfunction(build_add_global_target)
# - EXCLUDED_SOURCES: sources already "consumed", that is, processed by an autocoder
# - DEPENDENCIES: dependencies of this module. Also link flags and libraries.
####
function(build_setup_build_module MODULE SOURCES GENERATED EXCLUDED_SOURCES DEPENDENCIES)
# Add generated sources
foreach(SOURCE IN LISTS SOURCES GENERATED)
if (NOT SOURCE IN_LIST EXCLUDED_SOURCES)
target_sources("${MODULE}" PRIVATE "${SOURCE}")
endif()
endforeach()
function(build_setup_build_module MODULE SOURCES GENERATED DEPENDENCIES)
target_sources("${MODULE}" PRIVATE ${SOURCES} ${GENERATED})

# Set those files as generated to prevent build errors
foreach(SOURCE IN LISTS GENERATED)
Expand Down Expand Up @@ -105,11 +100,11 @@ endfunction()
# of arguments. FULL_DEPENDENCY_LIST is unused (these are already known to CMake).
####
function(build_add_deployment_target MODULE TARGET SOURCES DIRECT_DEPENDENCIES FULL_DEPENDENCY_LIST)
build_add_module_target("${MODULE}" "${TARGET}" "${SOURCES}" "${DEPENDENCIES}")
build_add_module_target("${MODULE}" "${TARGET}" "${SOURCES}" "${FULL_DEPENDENCY_LIST}")
endfunction()

####
# Build function `add_module_target`:
# Function `build_add_module_target`:
#
# Adds a module-by-module target for building fprime.
#
Expand All @@ -123,8 +118,14 @@ function(build_add_module_target MODULE TARGET SOURCES DEPENDENCIES)
message(STATUS "Adding ${MODULE_TYPE}: ${MODULE}")
get_property(CUSTOM_AUTOCODERS GLOBAL PROPERTY FPRIME_AUTOCODER_TARGET_LIST)
run_ac_set("${SOURCES}" ${CUSTOM_AUTOCODERS})
resolve_dependencies(RESOLVED ${DEPENDENCIES} ${AC_DEPENDENCIES} )
build_setup_build_module("${MODULE}" "${SOURCES}" "${AC_GENERATED}" "${AC_SOURCES}" "${RESOLVED}")
resolve_dependencies(RESOLVED ${DEPENDENCIES} ${AC_DEPENDENCIES})

# Create lists of hand-coded and generated sources not "consumed" by an autocoder
filter_lists("${AC_SOURCES}" SOURCES AC_GENERATED)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module-info.txt"
"${HEADER_FILES}\n${SOURCES_FILTERED}\n${AC_GENERATED}\n${AC_FILE_DEPENDENCIES}\n${DEPENDENCIES}\n"
)
build_setup_build_module("${MODULE}" "${SOURCES_FILTERED}" "${AC_GENERATED_FILTERED}" "${RESOLVED}")

if (CMAKE_DEBUG_OUTPUT)
introspect("${MODULE}")
Expand Down
8 changes: 7 additions & 1 deletion cmake/target/ut.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ function(ut_add_module_target MODULE_NAME TARGET_NAME SOURCE_FILES DEPENDENCIES)
)
run_ac_set("${SOURCE_FILES}" autocoder/fpp autocoder/fpp_ut)
resolve_dependencies(RESOLVED gtest_main ${DEPENDENCIES} ${AC_DEPENDENCIES})
build_setup_build_module("${UT_EXE_NAME}" "${SOURCE_FILES}" "${AC_GENERATED}" "${AC_SOURCES}" "${RESOLVED}")

# Create lists of hand-coded and generated sources not "consumed" by an autocoder
filter_lists("${AC_SOURCES}" SOURCE_FILES AC_GENERATED)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/module-ut-info.txt"
"${UT_HEADER_FILES}\n${SOURCE_FILES_FILTERED}\n${AC_GENERATED}\n${AC_FILE_DEPENDENCIES}\n${DEPENDENCIES}"
)
build_setup_build_module("${UT_EXE_NAME}" "${SOURCE_FILES_FILTERED}" "${AC_GENERATED_FILTERED}" "${RESOLVED}")

ut_setup_unit_test_include_directories("${UT_EXE_NAME}" "${SOURCE_FILES}")
add_test(NAME ${UT_EXE_NAME} COMMAND ${UT_EXE_NAME})
Expand Down
51 changes: 51 additions & 0 deletions cmake/test/src/test_ref_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import cmake

from pathlib import Path

_ = cmake.get_build(
"REF_BUILD",
settings.REF_APP_PATH,
Expand Down Expand Up @@ -65,3 +67,52 @@ def test_ref_dictionary(REF_BUILD):
/ "RefTopologyAppDictionary.xml"
)
assert output_path.exists(), "Failed to locate Ref 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)
txt_path = REF_BUILD["build"] / "Ref" / "SignalGen" / "module-info.txt"
assert txt_path.exists(), "Failed to locate module-info.txt under SignalGen"

with open(txt_path, "r") as file_path:
lines = file_path.readlines()
assert len(lines) == 5, "Module info not correct number of lines"
headers, sources, generated, ac_sources, dependencies = [
line.strip().split(";") for line in lines
]
assert ["SignalGen.hpp"] == [
Path(header).name for header in headers
], "Did not find expected headers"
assert ["SignalGen.cpp"] == [
Path(source).name for source in sources
], "Did not find expected sources"
expected_ac = ["SignalGen.fpp", "Commands.fppi", "Events.fppi", "Telemetry.fppi"]
actual_ac = [Path(source).name for source in ac_sources]
assert sorted(expected_ac) == sorted(
actual_ac
), "Did not find expected autocoder sources"
expected_gen = [
"SignalGenComponentAi.xml",
"SignalInfoSerializableAi.xml",
"SignalPairSerializableAi.xml",
"SignalPairSetArrayAi.xml",
"SignalSetArrayAi.xml",
"SignalTypeEnumAi.xml",
"SignalGenComponentAc.cpp",
"SignalGenComponentAc.hpp",
"SignalInfoSerializableAc.cpp",
"SignalInfoSerializableAc.hpp",
"SignalPairSerializableAc.cpp",
"SignalPairSerializableAc.hpp",
"SignalPairSetArrayAc.cpp",
"SignalPairSetArrayAc.hpp",
"SignalSetArrayAc.cpp",
"SignalSetArrayAc.hpp",
"SignalTypeEnumAc.cpp",
"SignalTypeEnumAc.hpp",
]
actual_gen = [Path(source).name for source in generated]
assert sorted(expected_gen) == sorted(
actual_gen
), "Did not find expected autocoder generated sources"
56 changes: 56 additions & 0 deletions cmake/test/src/test_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import settings

import cmake
from pathlib import Path

_ = cmake.get_build(
"UT_BUILD",
Expand Down Expand Up @@ -110,3 +111,58 @@ def test_unittest_dictionary(UT_BUILD):
/ "RefTopologyAppDictionary.xml"
)
assert output_path.exists(), "Failed to locate Ref in build output"


def test_unittest_module_ut_info(UT_BUILD):
"""Run reference and assert module-ut-info.txt was created"""
cmake.assert_process_success(UT_BUILD, errors_ok=True)
txt_path = UT_BUILD["build"] / "Ref" / "SignalGen" / "module-ut-info.txt"
assert txt_path.exists(), "Failed to locate module-info.txt under SignalGen"

with open(txt_path, "r") as file_path:
lines = file_path.readlines()
assert len(lines) == 5, "Module info not correct number of lines"
headers, sources, generated, ac_sources, dependencies = [
line.strip().split(";") for line in lines
]
assert ["SignalGenTester.hpp"] == [
Path(header).name for header in headers
], "Did not find expected headers"
assert sorted(["SignalGenTester.cpp", "SignalGenTestMain.cpp"]) == sorted(
[Path(source).name for source in sources]
), "Did not find expected sources"
expected_ac = ["SignalGen.fpp", "Commands.fppi", "Events.fppi", "Telemetry.fppi"]
actual_ac = [Path(source).name for source in ac_sources]
assert sorted(expected_ac) == sorted(
actual_ac
), "Did not find expected autocoder sources"
expected_gen = [
"SignalGenComponentAi.xml",
"SignalInfoSerializableAi.xml",
"SignalPairSerializableAi.xml",
"SignalPairSetArrayAi.xml",
"SignalSetArrayAi.xml",
"SignalTypeEnumAi.xml",
"SignalGenComponentAc.cpp",
"SignalGenComponentAc.hpp",
"SignalInfoSerializableAc.cpp",
"SignalInfoSerializableAc.hpp",
"SignalPairSerializableAc.cpp",
"SignalPairSerializableAc.hpp",
"SignalPairSetArrayAc.cpp",
"SignalPairSetArrayAc.hpp",
"SignalSetArrayAc.cpp",
"SignalSetArrayAc.hpp",
"SignalTypeEnumAc.cpp",
"SignalTypeEnumAc.hpp",
"SignalGenGTestBase.cpp",
"SignalGenGTestBase.hpp",
"SignalGenTesterBase.cpp",
"SignalGenTesterBase.hpp",
"SignalGenTesterHelpers.cpp",
]
actual_gen = [Path(source).name for source in generated]
assert sorted(expected_gen) == sorted(
actual_gen
), "Did not find expected autocoder generated sources"
assert dependencies == ["Ref_SignalGen"], "Did not find expected dependencies"
20 changes: 20 additions & 0 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,23 @@ function(append_list_property NEW_ITEM)
list(REMOVE_DUPLICATES LOCAL_COPY)
set_property(${ARGN} "${LOCAL_COPY}")
endfunction()

####
# Function `filter_lists`:
#
# Filters lists set in ARGN to to ensure that they are not in the exclude list. Sets the <LIST>_FILTERED variable in
# PARENT_SCOPE with the results
# **EXCLUDE_LIST**: list of items to filter-out of ARGN lists
# **ARGN:** list of list names in parent scope to filter
####
function (filter_lists EXCLUDE_LIST)
foreach(SOURCE_LIST IN LISTS ARGN)
set(${SOURCE_LIST}_FILTERED "")
foreach(SOURCE IN LISTS ${SOURCE_LIST})
if (NOT SOURCE IN_LIST EXCLUDE_LIST)
list(APPEND ${SOURCE_LIST}_FILTERED "${SOURCE}")
endif()
endforeach()
set(${SOURCE_LIST}_FILTERED "${${SOURCE_LIST}_FILTERED}" PARENT_SCOPE)
endforeach()
endfunction(filter_lists)

0 comments on commit 20997fd

Please sign in to comment.