2012-12-12 17:23:25 +00:00
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012 Kornel Benko kornel@lyx.org
|
|
|
|
#
|
|
|
|
#
|
2013-07-23 19:42:44 +00:00
|
|
|
# LYX_ROOT = ${TOP_SRC_DIR}/lib/{doc,examples,templates}
|
2013-08-21 11:34:26 +00:00
|
|
|
# LYX_USERDIR_VER = Name of environment variable for the user directory
|
2014-01-05 09:02:29 +00:00
|
|
|
# lyx =
|
2016-08-29 16:14:37 +00:00
|
|
|
# format = lyx16x|lyx21x|lyx22x|xhtml
|
|
|
|
# extension = 16.lyx|21.lyx|22.lyx|xhtml
|
2012-12-13 11:38:38 +00:00
|
|
|
# file = xxx
|
2012-12-12 17:23:25 +00:00
|
|
|
#
|
|
|
|
# Script should be called like:
|
|
|
|
# cmake -DLYX_ROOT=xxx \
|
2013-08-25 09:41:10 +00:00
|
|
|
# -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR} \
|
2013-08-21 11:34:26 +00:00
|
|
|
# -DWORKDIR=${BUILD_DIR}/autotests/out-home \
|
|
|
|
# -DLYX_USERDIR_VER=${LYX_USERDIR_VER} \
|
2012-12-12 17:23:25 +00:00
|
|
|
# -Dlyx=xxx \
|
2012-12-13 11:38:38 +00:00
|
|
|
# -Dformat=xxx \
|
2013-12-16 10:36:36 +00:00
|
|
|
# -Dfonttype=xxx \
|
2012-12-13 11:38:38 +00:00
|
|
|
# -Dextension=xxx \
|
2015-12-28 05:00:10 +00:00
|
|
|
# -DLYX_FORMAT_NUM=${_lyx_format_num} \
|
2012-12-13 11:38:38 +00:00
|
|
|
# -Dfile=xxx \
|
2015-12-02 23:23:07 +00:00
|
|
|
# -Dinverted=[01] \
|
2016-11-09 23:56:49 +00:00
|
|
|
# -DTOP_SRC_DIR=${TOP_SRC_DIR} \
|
2017-01-11 09:15:13 +00:00
|
|
|
# -DIgnoreErrorMessage=(ON/OFF) \
|
2016-11-09 23:56:49 +00:00
|
|
|
# -DPERL_EXECUTABLE=${PERL_EXECUTABLE} \
|
|
|
|
# -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE} \
|
|
|
|
# -DENCODING=xxx \
|
2012-12-12 17:23:25 +00:00
|
|
|
# -P "${TOP_SRC_DIR}/development/autotests/export.cmake"
|
|
|
|
#
|
2012-12-11 14:17:04 +00:00
|
|
|
|
2017-04-24 15:44:31 +00:00
|
|
|
message(STATUS "IgnoreErrorMessage = \"${IgnoreErrorMessage}\"")
|
2013-11-17 22:17:27 +00:00
|
|
|
set(Perl_Script "${TOP_SRC_DIR}/development/autotests/useSystemFonts.pl")
|
2015-12-27 13:33:11 +00:00
|
|
|
set(Structure_Script "${TOP_SRC_DIR}/development/autotests/beginEndStructureCheck.pl")
|
2015-11-10 18:42:43 +00:00
|
|
|
set(LanguageFile "${TOP_SRC_DIR}/lib/languages")
|
2015-03-28 20:21:16 +00:00
|
|
|
set(GetTempDir "${TOP_SRC_DIR}/development/autotests/getTempDir.pl")
|
2013-12-16 10:36:36 +00:00
|
|
|
set(_ft ${fonttype})
|
2015-03-28 20:21:16 +00:00
|
|
|
execute_process(COMMAND ${PERL_EXECUTABLE} "${GetTempDir}" "${WORKDIR}" OUTPUT_VARIABLE TempDir)
|
2013-12-16 10:36:36 +00:00
|
|
|
message(STATUS "using fonttype = ${_ft}")
|
2016-11-09 23:56:49 +00:00
|
|
|
if(NOT ENCODING)
|
|
|
|
set(ENCODING "default")
|
|
|
|
endif()
|
|
|
|
if(ENCODING STREQUAL "default")
|
|
|
|
set(_enc)
|
|
|
|
else()
|
|
|
|
set(_enc "_${ENCODING}")
|
|
|
|
endif()
|
2015-11-29 15:11:10 +00:00
|
|
|
if(format MATCHES "dvi|pdf")
|
2013-11-17 22:17:27 +00:00
|
|
|
message(STATUS "LYX_TESTS_USERDIR = ${LYX_TESTS_USERDIR}")
|
|
|
|
message(STATUS "Converting with perl ${Perl_Script}")
|
2016-11-09 23:56:49 +00:00
|
|
|
set(LYX_SOURCE "${TempDir}/${file}_${format}_${_ft}${_enc}.lyx")
|
2013-11-17 22:17:27 +00:00
|
|
|
message(STATUS "Using source \"${LYX_ROOT}/${file}.lyx\"")
|
|
|
|
message(STATUS "Using dest \"${LYX_SOURCE}\"")
|
2016-11-09 23:56:49 +00:00
|
|
|
if(NOT "${ENCODING}" STREQUAL "default")
|
|
|
|
# message(STATUS "ENCODING = ${ENCODING}")
|
|
|
|
endif()
|
2017-11-17 16:53:52 +00:00
|
|
|
message(STATUS "Executing ${PERL_EXECUTABLE} \"${Perl_Script}\" \"${LYX_ROOT}/${file}.lyx\" \"${LYX_SOURCE}\" ${format} ${_ft} ${ENCODING} ${LanguageFile}")
|
2016-11-09 23:56:49 +00:00
|
|
|
execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} ${_ft} ${ENCODING} ${LanguageFile}
|
2013-11-17 22:17:27 +00:00
|
|
|
RESULT_VARIABLE _err)
|
|
|
|
string(COMPARE EQUAL ${_err} 0 _erg)
|
|
|
|
if(NOT _erg)
|
|
|
|
message(FATAL_ERROR "Export failed while converting")
|
|
|
|
endif()
|
2015-12-25 18:02:06 +00:00
|
|
|
set(result_file_name ${file}_${_ft}.${extension})
|
2013-11-17 22:17:27 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Not converting")
|
|
|
|
set(LYX_SOURCE "${LYX_ROOT}/${file}.lyx")
|
2015-12-28 07:37:58 +00:00
|
|
|
if(extension MATCHES "\\.lyx$")
|
|
|
|
# Font-type not relevant for lyx16/lyx21 exports
|
|
|
|
set(result_file_base ${file})
|
|
|
|
else()
|
|
|
|
set(result_file_name ${file}.${extension})
|
|
|
|
endif()
|
2013-11-17 22:17:27 +00:00
|
|
|
endif()
|
|
|
|
|
2015-12-29 12:23:08 +00:00
|
|
|
function(get_md5sum msource mresult mreserr)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E md5sum ${${msource}}
|
|
|
|
OUTPUT_VARIABLE msource_md5sum_x
|
|
|
|
RESULT_VARIABLE mres_err)
|
|
|
|
if (NOT mres_err)
|
|
|
|
string(REGEX REPLACE " .*" "" msource_md5sum ${msource_md5sum_x})
|
|
|
|
set(${mresult} ${msource_md5sum} PARENT_SCOPE)
|
|
|
|
message(STATUS "MD5SUM of \"${${msource}}\" is ${msource_md5sum}")
|
|
|
|
else()
|
|
|
|
set(${mresult} "xx" PARENT_SCOPE)
|
|
|
|
message(STATUS "Error getting MD5SUM of \"${${msource}}\"")
|
|
|
|
endif()
|
|
|
|
set(${mreserr} ${mres_err} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2013-08-25 09:41:10 +00:00
|
|
|
set(ENV{${LYX_USERDIR_VER}} "${LYX_TESTS_USERDIR}")
|
2017-10-02 08:35:57 +00:00
|
|
|
set(ENV{LANG} "en_US.UTF-8") # to get all error-messages in english
|
|
|
|
#set(ENV{LC_ALL} "C")
|
2015-12-28 05:00:10 +00:00
|
|
|
if (extension MATCHES "\\.lyx$")
|
|
|
|
include(${TOP_SRC_DIR}/development/autotests/CheckLoadErrors.cmake)
|
2015-12-29 12:23:08 +00:00
|
|
|
get_md5sum(LYX_SOURCE source_md5sum _err)
|
2018-01-22 13:43:50 +00:00
|
|
|
foreach(_lv RANGE 1 20)
|
2015-12-28 05:00:10 +00:00
|
|
|
set(result_file_base "${result_file_base}.${LYX_FORMAT_NUM}")
|
|
|
|
set(result_file_name "${result_file_base}.lyx")
|
|
|
|
file(REMOVE "${result_file_name}" "${result_file_name}.emergency" )
|
|
|
|
message(STATUS "Executing ${lyx} -userdir \"${LYX_TESTS_USERDIR}\" -E ${format} ${result_file_name} \"${LYX_SOURCE}\"")
|
2015-12-29 12:23:08 +00:00
|
|
|
message(STATUS "This implicitly checks load of ${LYX_SOURCE}")
|
2015-12-25 09:28:40 +00:00
|
|
|
execute_process(
|
2015-12-28 05:00:10 +00:00
|
|
|
COMMAND ${lyx} -userdir "${LYX_TESTS_USERDIR}" -E ${format} ${result_file_name} "${LYX_SOURCE}"
|
2015-12-25 09:28:40 +00:00
|
|
|
RESULT_VARIABLE _err
|
|
|
|
ERROR_VARIABLE lyxerr)
|
2015-12-28 05:00:10 +00:00
|
|
|
if(_err)
|
|
|
|
break()
|
2015-12-29 12:23:08 +00:00
|
|
|
elseif(NOT EXISTS "${result_file_name}")
|
|
|
|
message(STATUS "Expected result file \"${result_file_name}\" does not exist")
|
|
|
|
set(_err -1)
|
|
|
|
break()
|
2015-12-28 05:00:10 +00:00
|
|
|
else()
|
2015-12-29 12:23:08 +00:00
|
|
|
message(STATUS "Expected result file \"${result_file_name}\" exists")
|
2018-01-06 11:05:51 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${PERL_EXECUTABLE} ${Structure_Script} "${WORKDIR}/${result_file_name}"
|
|
|
|
RESULT_VARIABLE _err)
|
|
|
|
if(_err)
|
|
|
|
break()
|
|
|
|
endif()
|
2015-12-29 12:23:08 +00:00
|
|
|
checkLoadErrors(lyxerr "${TOP_SRC_DIR}/development/autotests" _err)
|
|
|
|
if(_err)
|
2015-12-28 05:00:10 +00:00
|
|
|
break()
|
2015-12-27 19:05:37 +00:00
|
|
|
endif()
|
2015-12-25 09:28:40 +00:00
|
|
|
endif()
|
2015-12-29 12:23:08 +00:00
|
|
|
get_md5sum(result_file_name result_md5sum _err)
|
2015-12-28 05:00:10 +00:00
|
|
|
if(_err)
|
2015-12-29 12:23:08 +00:00
|
|
|
# Somehow the created file is not readable?
|
2015-12-28 05:00:10 +00:00
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
# Check if result file identical to source file
|
|
|
|
if(result_md5sum STREQUAL ${source_md5sum})
|
2018-03-15 21:34:26 +00:00
|
|
|
if (format MATCHES "lyx(1[0-9]|2[01])x")
|
|
|
|
# Do not compile, missing \origin statement prevents inclusion of
|
|
|
|
# files with relative path
|
|
|
|
message(STATUS "Not exporting due to missing \\origin statement")
|
|
|
|
break()
|
|
|
|
endif()
|
2015-12-28 05:00:10 +00:00
|
|
|
message(STATUS "Source(${LYX_SOURCE}) and dest(${result_file_name}) are equal")
|
2018-03-15 21:34:26 +00:00
|
|
|
message(STATUS "Now try to export the lyx2lyx created file")
|
|
|
|
message(STATUS "Executing ${lyx} -userdir \"${LYX_TESTS_USERDIR}\" -E default \"${result_file_name}.default\" \"${result_file_name}\"")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${lyx} -userdir "${LYX_TESTS_USERDIR}" -E default "${result_file_name}.default" "${result_file_name}"
|
|
|
|
RESULT_VARIABLE _err
|
|
|
|
ERROR_VARIABLE lyxerr)
|
2015-12-28 05:00:10 +00:00
|
|
|
break()
|
2018-01-22 13:43:50 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Source(${LYX_SOURCE}) and dest(${result_file_name}) are still different")
|
|
|
|
if (_lv GREATER 10)
|
|
|
|
set(_err 1)
|
|
|
|
message(STATUS "Possible endless loop encountered")
|
|
|
|
break()
|
|
|
|
endif()
|
2015-12-28 05:00:10 +00:00
|
|
|
endif()
|
|
|
|
set(source_md5sum ${result_md5sum})
|
|
|
|
set(LYX_SOURCE ${result_file_name})
|
|
|
|
endforeach()
|
|
|
|
else()
|
2016-10-12 12:35:23 +00:00
|
|
|
if ($ENV{LYX_DEBUG_LATEX})
|
2017-01-11 09:15:13 +00:00
|
|
|
set(LyXExtraParams -dbg latex)
|
2016-10-12 12:35:23 +00:00
|
|
|
else()
|
2017-01-11 09:15:13 +00:00
|
|
|
set(LyXExtraParams)
|
2016-10-12 12:35:23 +00:00
|
|
|
endif()
|
2017-01-11 09:15:13 +00:00
|
|
|
if(IgnoreErrorMessage)
|
|
|
|
foreach (_em ${IgnoreErrorMessage})
|
|
|
|
list(APPEND LyXExtraParams --ignore-error-message ${_em})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
string(REGEX REPLACE ";" " " _LyXExtraParams "${LyXExtraParams}")
|
|
|
|
message(STATUS "Executing ${lyx} ${_LyXExtraParams} -userdir \"${LYX_TESTS_USERDIR}\" -E ${format} ${result_file_name} \"${LYX_SOURCE}\"")
|
2015-12-28 05:00:10 +00:00
|
|
|
file(REMOVE ${result_file_name})
|
|
|
|
execute_process(
|
2017-01-11 09:15:13 +00:00
|
|
|
COMMAND ${lyx} ${LyXExtraParams} -userdir "${LYX_TESTS_USERDIR}" -E ${format} ${result_file_name} "${LYX_SOURCE}"
|
2015-12-28 05:00:10 +00:00
|
|
|
RESULT_VARIABLE _err)
|
|
|
|
|
|
|
|
#check if result file created
|
|
|
|
if (NOT _err)
|
|
|
|
if (NOT EXISTS "${result_file_name}")
|
|
|
|
message(STATUS "Expected result file \"${result_file_name}\" does not exist")
|
|
|
|
set(_err -1)
|
|
|
|
else()
|
|
|
|
message(STATUS "Expected result file \"${result_file_name}\" exists")
|
2016-05-30 07:50:22 +00:00
|
|
|
if (format MATCHES "xhtml")
|
|
|
|
if (XMLLINT_EXECUTABLE)
|
2016-08-29 16:14:37 +00:00
|
|
|
message(STATUS "Calling: ${XMLLINT_EXECUTABLE} --sax --html --valid")
|
2016-05-30 07:50:22 +00:00
|
|
|
# check the created xhtml file
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${XMLLINT_EXECUTABLE} --sax --html --valid "${result_file_name}"
|
|
|
|
OUTPUT_VARIABLE xmlout
|
|
|
|
ERROR_VARIABLE xmlerr
|
|
|
|
RESULT_VARIABLE _err)
|
|
|
|
file(WRITE "${result_file_name}.sax_out" ${xmlout})
|
|
|
|
if (NOT _err)
|
|
|
|
# check if sax-parser output contains error messages
|
2016-08-29 16:14:37 +00:00
|
|
|
message(STATUS "Check the output: ${PERL_EXECUTABLE} ${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl")
|
2016-05-30 07:50:22 +00:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl" "${result_file_name}.sax_out"
|
|
|
|
OUTPUT_VARIABLE xmlout
|
|
|
|
RESULT_VARIABLE _err)
|
|
|
|
endif()
|
|
|
|
if (NOT _err)
|
|
|
|
if (NOT "${xmlout}" STREQUAL "")
|
|
|
|
message(STATUS "${xmlout}")
|
|
|
|
set(_err -1)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
2015-12-28 05:00:10 +00:00
|
|
|
endif()
|
2015-12-25 09:28:40 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-12-02 23:23:07 +00:00
|
|
|
if(inverted)
|
2013-08-04 12:31:47 +00:00
|
|
|
string(COMPARE EQUAL ${_err} 0 _erg)
|
|
|
|
else()
|
|
|
|
string(COMPARE NOTEQUAL ${_err} 0 _erg)
|
|
|
|
endif()
|
2015-03-28 20:21:16 +00:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${TempDir}")
|
2013-01-21 01:36:42 +00:00
|
|
|
if(_erg)
|
2015-12-25 09:28:40 +00:00
|
|
|
message(STATUS "Exporting ${file}.lyx to ${format}")
|
2012-12-13 11:38:38 +00:00
|
|
|
message(FATAL_ERROR "Export failed")
|
|
|
|
endif()
|