Skip to content

Commit

Permalink
Add yaml error definition
Browse files Browse the repository at this point in the history
  • Loading branch information
andistorm committed Aug 24, 2023
1 parent 5478fbc commit b0bbc28
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
57 changes: 57 additions & 0 deletions cmake/everest-generate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ function(ev_add_project)
)
get_target_property(EVEREST_PROJECT_DIRS generate_cpp_files EVEREST_PROJECT_DIRS)

# check for errors
set(ERRORS_DIR "${EVEREST_PROJECT_DIR}/errors")
if (EXISTS ${ERRORS_DIR})
message(STATUS "Adding errors from ${ERRORS_DIR}")
file(GLOB ERRORS_FILES
${ERRORS_DIR}/*.yaml
)

_ev_add_errors(${ERRORS_FILES})

if (CALLED_FROM_WITHIN_PROJECT)
install(
DIRECTORY ${ERRORS_DIR}
DESTINATION "${CMAKE_INSTALL_DATADIR}/everest"
FILES_MATCHING PATTERN "*.yaml"
)
endif ()
endif ()

# check for types
set(TYPES_DIR "${EVEREST_PROJECT_DIR}/types")
if (EXISTS ${TYPES_DIR})
Expand Down Expand Up @@ -139,6 +158,44 @@ function (_ev_add_interfaces)
)
endfunction()

#
# errors
#

function (_ev_add_errors)
get_target_property(GENERATED_OUTPUT_DIR generate_cpp_files EVEREST_GENERATED_OUTPUT_DIR)
set(CHECK_DONE_FILE "${GENERATED_OUTPUT_DIR}/.errors_generated_${EVEREST_PROJECT_NAME}")

add_custom_command(
OUTPUT
"${CHECK_DONE_FILE}"
DEPENDS
${ARGV}
COMMENT
"Generating/updating error definition files ..."
VERBATIM
COMMAND
${EV_CLI} errors generate-headers
--disable-clang-format
--schemas-dir "$<TARGET_PROPERTY:generate_cpp_files,EVEREST_SCHEMA_DIR>"
--output-dir "$<TARGET_PROPERTY:generate_cpp_files,EVEREST_GENERATED_INCLUDE_DIR>/generated/errors"
--everest-dir ${EVEREST_PROJECT_DIRS}
COMMAND
${CMAKE_COMMAND} -E touch "${CHECK_DONE_FILE}"
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
)

add_custom_target(generate_errors_cpp_${EVEREST_PROJECT_NAME}
DEPENDS
${CHECK_DONE_FILE}
)

add_dependencies(generate_cpp_files
generate_errors_cpp_${EVEREST_PROJECT_NAME}
)
endfunction()

#
# types
#
Expand Down
1 change: 1 addition & 0 deletions errors/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description: An empty error file
6 changes: 6 additions & 0 deletions errors/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Example group of errors used by example modules to demonstrate error handling
errors:
- name: ExampleErrorA
description: Example error A
- name: ExampleErrorB
description: Example error B
4 changes: 4 additions & 0 deletions errors/ocpp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: All errors defined by OCPP
errors:
- name: NotImplemented
description: The requested Action is recognized but not implemented by the receiver.

0 comments on commit b0bbc28

Please sign in to comment.