Skip to content

Commit

Permalink
Fix #2315, uniqueness of tbl target names
Browse files Browse the repository at this point in the history
If the passed-in table name does not use a qualifier suffix, then
generate one by computing a hash of the context information.  This
ensures that the generated intermediate target names will be unique.
  • Loading branch information
jphickey committed May 2, 2023
1 parent 7479d22 commit 4a11c24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ function(add_cfe_tables TABLE_FQNAME TBL_DEFAULT_SRC_FILES)

get_filename_component(APP_NAME ${TABLE_FQNAME} NAME_WE)

# The passed-in name allows for a qualifier (in the form of APP_NAME.QUALIFIER) to get
# uniqueness in the generated target names. If there is no qualifier, then there
# will potentially be a target name conflict. To avoid this, generate a hash of the
# context of this call - the current directory, app/tgt names, and source files. This
# should be unique but also produce the same hash when CMake is re-run. The hash
# can then be used as a qualifier.
if (TABLE_FQNAME STREQUAL APP_NAME)
string(SHA1 CONTEXT_HASH
"${CMAKE_CURRENT_LIST_DIR}+${TGTNAME}+${APP_NAME}+${TBL_DEFAULT_SRC_FILES};${ARGN}"
)
set(TABLE_FQNAME "${APP_NAME}.tbl${CONTEXT_HASH}")

if ($ENV{VERBOSE})
message("No suffix specified, table build using ${TABLE_FQNAME} for ${APP_NAME} table")
endif()
endif()

# If "TGTNAME" is set, then use it directly
set(TABLE_TGTLIST ${TGTNAME})
set(TABLE_TEMPLATE "${CFE_SOURCE_DIR}/cmake/tables/table_rule_template.d.in")
Expand Down
8 changes: 6 additions & 2 deletions cmake/global_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ function(cfe_locate_implementation_file OUTPUT_VAR FILE_NAME)

set(SELECTED_FILE)
foreach (CHECK_FILE ${IMPL_SEARCH_PATH})
if ($ENV{VERBOSE})
message("Testing for: ${CHECK_FILE}")
endif()
if (EXISTS "${CHECK_FILE}")
list(APPEND SELECTED_FILE ${CHECK_FILE})
endif()
Expand All @@ -76,12 +79,13 @@ function(cfe_locate_implementation_file OUTPUT_VAR FILE_NAME)
else()
set(SELECTED_FILE "${CMAKE_CURRENT_LIST_DIR}/${LOCATEIMPL_ARG_FALLBACK_FILE}")
endif()
if (NOT EXISTS "${SELECTED_FILE}" AND NOT LOCATEIMPL_ARG_OPTIONAL)
message(FATAL_ERROR "No implementation for ${FILE_NAME} found")
endif()
endif()

if (SELECTED_FILE)
message(STATUS "Using file: ${SELECTED_FILE} for ${FILE_NAME}")
elseif(NOT LOCATEIMPL_ARG_OPTIONAL)
message(FATAL_ERROR "No implementation for ${FILE_NAME} found")
endif()

# Export the result to the caller
Expand Down

0 comments on commit 4a11c24

Please sign in to comment.