diff --git a/CMakeLists.txt b/CMakeLists.txt index 370f611d4..c05a7fbc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,7 +292,7 @@ if(GENERATE_DOC) configure_file(${SOURCE_DIR}/docs/ldoc.ltp ${BUILD_DIR}/docs COPYONLY) add_custom_target(ldoc ALL - DEPENDS ${BUILD_DIR}/doc/index.html + DEPENDS ${BUILD_DIR}/doc/index.html DOC_EXAMPLES_PPOSTPROCESS_CLEANUP ) if (STRICT_TESTS) diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt index 2a63c4c43..8fe46ffc3 100644 --- a/tests/examples/CMakeLists.txt +++ b/tests/examples/CMakeLists.txt @@ -309,7 +309,6 @@ function(run_test test_path namespace escaped_content) DEPENDS ${TARGET_NAME}_RAW "${TOP_SOURCE_DIR}/tests/examples/_postprocess.lua" ) - if(NOT ${OUTPUT_RAW_IMAGE_PATH} STREQUAL "") file(RELATIVE_PATH rel_output "${TOP_SOURCE_DIR}" "${OUTPUT_RAW_IMAGE_PATH}") if(tmp_content MATCHES "--DOC_GEN_OUTPUT") @@ -382,4 +381,11 @@ endforeach() add_custom_target(generate-examples DEPENDS ${EXAMPLE_DOC_GENERATED_FILES}) add_custom_target(check-examples DEPENDS ${EXAMPLE_DOC_TEST_TARGETS}) +# Some tests produce multiple files, find them and post-process them. +add_custom_target(DOC_EXAMPLES_PPOSTPROCESS_CLEANUP + COMMAND "${TOP_SOURCE_DIR}/tests/examples/_postprocess_cleanup.lua" ${RAW_IMAGE_DIR} ${IMAGE_DIR} "${TOP_SOURCE_DIR}/tests/examples/_postprocess.lua" + VERBATIM + DEPENDS ${BUILD_DIR}/doc/index.html +) + # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80:foldmethod=marker diff --git a/tests/examples/_postprocess.lua b/tests/examples/_postprocess.lua index 7ba00829b..363cc054a 100755 --- a/tests/examples/_postprocess.lua +++ b/tests/examples/_postprocess.lua @@ -23,9 +23,8 @@ local i, o = io.open(input, "r"), io.open(output, "w") if (not i) or (not o) then return end -local line, count = i:read("*line"), 0 - -local add_link = false +local line = i:read("*line") +local count while line do -- Deduplicate and concatenate the classes. diff --git a/tests/examples/_postprocess_cleanup.lua b/tests/examples/_postprocess_cleanup.lua new file mode 100755 index 000000000..90a2fae71 --- /dev/null +++ b/tests/examples/_postprocess_cleanup.lua @@ -0,0 +1,45 @@ +#!/usr/bin/env lua +-- This script locate and post process all "dangling" files CMake +-- didn't track. This allows the `tests/examples/` file to save more +-- than one output artifact. + +pcall(require, "luarocks.loader") + +local gio = require("lgi").Gio + +local name_attr = gio.FILE_ATTRIBUTE_STANDARD_NAME +local type_attr = gio.FILE_ATTRIBUTE_STANDARD_TYPE + +local raw_path, processed_path, script_path = ... + +local function list_svg(path) + local ret = {} + + local enumerator = gio.File.new_for_path(path):enumerate_children( + table.concat({name_attr, type_attr}, ",") , 0, nil, nil + ) + + for file in function() return enumerator:next_file() end do + local file_name = file:get_attribute_as_string(name_attr) + local file_type = file:get_file_type() + local match_ext = file_name:match("[.]svg$") + + if file_type == "REGULAR" and match_ext then + ret[file_name] = true + end + end + + return ret +end + +local raw_files, processed_files = list_svg(raw_path), list_svg(processed_path) + +for file in pairs(raw_files) do + if not processed_files[file] then + os.execute(table.concat({ + script_path, + raw_path .. "/" .. file, + processed_path .. "/" .. file + }, " ")) + end +end