If pyexpander is available, run it and check the source file.

Although we cannot expect every developer to have pyexpander, for those
that do the build will automatically run it and check the expanded file
in the source code. If they match, a descriptive error is given.

We don't automatically update the file because subtle problems might
occur. It is better to alert a developer to fix the problem properly.
This commit is contained in:
Kenneth Moreland 2014-06-26 18:26:45 -06:00
parent 5fb7f63829
commit adad702652
5 changed files with 133 additions and 0 deletions

@ -0,0 +1,37 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014. Los Alamos National Security
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
#
# - Finds the pyexpander macro tool.
# Use this module by invoking find_package.
#
# This module finds the expander.py command distributed with pyexpander.
# pyexpander can be downloaded from http://pyexpander.sourceforge.net.
# The following variables are defined:
#
# PYEXPANDER_FOUND - True if pyexpander is found
# PYEXPANDER_COMMAND - The pyexpander executable
#
find_program(PYEXPANDER_COMMAND expander.py)
mark_as_advanced(PYEXPANDER_COMMAND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Pyexpander DEFAULT_MSG PYEXPANDER_COMMAND)

@ -0,0 +1,71 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014. Los Alamos National Security
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
# This script, which is run as part of a target, uses pyexpander to do
# macro substitution on an input file and checks the result with the
# version stored in the source code. If the versions are different, an
# error message is printed with further instructions.
#
# To use this script, the CMake variables PYEXPANDER_COMMAND, SOURCE_FILE,
# and GENERATED_FILE must be defined as the two files to compare. A ".in"
# is appended to SOURCE_FILE to get the pyexpander input.
if(NOT PYEXPANDER_COMMAND)
message(SEND_ERROR "Variable PYEXPANDER_COMMAND must be set.")
return()
endif()
if(NOT SOURCE_FILE)
message(SEND_ERROR "Variable SOURCE_FILE must be set.")
return()
endif()
if(NOT GENERATED_FILE)
message(SEND_ERROR "Variable GENERATED_FILE must be set.")
return()
endif()
execute_process(
COMMAND ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in
RESULT_VARIABLE pyexpander_result
OUTPUT_VARIABLE pyexpander_output
)
if(${pyexpander_result})
# If pyexpander returned non-zero, it failed.
message(SEND_ERROR "Running pyexpander failed.")
return()
endif()
file(WRITE ${GENERATED_FILE} "${pyexpander_output}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${SOURCE_FILE} ${GENERATED_FILE}
RESULT_VARIABLE diff_result
)
if(${diff_result})
# If diff returned non-zero, it failed and the two files are different.
file(REMOVE ${GENERATED_FILE})
get_filename_component(filename ${SOURCE_FILE} NAME)
message(SEND_ERROR
"The source file ${filename} does not match the generated file. If you have modified this file directly, then you have messed up. Modify the ${filename}.in file instead and then copy the pyexpander result to ${filename}. If you modified ${filename}.in, then you might just need to copy the pyresult back to the source directory. If you have not modifed either, then you have likely checked out an inappropriate change. Check the git logs to see what changes were made.
If the changes have resulted from modifying ${filename}.in, then you can finish by copying ${GENERATED_FILE} to ${SOURCE_FILE}.")
endif()

@ -131,6 +131,26 @@ function(vtkm_declare_worklets)
vtkm_declare_headers(${ARGN})
endfunction(vtkm_declare_worklets)
function(vtkm_pyexpander_generated_file generated_file_name)
# If pyexpander is available, add targets to build and check
if(PYEXPANDER_FOUND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
COMMAND ${CMAKE_COMMAND}
-DPYEXPANDER_COMMAND=${PYEXPANDER_COMMAND}
-DSOURCE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}
-DGENERATED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
-P ${CMAKE_SOURCE_DIR}/CMake/VTKmCheckPyexpander.cmake
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}.in
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}
)
add_custom_target(check_${generated_file_name} ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}
COMMENT "Checking validity of ${generated_file_name}"
)
endif()
endfunction(vtkm_pyexpander_generated_file)
# Declare unit tests, which should be in the same directory as a kit
# (package, module, whatever you call it). Usage:
#

@ -122,6 +122,8 @@ vtkm_install_headers(
# * Meta programming language
find_package(BoostHeaders ${VTKm_REQUIRED_BOOST_VERSION} REQUIRED)
find_package(Pyexpander)
#-----------------------------------------------------------------------------
# Add subdirectories
add_subdirectory(vtkm)

@ -29,5 +29,8 @@ set(headers
vtkm_declare_headers(${headers})
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPre.h)
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPost.h)
add_subdirectory(testing)