[pcre-dev] [PATCH] RunTest.bat, pcre_test.bat and CMake

Etusivu
Poista viesti
Lähettäjä: Daniel Richard G
Päiväys:  
Vastaanottaja: pcre-dev
Aihe: [pcre-dev] [PATCH] RunTest.bat, pcre_test.bat and CMake
I was building PCRE on Windows, but the pcre_test_bat test was not working
for me. There were a few issues with how RunTest.bat is invoked via CMake,
and how the batch file makes use of quoting; the attached patch addresses
these:

++ CMakeLists.txt

* Added quoting to "When testing is complete..." message for better
clarity when PROJECT_BINARY_DIR contains spaces

* MESSAGE("") does not print a blank line, but MESSAGE(" ") does

* Reworked the generation of pcre_test.txt (now pcre_test.bat) to handle
path quoting correctly (Windows convention is to use quoting only with
literal path values, not with variable dereferences), and use
%CMAKE_CONFIG_TYPE% to play well with IDEs that build different
configurations of pcretest.exe

* Got rid of BatDriver.cmake, as the extra indirection should no longer be
needed

++ RunTest.bat

* Fixed quoting


I proofed this using Visual Studio IDE and NMake-makefile CMake
generators, with spaces in both the source and binary directory paths.


--Daniel


--
Daniel Richard G. || danielg@??? || Software Developer
Teragram Linguistic Technologies (a division of SAS)
http://www.teragram.com/Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt    (revision 1052)
+++ CMakeLists.txt    (working copy)
@@ -682,8 +682,8 @@
   FILE(WRITE ${PROJECT_BINARY_DIR}/CTestCustom.ctest
   "# This is a generated file.
 MESSAGE(\"When testing is complete, review test output in the
-${PROJECT_BINARY_DIR}/Testing/Temporary folder.\")
-MESSAGE(\"\")
+\\\"${PROJECT_BINARY_DIR}/Testing/Temporary\\\" folder.\")
+MESSAGE(\" \")
 ")
 
   FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_test.sh
@@ -719,37 +719,24 @@
 
   IF(WIN32)
     # Provide environment for executing the bat file version of RunTest
-    string(REPLACE "/" "\\" winsrc "${PROJECT_SOURCE_DIR}")
+    FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} winsrc)
+    FILE(TO_NATIVE_PATH ${PROJECT_BINARY_DIR} winbin)
+    FILE(TO_NATIVE_PATH ${PCRETEST_EXE} winexe)
 
-    FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_test.txt
+    FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_test.bat
     "\@REM This is a generated file.
-\@Echo off
+\@echo off
 setlocal
-SET\ srcdir=\${srcdir}
-SET\ pcretest=\${pcretest}
-call \"\${srcdir}\\RunTest.Bat\"
+SET srcdir=\"${winsrc}\"
+SET pcretest=\"${winexe}\"
+if not [%CMAKE_CONFIG_TYPE%]==[] SET pcretest=\"${winbin}\\%CMAKE_CONFIG_TYPE%\\pcretest.exe\"
+call %srcdir%\\RunTest.Bat
 if errorlevel 1 exit /b 1
 echo RunTest.bat tests successfully completed
 ")
 
-  FILE(WRITE ${PROJECT_BINARY_DIR}/BatDriver.cmake
-  "# This is a generated file.
-# this script is run with arguments via the cmake command in add_test(NAME pcre_test_bat)
-# BatDriver feeds the actual location of pcretest.exe
-FILE(TO_NATIVE_PATH \${pcretestx} pcretest)
-FILE(TO_NATIVE_PATH \${srcdirx} srcdir)
-configure_file(\"\${bindirx}/pcre_test.txt\" \"\${bindirx}/pcre_test.bat\")
-# MESSAGE(\"cmake\ variable\ pcretest\ is\ \${pcretest}\")
-# STRING(REPLACE \" \" \"\\ \" bindir \${bindirx})
-MESSAGE(\"COMMAND pcre_test.bat \")
-EXECUTE_PROCESS(COMMAND pcre_test.bat
-WORKING_DIRECTORY .
-OUTPUT_VARIABLE batoutput)
-MESSAGE(\"OUTPUT: \${batoutput}\")
-")
-
   ADD_TEST(NAME pcre_test_bat
-  COMMAND ${CMAKE_COMMAND} -D bindirx=${PROJECT_BINARY_DIR} -D srcdirx=${PROJECT_SOURCE_DIR} -D pcretestx=$<TARGET_FILE:pcretest> -P "${PROJECT_BINARY_DIR}/BatDriver.cmake")
+  COMMAND pcre_test.bat)
   SET_TESTS_PROPERTIES(pcre_test_bat PROPERTIES
   PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed")
 
Index: RunTest.bat
===================================================================
--- RunTest.bat    (revision 1052)
+++ RunTest.bat    (working copy)
@@ -27,36 +27,36 @@
 if exist ..\testdata\ set srcdir=..)
 if [%srcdir%]==[] (
 if exist ..\..\testdata\ set srcdir=..\..)
-if NOT exist "%srcdir%\testdata\" (
+if NOT exist %srcdir%\testdata\ (
 Error: echo distribution testdata folder not found!
 call :conferror
 exit /b 1
 goto :eof
 )
 
-if "%pcretest%"=="" set pcretest=.\pcretest.exe
+if [%pcretest%]==[] set pcretest=.\pcretest.exe
 
 echo source dir is %srcdir%
 echo pcretest=%pcretest%
 
-if NOT exist "%pcretest%" (
-echo Error: "%pcretest%" not found!
+if NOT exist %pcretest% (
+echo Error: %pcretest% not found!
 echo.
 call :conferror
 exit /b 1
 )
 
-"%pcretest%" -C linksize >NUL
+%pcretest% -C linksize >NUL
 set link_size=%ERRORLEVEL%
-"%pcretest%" -C pcre8 >NUL
+%pcretest% -C pcre8 >NUL
 set support8=%ERRORLEVEL%
-"%pcretest%" -C pcre16 >NUL
+%pcretest% -C pcre16 >NUL
 set support16=%ERRORLEVEL%
-"%pcretest%" -C utf >NUL
+%pcretest% -C utf >NUL
 set utf=%ERRORLEVEL%
-"%pcretest%" -C ucp >NUL
+%pcretest% -C ucp >NUL
 set ucp=%ERRORLEVEL%
-"%pcretest%" -C jit >NUL
+%pcretest% -C jit >NUL
 set jit=%ERRORLEVEL%
 
 if %support8% EQU 1 (
@@ -216,21 +216,21 @@
 )
 
 echo Test %1: %3
-"%pcretest%" %mode% %4 %5 %6 %7 %8 %9 "%srcdir%\testdata\%testinput%">%2%bits%\%testoutput%
+%pcretest% %mode% %4 %5 %6 %7 %8 %9 %srcdir%\testdata\%testinput% >%2%bits%\%testoutput%
 if errorlevel 1 (
   echo.          failed executing command-line:
-  echo.            "%pcretest%" %mode% %4 %5 %6 %7 %8 %9 "%srcdir%\testdata\%testinput%"^>%2%bits%\%testoutput%
+  echo.            %pcretest% %mode% %4 %5 %6 %7 %8 %9 %srcdir%\testdata\%testinput% ^>%2%bits%\%testoutput%
   set failed="yes"
   goto :eof
 )
 
 if [%1]==[11] (
-  fc /n "%srcdir%\testdata\%testoutput%-%bits%" "%2%bits%\%testoutput%">NUL
+  fc /n %srcdir%\testdata\%testoutput%-%bits% %2%bits%\%testoutput% >NUL
 ) else (
-  fc /n "%srcdir%\testdata\%testoutput%" "%2%bits%\%testoutput%">NUL
+  fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput% >NUL
 )
 if errorlevel 1 (
-  echo.          failed comparison: fc /n "%srcdir%\testdata\%testoutput%" "%2%bits%\%testoutput%"
+  echo.          failed comparison: fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput%
   if [%1]==[2] (
     echo.
     echo ** Test 2 requires a lot of stack. PCRE can be configured to
@@ -370,7 +370,7 @@
   echo Test 14 Skipped when running 16-bit tests.
   goto :eof
 )
-  copy /Y "%srcdir%\testdata\saved16" testsaved16
+  copy /Y %srcdir%\testdata\saved16 testsaved16
   call :runsub 14 testout "Specials for the basic 8-bit library" -q
   call :runsub 14 testoutstudy "Test with Study Override" -q -s
   if %jit% EQU 1 call :runsub 14 testoutjit "Test with JIT Override" -q -s+
@@ -409,9 +409,9 @@
   echo Test 17 Skipped when running 8-bit tests.
   goto :eof
 )
-  copy /Y "%srcdir%\testdata\saved8" testsaved8
-  copy /Y "%srcdir%\testdata\saved16LE-1" testsaved16LE-1
-  copy /Y "%srcdir%\testdata\saved16BE-1" testsaved16BE-1
+  copy /Y %srcdir%\testdata\saved8 testsaved8
+  copy /Y %srcdir%\testdata\saved16LE-1 testsaved16LE-1
+  copy /Y %srcdir%\testdata\saved16BE-1 testsaved16BE-1
   call :runsub 17 testout "Specials for the basic 8-bit library" -q
   call :runsub 17 testoutstudy "Test with Study Override" -q -s
   if %jit% EQU 1 call :runsub 17 testoutjit "Test with JIT Override" -q -s+
@@ -426,8 +426,8 @@
   echo Test 18 Skipped due to absence of UTF-8 support.
   goto :eof
 )
-  copy /Y "%srcdir%\testdata\saved16LE-2" testsaved16LE-2
-  copy /Y "%srcdir%\testdata\saved16BE-2" testsaved16BE-2
+  copy /Y %srcdir%\testdata\saved16LE-2 testsaved16LE-2
+  copy /Y %srcdir%\testdata\saved16BE-2 testsaved16BE-2
   call :runsub 18 testout "Specials for the basic 8-bit library" -q
   call :runsub 18 testoutstudy "Test with Study Override" -q -s
   if %jit% EQU 1 call :runsub 18 testoutjit "Test with JIT Override" -q -s+