Skip to content

Commit cc2522b

Browse files
authored
Add fpp-to-json to FPP model sub-build (#4268)
* Add fpp-to-json to FPP model subbuild * Update fprime-fpp version to 3.1.0a9
1 parent 6af7bcd commit cc2522b

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

cmake/FPrime.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ macro(fprime_initialize_build_system)
160160

161161
# Perform necessary sub-builds
162162
if (NOT FPRIME_IS_SUB_BUILD)
163-
run_sub_build(info-cache target/sub-build/fpp_locs target/sub-build/fpp_depend target/sub-build/module_info)
163+
run_sub_build(info-cache target/sub-build/fpp_locs target/sub-build/fpp_depend target/sub-build/fpp_to_json target/sub-build/module_info)
164164
# Import the pre-computed properties!
165165
include("${CMAKE_BINARY_DIR}/fprime_module_info.cmake")
166166
endif()
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
####
2+
# fpp_to_json.cmake:
3+
#
4+
# fpp_to_json is a special target used to generate the JSON representation of the FPP model. This allows tools built on
5+
# the JSON model representation to integrate with the build system.
6+
####
7+
include_guard()
8+
set(FPP__INTERNAL_ARGS_FROM_FILE "${PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/../tools/arguments-from-file.py")
9+
####
10+
# Function `fpp_to_json_add_global_target`:
11+
#
12+
# Sets up the `fpp_to_json` target used to generate depend output across the whole build.
13+
# - **TARGET:** name of the target to setup (fpp_to_json)
14+
####
15+
function(fpp_to_json_add_global_target TARGET)
16+
add_custom_target("${TARGET}")
17+
endfunction(fpp_to_json_add_global_target)
18+
19+
####
20+
# Function `fpp_to_json_add_deployment_target`:
21+
#
22+
# Pass-through to fpp_to_json_add_module_target. FULL_DEPENDENCIES is unused.
23+
####
24+
function(fpp_to_json_add_deployment_target MODULE TARGET SOURCES DEPENDENCIES FULL_DEPENDENCIES)
25+
fpp_to_json_add_module_target("${MODULE}" "${TARGET}" "${SOURCES}" "${DEPENDENCIES}")
26+
endfunction(fpp_to_json_add_deployment_target)
27+
28+
####
29+
# Function `fpp_to_json_add_module_target`:
30+
#
31+
# Generates the cached fpp-to-json output fore each module and registers the target to the global fpp_to_json target.
32+
# - **MODULE:** module name, unused
33+
# - **TARGET:** name of the target to setup (fpp_depend)
34+
# - **SOURCES:** list of sources filtered to .fpp
35+
# - **DEPENDENCIES:** module dependencies, unused.
36+
####
37+
function(fpp_to_json_add_module_target MODULE TARGET SOURCES_UNUSED DEPENDENCIES)
38+
get_target_property(AUTOCODER_INPUTS "${MODULE}" AUTOCODER_INPUTS)
39+
set(FPP_SOURCES "")
40+
# Check each source for FPP support
41+
foreach(SOURCE IN LISTS AUTOCODER_INPUTS)
42+
fpp_is_supported("${SOURCE}")
43+
if (IS_SUPPORTED)
44+
list(APPEND FPP_SOURCES "${SOURCE}")
45+
endif()
46+
endforeach()
47+
file(RELATIVE_PATH OFFSET "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
48+
set(LOCAL_DIR "${CMAKE_CURRENT_BINARY_DIR}")
49+
set(DELIVERY_DIR "${FPRIME_BINARY_DIR}/${OFFSET}")
50+
file(MAKE_DIRECTORY "${LOCAL_DIR}")
51+
file(MAKE_DIRECTORY "${DELIVERY_DIR}")
52+
if (FPP_SOURCES)
53+
set(OUTPUT_FILES
54+
"${LOCAL_DIR}/fpp-ast.json"
55+
"${LOCAL_DIR}/fpp-analysis.json"
56+
"${LOCAL_DIR}/fpp-loc-map.json"
57+
)
58+
add_custom_command(
59+
OUTPUT ${OUTPUT_FILES}
60+
COMMAND ${FPP__INTERNAL_ARGS_FROM_FILE}
61+
"${LOCAL_DIR}/fpp-cache/stdout.txt"
62+
"fpp-to-json"
63+
${FPP_SOURCES}
64+
DEPENDS
65+
fpp_depend
66+
${FPP_SOURCES}
67+
"${LOCAL_DIR}/fpp-cache/stdout.txt"
68+
)
69+
add_custom_target("${TARGET}_${MODULE}" DEPENDS ${OUTPUT_FILES}
70+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${OUTPUT_FILES} "${DELIVERY_DIR}"
71+
)
72+
else()
73+
add_custom_target("${TARGET}_${MODULE}")
74+
endif()
75+
add_dependencies("${TARGET}" "${TARGET}_${MODULE}")
76+
endfunction(fpp_to_json_add_module_target)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
import subprocess
3+
4+
if len(sys.argv) < 2:
5+
print("[ERROR] Supply output file then tool")
6+
sys.exit(1)
7+
with open(sys.argv[1], "r") as file_handle:
8+
args = sys.argv[2:] + [line.strip() for line in file_handle.readlines()]
9+
sys.exit(subprocess.run(args, stdout=file_handle).returncode)

0 commit comments

Comments
 (0)