[Piglit] [PATCH 2/4] Refactor cmake script to generate tests for later reuse.
Paul Berry
stereotype441 at gmail.com
Mon Aug 8 14:15:05 PDT 2011
This patch creates a function, piglit_make_generated_tests (in
generated_tests/CMakeLists.txt), to encapsulate the logic that runs a
python script to determine dependencies and builds a custom command.
The new function can be reused to generate tests using other python
scripts.
---
generated_tests/CMakeLists.txt | 64 +++++++++++++++++++++++++++------------
1 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index 79e2a01..6772813 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -1,24 +1,48 @@
-# Execute gen_builtin_uniform_tests.py once during configure to find
-# out what files it generates.
-set(gen_builtin_uniform
- ${CMAKE_CURRENT_SOURCE_DIR}/gen_builtin_uniform_tests.py)
-execute_process(
- COMMAND python ${gen_builtin_uniform} --names-only
- OUTPUT_VARIABLE builtin_uniform_tests
- RESULT_VARIABLE builtin_uniform_tests_result)
-if(NOT builtin_uniform_tests_result EQUAL 0)
- message(FATAL_ERROR "gen_builtin_uniform_tests.py failed")
-endif(NOT builtin_uniform_tests_result EQUAL 0)
-string(REPLACE "\n" ";" builtin_uniform_tests ${builtin_uniform_tests})
+# Create a custom command that runs the Python script
+# ${generator_script} to generate tests. The script is also run at
+# configure tyme, with the "--names-only" option, to find out what
+# files will be generated.
+#
+# Also create a custom target ${custom_target} which can be used to
+# run the custom command.
+#
+# The custom command will automatically depend on ${generator_script}.
+# Additional dependencies can be supplied using additional arguments.
+function(piglit_make_generated_tests custom_target generator_script)
-# Add a custom command which executes gen_builtin_uniform_tests.py
-# during the build.
-add_custom_command(OUTPUT ${builtin_uniform_tests}
- COMMAND python ${gen_builtin_uniform}
- DEPENDS gen_builtin_uniform_tests.py builtin_function.py
- VERBATIM)
+ # Execute ${generator_script} once during configure to find
+ # out what files it generates.
+ execute_process(
+ COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${generator_script}
+ --names-only
+ OUTPUT_VARIABLE tests_to_generate
+ RESULT_VARIABLE generator_script_result)
+ if(NOT(generator_script_result EQUAL 0))
+ message(FATAL_ERROR "${generator_script} failed")
+ endif(NOT(generator_script_result EQUAL 0))
+ string(REPLACE "\n" ";" tests_to_generate ${tests_to_generate})
-# And add a "gen-tests" target that can be used to generate all the
+ # Add a custom command which executes ${generator_script}
+ # during the build.
+ add_custom_command(OUTPUT ${tests_to_generate}
+ COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/${generator_script}
+ DEPENDS ${generator_script} ${ARGN}
+ VERBATIM)
+
+ # And add a target named ${custom_target} that can be used to run the
+ # custom command.
+ add_custom_target(${custom_target} ALL
+ DEPENDS ${tests_to_generate})
+
+endfunction(piglit_make_generated_tests custom_target generator_script)
+
+# Create custom commands and targets to build generated tests.
+piglit_make_generated_tests(
+ gen-builtin-uniform-tests
+ gen_builtin_uniform_tests.py
+ builtin_function.py)
+
+# Add a "gen-tests" target that can be used to generate all the
# tests without doing any other compilation.
add_custom_target(gen-tests ALL
- DEPENDS ${builtin_uniform_tests})
+ DEPENDS gen-builtin-uniform-tests)
--
1.7.6
More information about the Piglit
mailing list