Skip to content

Commit

Permalink
Add TRIBITS_REPORT_INVALID_TRIBITS_USAGE( and <Project>_ASSERT_CORREC…
Browse files Browse the repository at this point in the history
…T_TRIBITS_USAGE (#200)

This will allow CASL VERA to set:

  SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT WARNING)

so that it can upgrade TriBITS and then deal with the invalid usage warnings
after that.

This also sets ${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE_DEFAULT=ON by default
if it is not set by the project.  This is what it should have always been from
the beginning.  Hopefully this will not break any existing TriBITS projects
(but it is easy to fix by just setting the default in the
<projectDir>/ProjectName.cmake file).
  • Loading branch information
bartlettroscoe committed May 9, 2019
1 parent 1cbab5b commit eb2ffc4
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 116 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TRIBITS_ADD_ADVANCED_TEST( TestingFunctionMacro_UnitTests
-D${PROJECT_NAME}_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-P "${CMAKE_CURRENT_SOURCE_DIR}/TestingFunctionMacro_UnitTests.cmake"
PASS_REGULAR_EXPRESSION_ALL
"Final UnitTests Result: num_run = 544"
"Final UnitTests Result: num_run = 550"
"Final UnitTests Result: PASSED"
)

Expand Down
11 changes: 6 additions & 5 deletions test/core/ExamplesUnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4306,7 +4306,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPackageA_DOUBLE_SUBPACKAGE_INIT=TRUE
.
PASS_REGULAR_EXPRESSION_ALL
"Already called TRIBITS_SUBPACKGE[(][)] for thePkgWithSubpkgsWithUserErrors"
"Already called TRIBITS_SUBPACKGE[(][)] for the PkgWithSubpkgsWithUserErrors"
"subpackage A"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand All @@ -4317,8 +4318,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPAckageA_DOUBLE_SUBPACKAGE_POSTPROCESS=TRUE
.
PASS_REGULAR_EXPRESSION_ALL
"Already called TRIBITS_SUBPACKGE_POSTPROCESS[(][)] for"
"thePkgWithSubpkgsWithUserErrors subpackage A"
"Already called TRIBITS_SUBPACKGE_POSTPROCESS[(][)] for the"
"PkgWithSubpkgsWithUserErrors subpackage A"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand All @@ -4329,8 +4330,8 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsExampleProject_PkgWithSubpkgsWithUserErrors_SU
-DsubPAckageA_DOUBLE_SUBPACKAGE_POSTPROCESS=FALSE
.
PASS_REGULAR_EXPRESSION_ALL
"TRIBITS_SUBPACKAGE[(][)] must be called before"
"TRIBITS_SUBPACKAGE_POSTPROCESS[(][)]for the PkgWithSubpkgsWithUserErrors"
"TRIBITS_SUBPACKAGE[(][)] must be called before TRIBITS_SUBPACKAGE_POSTPROCESS[(][)]"
" for the PkgWithSubpkgsWithUserErrors"
"Configuring incomplete, errors occurred!"
ALWAYS_FAIL_ON_ZERO_RETURN

Expand Down
57 changes: 56 additions & 1 deletion test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ INCLUDE(TribitsStripQuotesFromStr)
INCLUDE(TribitsStandardizePaths)
INCLUDE(TribitsGetVersionDate)
INCLUDE(TribitsTplFindIncludeDirsAndLibraries)
INCLUDE(TribitsReportInvalidTribitsUsage)
INCLUDE(UnitTestHelpers)
INCLUDE(GlobalSet)
INCLUDE(GlobalNullSet)
Expand Down Expand Up @@ -556,6 +557,59 @@ FUNCTION(UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE)
ENDFUNCTION()


FUNCTION(UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE)

MESSAGE("\n***")
MESSAGE("*** Testing TRIBITS_REPORT_INVALID_TRIBITS_USAGE()")
MESSAGE("***\n")

SET(MESSAGE_WRAPPER_UNIT_TEST_MODE TRUE)
SET(PROJECT_NAME TRITU_PROJECT)

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): Default (FATAL_ERROR)")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went" " very wrong" " I think 1!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Something went; very wrong; I think 1!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): FATAL_ERROR")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE FATAL_ERROR)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went" " very wrong" " I think 2!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Something went; very wrong; I think 2!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): SEND_ERROR")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE SEND_ERROR)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 3!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"SEND_ERROR;Something went very wrong I think 3!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): WARNING")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE WARNING)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 4!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"WARNING;Something went very wrong I think 4!")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): IGNORE")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE IGNORE)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 5!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"")

MESSAGE("TRIBITS_REPORT_INVALID_TRIBITS_USAGE(): INVALID_ARGUMENT")
GLOBAL_SET(MESSAGE_WRAPPER_INPUT)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE INVALID_ARGUMENT)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE("Something went very wrong I think 6!")
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Error, invalid value for; TRITU_PROJECT_ASSERT_CORRECT_TRIBITS_USAGE =; 'INVALID_ARGUMENT'!; Value values include 'FATAL_ERROR', 'SEND_ERROR', 'WARNING', and 'IGNORE'!")

ENDFUNCTION()


FUNCTION(UNITEST_TRIBITS_ADD_TEST_BASIC)

MESSAGE("\n***")
Expand Down Expand Up @@ -3590,6 +3644,7 @@ UNITEST_TRIBITS_STRIP_QUOTES_FROM_STR()
UNITEST_TRIBITS_GET_VERSION_DATE_FROM_RAW_GIT_COMMIT_UTC_TIME()
UNITEST_TRIBITS_GET_RAW_GIT_COMMIT_UTC_TIME()
UNITTEST_TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE()
UNITTEST_TRIBITS_REPORT_INVALID_TRIBITS_USAGE()

# Set the default test categories
SET(${PROJECT_NAME}_TEST_CATEGORIES NIGHTLY)
Expand Down Expand Up @@ -3641,4 +3696,4 @@ MESSAGE("*** Determine final result of all unit tests")
MESSAGE("***\n")

# Pass in the number of expected tests that must pass!
UNITTEST_FINAL_RESULT(544)
UNITTEST_FINAL_RESULT(550)
46 changes: 27 additions & 19 deletions tribits/core/package_arch/TribitsAddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ INCLUDE(TribitsAddExecutableTestHelpers)
INCLUDE(TribitsCommonArgsHelpers)
INCLUDE(TribitsAddTestHelpers)
INCLUDE(TribitsGeneralMacros)
INCLUDE(TribitsReportInvalidTribitsUsage)

INCLUDE(PrintVar)
INCLUDE(AppendSet)
Expand Down Expand Up @@ -344,12 +345,14 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
# This is a subpackage being processed

IF(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_EXECUTABLE()"
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_EXECUTABLE()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_EXECUTABLE() before "
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_ADD_EXECUTABLE() before "
" TRIBITS_SUBPACKAGE_POSTPROCESS() in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand All @@ -358,12 +361,14 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
# This is a package being processed

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
" TRIBITS_ADD_EXECUTABLE() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_EXECUTABLE() before "
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_ADD_EXECUTABLE() before "
" TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand Down Expand Up @@ -488,25 +493,28 @@ FUNCTION(TRIBITS_ADD_EXECUTABLE EXE_NAME)
FOREACH(IMPORTEDLIB ${PARSE_IMPORTEDLIBS})
SET(PREFIXED_LIB "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${IMPORTEDLIB}")
IF (${PREFIXED_LIB}_INCLUDE_DIRS)
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is not allowed to be a TESTONLY lib!"
" Use TESTONLYLIBS instead!" )
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is not allowed to be a TESTONLY lib!"
" Use TESTONLYLIBS instead!" )
ENDIF()
LIST(FIND ${PACKAGE_NAME}_LIBRARIES ${PREFIXED_LIB} FOUND_IDX)
IF (NOT FOUND_IDX EQUAL -1)
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' in IMPORTEDLIBS is in"
" this SE package and is *not* an external lib!"
" TriBITS takes care of linking against libs the current"
" SE package automatically. Please remove '${IMPORTEDLIB}' from IMPORTEDLIBS!")
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' in IMPORTEDLIBS is in"
" this SE package and is *not* an external lib!"
" TriBITS takes care of linking against libs the current"
" SE package automatically. Please remove '${IMPORTEDLIB}' from IMPORTEDLIBS!")
ELSEIF (TARGET ${PREFIXED_LIB})
MESSAGE(FATAL_ERROR "ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is *not* an external library but instead is a library"
" defined in this CMake project!"
" TriBITS takes care of linking against libraries in dependent upstream"
" SE packages. If you want to link to a library in an upstream SE"
" package then add the SE package name for that library to the appropriate"
" list in this SE package's dependencies file"
" ${${PACKAGE_NAME}_SOURCE_DIR}/cmake/Dependencies.cmake")
MESSAGE(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is *not* an external library but instead is a library"
" defined in this CMake project!"
" TriBITS takes care of linking against libraries in dependent upstream"
" SE packages. If you want to link to a library in an upstream SE"
" package then add the SE package name for that library to the appropriate"
" list in this SE package's dependencies file"
" ${${PACKAGE_NAME}_SOURCE_DIR}/cmake/Dependencies.cmake")
ENDIF()
ENDFOREACH()

Expand Down
25 changes: 21 additions & 4 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ INCLUDE(TribitsVerbosePrintVar)
INCLUDE(TribitsProcessEnabledTpl)
INCLUDE(TribitsInstallHeaders)
INCLUDE(TribitsGetVersionDate)
INCLUDE(TribitsReportInvalidTribitsUsage)

# Standard TriBITS utilities includes
INCLUDE(TribitsAddOptionAndDefine)
Expand Down Expand Up @@ -622,16 +623,32 @@ MACRO(TRIBITS_DEFINE_GLOBAL_OPTIONS_AND_DEFINE_EXTRA_REPOS)
"Relative CPU speed of the computer used to scale performance tests (default 1.0)."
)

IF ("${${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE_DEFAULT}" STREQUAL "")
SET(${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE_DEFAULT ON)
ENDIF()
ADVANCED_SET( ${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE
${${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE_DEFAULT}
CACHE BOOL
"Determines if a variety of development mode checks are turned on by default or not." )
"Determines if a variety of development mode checks are turned on by default or not."
)

ADVANCED_SET( ${PROJECT_NAME}_ASSERT_MISSING_PACKAGES
${${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE}
CACHE BOOL
"Determines if asserts are performed on missing packages or not." )

IF ("${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT}" STREQUAL "")
IF (${PROJECT_NAME}_ENABLE_DEVELOPMENT_MODE)
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT FATAL_ERROR)
ELSE()
SET(${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT IGNORE)
ENDIF()
ENDIF()
ADVANCED_SET( ${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE
"${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT}"
CACHE BOOL
"Assert correct usage of TriBITS. Value values include 'FATAL_ERROR', 'SEND_ERROR', 'WARNING', and 'IGNORE'. Default '${${PROJECT_NAME}_ASSERT_CORRECT_TRIBITS_USAGE_DEFAULT}' " )

ADVANCED_SET( ${PROJECT_NAME}_WARN_ABOUT_MISSING_EXTERNAL_PACKAGES
FALSE CACHE BOOL
"If set to TRUE, a 'NOTE' is printed for each missing package that is ignored." )
Expand Down Expand Up @@ -2568,9 +2585,9 @@ MACRO(TRIBITS_CONFIGURE_ENABLED_PACKAGES)
INCLUDE("${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()
IF (NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS)
MESSAGE(FATAL_ERROR
"ERROR: Forgot to call TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}"
)
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"ERROR: Forgot to call TRIBITS_PACKAGE_POSTPROCESS() in"
" ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

LIST(APPEND ENABLED_PACKAGE_LIBS_TARGETS ${TRIBITS_PACKAGE}_libs)
Expand Down
13 changes: 9 additions & 4 deletions tribits/core/package_arch/TribitsLibraryMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ INCLUDE(AppendStringVar)
INCLUDE(PrependGlobalSet)
INCLUDE(RemoveGlobalDuplicates)
INCLUDE(TribitsGeneralMacros)
INCLUDE(TribitsReportInvalidTribitsUsage)
INCLUDE(SetAndIncDirs)

###
Expand Down Expand Up @@ -483,12 +484,14 @@ FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)
# This is a subpackage being processed

IF(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_LIBRARY()"
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_SUBPACKAGE() before TRIBITS_ADD_LIBRARY()"
" in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_LIBRARY() before "
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_ADD_LIBRARY() before "
" TRIBITS_SUBPACKAGE_POSTPROCESS() in ${CURRENT_SUBPACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand All @@ -497,12 +500,14 @@ FUNCTION(TRIBITS_ADD_LIBRARY LIBRARY_NAME_IN)
# This is a package being processed

IF(NOT ${PACKAGE_NAME}_TRIBITS_PACKAGE_DECL_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_PACKAGE() or TRIBITS_PACKAGE_DECL() before"
" TRIBITS_ADD_LIBRARY() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

IF(${PACKAGE_NAME}_TRIBITS_PACKAGE_POSTPROCESS_CALLED)
MESSAGE(FATAL_ERROR "Must call TRIBITS_ADD_LIBRARY() before "
TRIBITS_REPORT_INVALID_TRIBITS_USAGE(
"Must call TRIBITS_ADD_LIBRARY() before "
" TRIBITS_PACKAGE_POSTPROCESS() in ${TRIBITS_PACKAGE_CMAKELIST_FILE}")
ENDIF()

Expand Down
Loading

0 comments on commit eb2ffc4

Please sign in to comment.