Skip to content
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
register_fprime_module(
TestChainedAutocoderModule
AUTOCODER_INPUTS
"${CMAKE_CURRENT_LIST_DIR}/test1.test-target.txt"
"${CMAKE_CURRENT_LIST_DIR}/test2.test-target.txt"
"${CMAKE_CURRENT_LIST_DIR}/test1.chained-input.txt"
"${CMAKE_CURRENT_LIST_DIR}/test2.chained-input.txt"
EXCLUDE_FROM_ALL
INTERFACE
)
21 changes: 11 additions & 10 deletions cmake/test/data/cmake/autocoder/test_chained_autocoder.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
####
# autocoder/test_chained_autocoder.cmake:
#
# Tests that a chained autocoder runs as expected - takes output from test_target_autocoder
# and creates chained files from them.
# Second stage of the chained-autocoder test. Takes the output of
# test_chained_input_autocoder (.chained-input.generated.txt) and produces .chained.txt files.
####
include_guard()
include(autocoder/helpers)
Expand All @@ -12,28 +12,29 @@ autocoder_setup_for_individual_sources()
####
# Function `test_chained_autocoder_is_supported`:
#
# Support all files with the ".test-target.generated.txt" suffix (output from test_target_autocoder)
# Support all files with the ".chained-input.generated.txt" suffix (output from
# test_chained_input_autocoder).
####
function(test_chained_autocoder_is_supported AC_INPUT_FILE)
autocoder_support_by_suffix(".test-target.generated.txt" "${AC_INPUT_FILE}" TRUE)
autocoder_support_by_suffix(".chained-input.generated.txt" "${AC_INPUT_FILE}" TRUE)
endfunction(test_chained_autocoder_is_supported)

####
# Function `test_chained_autocoder_setup_autocode`:
#
# Sets up the steps to run the chained autocoder and produce chained files during the build.
# Takes .test-target.generated.txt files and creates .chained.txt files from them.
# Takes .chained-input.generated.txt files and creates .chained.txt files from them.
#
# AC_INPUT_FILES: list of supported autocoder input files (.test-target.generated.txt files)
# AC_INPUT_FILES: list of supported autocoder input files (.chained-input.generated.txt files)
####
function(test_chained_autocoder_setup_autocode MODULE_NAME AC_INPUT_FILE)
# Set up generated sources list - convert .test-target.generated.txt to .chained.txt
# Set up generated sources list - convert .chained-input.generated.txt to .chained.txt
get_filename_component(BASENAME "${AC_INPUT_FILE}" NAME_WE)
# Remove the .test-target.generated part to get the base name
string(REPLACE ".test-target.generated" "" BASE_NAME "${BASENAME}")
# Remove the .chained-input.generated part to get the base name
string(REPLACE ".chained-input.generated" "" BASE_NAME "${BASENAME}")
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME}.chained.txt")

# This chained autocoder processes the .test-target.generated.txt file and creates a .chained.txt file
# This chained autocoder processes the .chained-input.generated.txt file and creates a .chained.txt file
add_custom_command(
OUTPUT ${GENERATED_SOURCE}
COMMAND "${CMAKE_COMMAND}" -E echo "Chained from: ${AC_INPUT_FILE}" > "${GENERATED_SOURCE}"
Expand Down
31 changes: 31 additions & 0 deletions cmake/test/data/cmake/autocoder/test_chained_input_autocoder.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
####
# autocoder/test_chained_input_autocoder.cmake:
#
# First stage of the chained-autocoder test. Consumes ".chained-input.txt" files and emits
# ".chained-input.generated.txt" files for the second stage (test_chained_autocoder) to chain
# off of. Kept distinct from test_target_autocoder so the chained test does not share an
# intermediate output filename with any other test target.
####
include_guard()
include(autocoder/helpers)

autocoder_setup_for_individual_sources()

function(test_chained_input_autocoder_is_supported AC_INPUT_FILE)
autocoder_support_by_suffix(".chained-input.txt" "${AC_INPUT_FILE}" TRUE)
endfunction(test_chained_input_autocoder_is_supported)

function(test_chained_input_autocoder_setup_autocode MODULE_NAME AC_INPUT_FILE)
get_filename_component(BASENAME "${AC_INPUT_FILE}" NAME_WE)
set(GENERATED_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${BASENAME}.chained-input.generated.txt")

add_custom_command(
OUTPUT ${GENERATED_SOURCE}
COMMAND "${CMAKE_COMMAND}" -E copy ${AC_INPUT_FILE} "${GENERATED_SOURCE}"
DEPENDS ${AC_INPUT_FILE}
COMMENT "Generating chained-input file from ${AC_INPUT_FILE}"
)

set(AUTOCODER_GENERATED_OTHER "${GENERATED_SOURCE}" PARENT_SCOPE)
set(AUTOCODER_GENERATED_AUTOCODER_INPUTS "${GENERATED_SOURCE}" PARENT_SCOPE)
endfunction(test_chained_input_autocoder_setup_autocode)
6 changes: 3 additions & 3 deletions cmake/test/data/cmake/target/test_chained_autocoder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function(test_chained_autocoder_add_deployment_target MODULE TARGET SOURCES DIRE
endfunction(test_chained_autocoder_add_deployment_target)

function(test_chained_autocoder_add_module_target MODULE TARGET SOURCES DEPENDENCIES)
# Run both autocoders in sequence: target autocoder first, then chained autocoder
run_ac_set("${MODULE}" "autocoder/test_target_autocoder" "autocoder/test_chained_autocoder")
# Run both autocoders in sequence: chained-input autocoder first, then chained autocoder
run_ac_set("${MODULE}" "autocoder/test_chained_input_autocoder" "autocoder/test_chained_autocoder")

# Use the variable from this run as set by the autocoders
add_custom_target("${MODULE}_test_chained_autocode" DEPENDS "${AUTOCODER_GENERATED_OTHER}")
add_dependencies("${MODULE}" "${MODULE}_test_chained_autocode")
Expand Down
4 changes: 2 additions & 2 deletions cmake/test/src/test_autocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def test_autocoder_chaining(AUTOCODER_BUILD):
# Verify that chained autocoder files are created
# First autocoder should create intermediate files with .generated suffix
for intermediate in [
"test1.test-target.generated.txt",
"test2.test-target.generated.txt",
"test1.chained-input.generated.txt",
"test2.chained-input.generated.txt",
]:
intermediate_path = build_cache_path / intermediate
assert (
Expand Down
Loading