Make a stab at adapting the new, simplier verification to vanilla stepcode

This commit is contained in:
Cliff Yapp 2016-08-06 11:23:34 -04:00
parent e38519a7f1
commit 06b13bb9af
8 changed files with 143 additions and 237 deletions

View file

@ -32,7 +32,7 @@ macro(VERIFY_FILES filelist warn resultvar)
MD5(${filefullname} ${filevar}_md5)
if(NOT "${${filevar}_md5}" STREQUAL "${baseline_${filevar}_md5}")
if("${warn}" STREQUAL "1")
message("\n${filename} differs from baseline: baseline md5 hash is ${baseline_${filevar}_md5} and current hash is ${${filevar}_md5}\n")
message("\n${filename} differs from baseline: baseline md5 hash is ${baseline_${filevar}_md5} and current hash is ${${filevar}_md5}\n")
endif("${warn}" STREQUAL "1")
set(${resultvar} 0)
endif(NOT "${${filevar}_md5}" STREQUAL "${baseline_${filevar}_md5}")
@ -59,20 +59,6 @@ macro(WRITE_MD5_SUMS filelist outfile)
endforeach(fileitem ${filelist})
endmacro(WRITE_MD5_SUMS)
macro(GET_GENERATOR_EXEC_VERSIONS)
# Read lemon version
execute_process(COMMAND ${LEMON_EXECUTABLE} -x OUTPUT_VARIABLE lemon_version)
string(REPLACE "Lemon version " "" lemon_version "${lemon_version}")
string(STRIP "${lemon_version}" lemon_version)
# Read re2c version
execute_process(COMMAND ${RE2C_EXECUTABLE} -V OUTPUT_VARIABLE re2c_version)
string(STRIP "${re2c_version}" re2c_version)
# Read perplex version
execute_process(COMMAND ${PERPLEX_EXECUTABLE} -v OUTPUT_VARIABLE perplex_version)
string(STRIP "${perplex_version}" perplex_version)
endmacro(GET_GENERATOR_EXEC_VERSIONS)
# Local Variables:
# tab-width: 8
# mode: cmake

View file

@ -1,102 +0,0 @@
# Inherit the parent CMake setting
set(CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
set(LEMON_EXECUTABLE "@LEMON_EXECUTABLE@")
set(RE2C_EXECUTABLE "@RE2C_EXECUTABLE@")
set(PERPLEX_EXECUTABLE "@PERPLEX_EXECUTABLE@")
set(SYNC_SCRIPT "@SYNC_SCRIPT@")
set(SYNC_TARGET_NAME "@SYNC_TARGET_NAME@")
set(DEBUGGING_GENERATED_SOURCES "@DEBUGGING_GENERATED_SOURCES@")
if(NOT DEBUGGING_GENERATED_SOURCES)
# Include the file the provides the baseline against which
# current files will be compared
include("@BASELINE_INFORMATION_FILE@")
# Define a variety of convenience routines
include("@PROJECT_CMAKE_DIR@/Generated_Source_Utils.cmake")
# The following need to be checked:
#
# 1. baseline input MD5 hashes against the current input
# hashes. If the cached sources were generated using
# inputs other than the current inputs, note they are
# out of sync but don't stop. Templates used by perplex
# and lemon are part of this group.
#
# 2. baseline cached source MD5 hashes against current
# cached source MD5 hashes. Making sure no changes
# have been made to the generated sources. If the
# cached sources need to be updated (see #1, for example)
# their MD5 hashes need to be updated at the same time.
#
# 3. MD5 hashes of output generated by the tools against
# the MD5 hashes of the equalivent cached sources, if
# a) the tool versions are the same b) the input MD5
# hash comparisions were the same and c) the baseline
# test from #2 passed. This is done to detect platform
# differences in output sources, but is only valid if
# the input files are in their "pristine" state and the
# toolchain is equalivent to that used for the baseline.
# Individually verify all of the files in question.
set(input_files "@INPUT_FILELIST@")
VERIFY_FILES("${input_files}" 0 input_unchanged)
set(template_files "@TEMPLATE_FILELIST@")
VERIFY_FILES("${template_files}" 1 templates_unchanged)
set(cached_files "@CACHED_FILELIST@")
VERIFY_FILES("${cached_files}" 1 cached_unchanged)
if(cached_unchanged)
message( "Cached generated source code has not been modified.")
else()
message(FATAL_ERROR "Cached generated sources do not match the MD5 hashes present in /home/mark/step/sc/src/express/generated/verification_info.cmake - if updating cached sources, remember that the build enforces the requirement that associated MD5 hashes in /home/mark/step/sc/src/express/generated/verification_info.cmake are current as well. Cached generated sources should not be directly edited.")
endif(cached_unchanged)
GET_GENERATOR_EXEC_VERSIONS()
if("${lemon_version}" VERSION_EQUAL "${baseline_lemon_version}" AND "${perplex_version}" VERSION_EQUAL "${baseline_perplex_version}" AND "${re2c_version}" VERSION_EQUAL "${baseline_re2c_version}")
set(tool_versions_equal 1)
else()
set(tool_versions_equal 0)
endif()
if(NOT input_unchanged)
if(templates_unchanged AND tool_versions_equal)
message("Input files changed - syncing cached outputs")
execute_process(COMMAND ${CMAKE_COMMAND} -P ${SYNC_SCRIPT} OUTPUT_VARIABLE output)
else(templates_unchanged AND tool_versions_equal)
if(NOT templates_unchanged AND NOT tool_versions_equal)
message("Input files have been updated, but templates and current tool versions do not match those previously used to generate cached sources. Automatic syncing will not proceed.")
message("To force syncing, use the build target ${SYNC_TARGET_NAME}")
else(NOT templates_unchanged AND NOT tool_versions_equal)
if(NOT templates_unchanged)
message("Input files have been updated, but templates do not match those previously used to generate cached sources. Automatic syncing will not proceed.")
message("To force syncing, use the build target ${SYNC_TARGET_NAME}")
endif(NOT templates_unchanged)
if(NOT tool_versions_equal)
message("Input files have been updated, but tool versions do not match those previously used to generate cached sources. Automatic syncing will not proceed.")
message("To force syncing, use the build target ${SYNC_TARGET_NAME}")
endif(NOT tool_versions_equal)
endif(NOT templates_unchanged AND NOT tool_versions_equal)
endif(templates_unchanged AND tool_versions_equal)
else(NOT input_unchanged)
if(templates_unchanged AND cached_unchanged AND tool_versions_equal)
# Under these conditions, the uncached generated output should be equal to the cached files.
# Check if it is - a difference here may indicate a platform-specific behavior in one of the
# generators.
set(build_files "@BUILD_OUTPUT_FILELIST@")
VERIFY_FILES("${build_files}" 1 platform_unchanged)
if(NOT platform_unchanged)
message("Note: give these build inputs and tools, source files should be identical to generated files. Differences were still observed - possible indiciation of platform-specific generator behavior.")
endif(NOT platform_unchanged)
endif(templates_unchanged AND cached_unchanged AND tool_versions_equal)
endif(NOT input_unchanged)
else(NOT DEBUGGING_GENERATED_SOURCES)
message("\nNote: DEBUGGING_GENERATED_SOURCES is enabled - generated outputs will contain configuration-specific debugging information, so syncing cached output files is not possible. To restore normal behavior, disable DEBUGGING_GENERATED_SOURCES.\n")
endif(NOT DEBUGGING_GENERATED_SOURCES)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

35
cmake/md5_gen.cmake.in Normal file
View file

@ -0,0 +1,35 @@
# Inherit the parent CMake setting
set(CURRENT_SOURCE_DIR @CMAKE_CURRENT_SOURCE_DIR@)
set(CURRENT_BINARY_DIR @CMAKE_CURRENT_BINARY_DIR@)
# Define a variety of convenience routines
include(@PROJECT_CMAKE_DIR@/Generated_Source_Utils.cmake)
# The following steps are executed to sync generated sources:
#
# 1. Create a new verification_info.cmake file and populate
# it with the MD5 sums for current files.
#
# 2. Overwrite the original cached verification_info.cmake
# and generated files with the new ones. If LOCKED_SOURCE_DIR
# is ON, this step will not be carried out - instead, an
# informational message with manual updating instructions
# will be printed.
set(new_info_file "${CURRENT_BINARY_DIR}/verification_info.cmake")
file(WRITE ${new_info_file} "# Autogenerated verification information\n")
# Handle input files
set(input_files "@MD5_FILELIST@")
WRITE_MD5_SUMS("${input_files}" "${new_info_file}")
message("New verification file created: ${new_info_file}")
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

30
cmake/md5_verify.cmake.in Normal file
View file

@ -0,0 +1,30 @@
# Inherit the parent CMake setting
set(DEBUGGING_GENERATED_SOURCES @DEBUGGING_GENERATED_SOURCES@)
set(CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
# Include the file the provides the baseline against which
# current files will be compared
include("@BASELINE_INFORMATION_FILE@")
# Define a variety of convenience routines
include("@PROJECT_CMAKE_DIR@/Generated_Source_Utils.cmake")
# Individually verify all of the files in question.
set(filelist "@MD5_FILELIST@")
VERIFY_FILES("${filelist}" 1 srcs_pass)
if(NOT srcs_pass)
if(NOT DEBUGGING_GENERATED_SOURCES)
message(FATAL_ERROR "Sources have been modified and md5 sums have not been updated. This generally indicates either\n a) an input file has been modified but generated files have not been updated, or\n b) genenerated files have been edited directly.\nTo clear the error:\n a) Copy the new generated sources from the build directory to the generated/ sources directory, use the <target>_md5gen build target to create a new verifictation_info.cmake file, and copy verfication_info.cmake to generated/ as well.\n b) install Perplex/Re2C/LEMON and make the changes to the input file rather than the generated file.\nNote:\n If this is a debugging situation where multiple sequential tests must be conducted, temporarily set the variable DEBUGGING_GENERATED_SOURCES to ON during the CMake configure to disable this check.\nThis measure is necessary to ensure that compilations using either Perplex/Re2C/LEMON generation or the cached outputs of those tools produce consistent results.")
else(NOT DEBUGGING_GENERATED_SOURCES)
message(WARNING "Note: Sources have been modified and md5 sums have not been updated - build failure condition temporarily overridden by DEBUGGING_GENERATED_SOURCES setting.")
endif(NOT DEBUGGING_GENERATED_SOURCES)
endif(NOT srcs_pass)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

View file

@ -1,39 +0,0 @@
# Inherit the parent CMake setting
set(DEBUGGING_GENERATED_SOURCES @DEBUGGING_GENERATED_SOURCES@)
set(CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
# Include the file the provides the baseline against which
# current files will be compared
if(NOT DEBUGGING_GENERATED_SOURCES)
include("@BASELINE_INFORMATION_FILE@")
# Define a variety of convenience routines
include("@PROJECT_CMAKE_DIR@/Generated_Source_Utils.cmake")
# Individually verify all of the files in question.
set(filelist "@CACHED_FILELIST@")
VERIFY_FILES("${filelist}" 1 srcs_pass)
if( srcs_pass)
message( "Generated source code has not been modified.")
else(srcs_pass)
message(FATAL_ERROR "Generated sources have been modified. These files should never be modified directly except when debugging faulty output from the generators - changes to lexer and parser logic should be made to the generator input files. If this is a debugging situation, set the variable DEBUGGING_GENERATED_SOURCES to ON during the CMake configure.")
endif(srcs_pass)
# If we got by that test, see if it looks like these
# sources came from the current input files. It's not
# a failure condition if they didn't, but warn about it.
set(filelist "@INPUT_FILELIST@")
VERIFY_FILES("${filelist}" 0 inputs_same)
if(NOT inputs_same)
message("Note: cached generated sources are not in sync with input files.")
endif(NOT inputs_same)
endif(NOT DEBUGGING_GENERATED_SOURCES)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8

View file

@ -2,72 +2,57 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${SC_SOURCE_DIR}/src/base
)
)
# Set up the information we need to feed the generated source management
# scripts
set(BASELINE_INFORMATION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/generated/verification_info.cmake")
set(PROJECT_CMAKE_DIR "${SC_SOURCE_DIR}/cmake")
set(INPUT_FILELIST expscan.l expparse.y)
set(TEMPLATE_FILELIST ${LEMON_TEMPLATE} ${PERPLEX_TEMPLATE})
set(BUILD_OUTPUT_FILELIST
${CMAKE_CURRENT_BINARY_DIR}/expscan.c
${CMAKE_CURRENT_BINARY_DIR}/expscan.h
${CMAKE_CURRENT_BINARY_DIR}/expparse.c
${CMAKE_CURRENT_BINARY_DIR}/expparse.h
)
set(CACHED_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}" "${CACHED_FILES_DIR}" CACHED_FILELIST "${BUILD_OUTPUT_FILELIST}")
set(SYNC_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.cmake")
set(SYNC_TARGET_NAME "express_sync_generated_files")
set(MD5_FILELIST
"${CMAKE_CURRENT_SOURCE_DIR}/expscan.l"
"${CMAKE_CURRENT_SOURCE_DIR}/expparse.y"
"${CMAKE_CURRENT_SOURCE_DIR}/generated/expscan.c"
"${CMAKE_CURRENT_SOURCE_DIR}/generated/expscan.h"
"${CMAKE_CURRENT_SOURCE_DIR}/generated/expparse.c"
"${CMAKE_CURRENT_SOURCE_DIR}/generated/expparse.h"
)
configure_file(${SC_SOURCE_DIR}/cmake/md5_gen.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/express_md5gen.cmake @ONLY)
configure_file(${SC_SOURCE_DIR}/cmake/md5_verify.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/express_verify.cmake @ONLY)
# Convenience target to generate an updated verification_info.cmake file
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/express_md5gen.sentinel
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_md5gen.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/express_md5gen.sentinel
)
add_custom_target(express_md5gen DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/express_md5gen.sentinel)
# Target for actually checking cached MD5 sums against files
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/express_verify.sentinel
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_verify.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/express_verify.sentinel
DEPENDS ${MD5_FILELIST}
)
add_custom_target(express_verify DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/express_verify.sentinel)
# Depending on whether we're using pre-generated sources or building them on
# the fly, set up targets and source lists.
if(SC_GENERATE_LP_SOURCES)
LEMON_TARGET(ExpParser expparse.y expparse.c expparse.h)
PERPLEX_TARGET(ExpScanner expscan.l ${CMAKE_CURRENT_BINARY_DIR}/expscan.c ${CMAKE_CURRENT_BINARY_DIR}/expscan.h)
LEMON_TARGET(ExpParser expparse.y)
PERPLEX_TARGET(ExpScanner expscan.l)
ADD_PERPLEX_LEMON_DEPENDENCY(ExpScanner ExpParser)
set(EXPRESS_GENERATED_SRCS
${LEMON_ExpParser_OUTPUT_SOURCE}
${PERPLEX_ExpScanner_OUTPUTS}
)
configure_file(${SC_SOURCE_DIR}/cmake/manage_generated.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/express_manage_generated.cmake @ONLY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/express_manage_generated.sentinel
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_manage_generated.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/express_manage_generated.sentinel
DEPENDS ${INPUT_FILELIST} ${TEMPLATE_FILELIST} ${CACHED_FILELIST} ${PERPLEX_ExpScanner_OUTPUTS} ${LEMON_ExpParser_OUTPUT_SOURCE} generated/verification_info.cmake ${PROJECT_CMAKE_DIR}/Generated_Source_Utils.cmake
)
add_custom_target(express_verify DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/express_manage_generated.sentinel)
configure_file(${SC_SOURCE_DIR}/cmake/sync_generated.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.cmake @ONLY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.sentinel
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.sentinel
DEPENDS ${INPUT_FILELIST} ${TEMPLATE_FILELIST} ${PERPLEX_ExpScanner_OUTPUTS} ${LEMON_ExpParser_OUTPUT_SOURCE} ${PROJECT_CMAKE_DIR}/Generated_Source_Utils.cmake
)
add_custom_target(express_sync_generated_files DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/express_sync_generated.sentinel)
${LEMON_ExpParser_SRC}
${PERPLEX_ExpScanner_SRC}
)
else(SC_GENERATE_LP_SOURCES)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/generated)
set(EXPRESS_GENERATED_SRCS
generated/expparse.c
generated/expscan.c
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/generated)
configure_file(${SC_SOURCE_DIR}/cmake/verify_generated.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/express_verify_generated.cmake @ONLY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/express_verify_generated.sentinel
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_verify_generated.cmake
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/express_verify_generated.sentinel
DEPENDS ${INPUT_FILELIST} ${CACHED_FILELIST} generated/verification_info.cmake ${PROJECT_CMAKE_DIR}/Generated_Source_Utils.cmake
)
add_custom_target(express_verify DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/express_verify_generated.sentinel)
)
endif(SC_GENERATE_LP_SOURCES)
set(EXPRESS_SOURCES
@ -110,14 +95,29 @@ set(CHECK_EXPRESS_SOURCES
inithook.c
)
set(EXPRESS_PRIVATE_HDRS
SET(EXPRESS_PRIVATE_HDRS
exptoks.h
stack.h
)
)
SC_ADDLIB(express "${EXPRESS_SOURCES}" "base")
add_dependencies(express express_verify)
add_dependencies(express version_string)
SC_ADDEXEC("check-express" "${CHECK_EXPRESS_SOURCES}" "express;base")
if(SC_GENERATE_LP_SOURCES)
set_property(TARGET express APPEND PROPERTY INCLUDE_DIRECTORIES "${PERPLEX_ExpScanner_INCLUDE_DIR}")
set_property(TARGET express APPEND PROPERTY INCLUDE_DIRECTORIES "${LEMON_ExpParser_INCLUDE_DIR}")
endif(SC_GENERATE_LP_SOURCES)
if(SC_GENERATE_LP_SOURCES)
add_custom_command(TARGET express POST_BUILD
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/express_verify.cmake
)
else(SC_GENERATE_LP_SOURCES)
add_dependencies(express express_verify)
endif(SC_GENERATE_LP_SOURCES)
if(NOT SC_IS_SUBBUILD)
add_dependencies(express version_string)
endif(NOT SC_IS_SUBBUILD)
SC_ADDEXEC("check-express" "${CHECK_EXPRESS_SOURCES}" "express;base" ${SC_EXEC_NOINSTALL})
if(SC_ENABLE_TESTING)
add_subdirectory(test)

View file

@ -1,24 +1,25 @@
This directory contains pre-generated outputs from
the Perplex/RE2C/Lemon toolchain. Their purpose
is to allow SCL to build on platforms that do not
have those tools installed, when users/developers
do not need to alter the lexing and parsing logic.
This directory contains pre-generated outputs from the Perplex/RE2C/Lemon
toolchain. Their purpose is to allow SC to build on platforms that do
not have those tools installed, when users/developers do not need to alter the
lexing and parsing logic.
DO NOT EDIT THESE FILES. They are machine generated
and should not be modified directly - bugs in these
files need to be fixed in either the Perplex/RE2C/Lemon
input files or the tools themselves. Directly changing
DO NOT EDIT THESE FILES. They are machine generated and should not be modified
directly - bugs in these files need to be fixed in either the
Perplex/RE2C/Lemon input files or the tools themselves. Directly changing
these files will result in a build failure.
If changes need to be made, the correct approach is to
install Perplex, RE2C, and Lemon and make changes in the
input files and/or tools. As long as the toolchain in place
is the same as that used previously when generating these
files, the contents of this directory will be kept in sync
automatically. In the case of updates to the tools, use the
express_sync_generated_files build target to force an
update.
If changes need to be made, the correct approach is:
The verification_info.cmake file in this directory is
used by CMake to protect the integrity of the generated
files.
1. install Perplex, RE2C, and Lemon
2. make any necessary fixes to the input files and/or the generator tools.
3. run the build, and copy the new generated expscan and expparse c and h
files to this directory.
4. run the build target "express_md5gen" to generate a new verification_info.cmake
file, and copy that file into this directory as well.
The verification_info.cmake file in this directory is used by CMake to protect
the integrity of the generated files.
If iterative debugging is necessary, set the cmake configure variable
DEBUGGING_GENERATED_SOURCES to avoid having to update generated sources and md5
sums each time an input file is changed.

View file

@ -1,9 +1,4 @@
# Autogenerated verification information
set(baseline_lemon_version "1.0")
set(baseline_re2c_version "001305")
set(baseline_perplex_version "1.0.0")
set(baseline_lempar_c_md5 fbf6255b88d54cf284c833da0d9ee5d2)
set(baseline_perplex_template_c_md5 85d44c3f626d898c5e988626b7e6d35d)
set(baseline_expscan_l_md5 c86358d3e57ce6916c28a63262fad6e6)
set(baseline_expparse_y_md5 91c889ef1f177533bcc581a735273b5e)
set(baseline_expscan_c_md5 b6b239869e4c7d169107fe45f760ffa0)