Directly call python when executing expander.py

On Unix-based systems, you can directly execute a script and the system
will automatically run it through its associated interpreter. However,
on Windows this does not work. You just get an error about the script,
which is just a text file, being an invalid executable.

This was an issue when running pyexpander. Now, Python is called
directly for pyexpander.
This commit is contained in:
Kenneth Moreland 2016-06-16 10:36:20 -06:00
parent 42cc4a0c10
commit 0581a83aa2
4 changed files with 22 additions and 7 deletions

5
CMake/FindPyexpander.cmake Normal file → Executable file

@ -28,6 +28,11 @@
# PYEXPANDER_FOUND - True if pyexpander is found
# PYEXPANDER_COMMAND - The pyexpander executable
#
# Note that on some platforms (such as Windows), you cannot execute a python
# script directly. Thus, it could be safer to execute the Python interpreter
# with PYEXPANDER_COMMAND as an argument. See FindPythonInterp.cmake for help
# in finding the Python interpreter.
#
find_program(PYEXPANDER_COMMAND expander.py)

17
CMake/VTKmCheckPyexpander.cmake Normal file → Executable file

@ -23,9 +23,14 @@
# 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.
# To use this script, the CMake variables PYTHON_EXECUTABLE 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 PYTHON_EXECUTABLE)
message(SEND_ERROR "Variable PYTHON_EXECUTABLE must be set.")
return()
endif()
if(NOT PYEXPANDER_COMMAND)
message(SEND_ERROR "Variable PYEXPANDER_COMMAND must be set.")
@ -43,14 +48,14 @@ if(NOT GENERATED_FILE)
endif()
execute_process(
COMMAND ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in
COMMAND ${PYTHON_EXECUTABLE} ${PYEXPANDER_COMMAND} ${SOURCE_FILE}.in
RESULT_VARIABLE pyexpander_result
OUTPUT_VARIABLE pyexpander_output
)
if(${pyexpander_result})
if(pyexpander_result)
# If pyexpander returned non-zero, it failed.
message(SEND_ERROR "Running pyexpander failed.")
message(SEND_ERROR "Running pyexpander failed (${pyexpander_result}).")
return()
endif()

3
CMake/VTKmMacros.cmake Normal file → Executable file

@ -198,10 +198,11 @@ 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)
if(PYEXPANDER_FOUND AND PYTHONINTERP_FOUND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}.checked
COMMAND ${CMAKE_COMMAND}
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DPYEXPANDER_COMMAND=${PYEXPANDER_COMMAND}
-DSOURCE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${generated_file_name}
-DGENERATED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${generated_file_name}

4
CMakeLists.txt Normal file → Executable file

@ -207,6 +207,10 @@ if(UNIX AND VTKm_ENABLE_OPENGL_INTEROP)
find_package(Threads REQUIRED)
endif()
#-----------------------------------------------------------------------------
# Find the Python interpreter, which we will use during the build process
find_package(PythonInterp)
#-----------------------------------------------------------------------------
# Find Pyexpander in case somebody wants to update the auto generated
# faux variadic template code