Browse Source

Merge topic 'execute_process-encoding'

3898e53e82 execute_process: Document and test ENCODING default
d67519fce8 Help/command/execute_process: Improve formatting of ENCODING names
e1fc4b9b17 Tests/RunCMake/execute_process: Add test for ENCODING AUTO
56ae758bc5 Tests/RunCMake/execute_process: Improve test for ENCODING UTF-8

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9816
Brad King 1 year ago
parent
commit
c76a5458ac

+ 15 - 5
Help/command/execute_process.rst

@@ -140,20 +140,30 @@ Options:
  ``NONE``
  ``NONE``
    Perform no decoding.  This assumes that the process output is encoded
    Perform no decoding.  This assumes that the process output is encoded
    in the same way as CMake's internal encoding (UTF-8).
    in the same way as CMake's internal encoding (UTF-8).
-   This is the default.
+
+   This was the default in CMake 3.14 and older.
+
  ``AUTO``
  ``AUTO``
    Use the current active console's codepage or if that isn't
    Use the current active console's codepage or if that isn't
    available then use ANSI.
    available then use ANSI.
+
+   This is the default since CMake 3.15.
+
  ``ANSI``
  ``ANSI``
    Use the ANSI codepage.
    Use the ANSI codepage.
+
  ``OEM``
  ``OEM``
    Use the original equipment manufacturer (OEM) code page.
    Use the original equipment manufacturer (OEM) code page.
- ``UTF8`` or ``UTF-8``
-   Use the UTF-8 codepage.
 
 
+ ``UTF-8``
    .. versionadded:: 3.11
    .. versionadded:: 3.11
-     Accept ``UTF-8`` spelling for consistency with the
-     `UTF-8 RFC <https://www.ietf.org/rfc/rfc3629>`_ naming convention.
+
+   Use the UTF-8 codepage.
+
+ ``UTF8``
+   Use the UTF-8 codepage.  Use of this name is discouraged in favor
+   of ``UTF-8`` to match the `UTF-8 RFC <https://www.ietf.org/rfc/rfc3629>`_
+   naming convention.
 
 
 ``COMMAND_ERROR_IS_FATAL <ANY|LAST>``
 ``COMMAND_ERROR_IS_FATAL <ANY|LAST>``
   .. versionadded:: 3.19
   .. versionadded:: 3.19

+ 11 - 0
Tests/RunCMake/execute_process/Encoding-common.cmake

@@ -0,0 +1,11 @@
+if(ENCODING)
+  set(maybe_ENCODING ENCODING ${ENCODING})
+else()
+  set(maybe_ENCODING "")
+  set(ENCODING AUTO) # execute_process's default ENCODING
+endif()
+execute_process(
+  COMMAND ${TEST_ENCODING_EXE} ${ENCODING} ${CMAKE_CURRENT_LIST_DIR}/Encoding${ENCODING}-stderr.txt
+  OUTPUT_VARIABLE out
+  ${maybe_ENCODING}
+  )

+ 7 - 0
Tests/RunCMake/execute_process/Encoding-windows.cmake

@@ -0,0 +1,7 @@
+# Set the console code page.
+execute_process(COMMAND cmd /c chcp ${CODEPAGE})
+
+include(${CMAKE_CURRENT_LIST_DIR}/Encoding-common.cmake)
+
+# Save our internal UTF-8 representation of the output.
+file(WRITE "out.txt" "${out}")

+ 13 - 5
Tests/RunCMake/execute_process/Encoding.cmake

@@ -1,6 +1,14 @@
-execute_process(
-  COMMAND ${TEST_ENCODING_EXE} ${TEST_ENCODING} ${CMAKE_CURRENT_LIST_DIR}/EncodingUTF8-stderr.txt
-  OUTPUT_VARIABLE out
-  ENCODING ${TEST_ENCODING}
-  )
+if(CMAKE_HOST_WIN32 AND CODEPAGE)
+  # Run cmake in a new Window to isolate its console code page.
+  execute_process(COMMAND cmd /c start /min /wait ""
+    ${CMAKE_COMMAND} -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE}
+                     -DENCODING=${ENCODING}
+                     -DCODEPAGE=${CODEPAGE}
+                     -P ${CMAKE_CURRENT_LIST_DIR}/Encoding-windows.cmake)
+
+  # Load our internal UTF-8 representation of the output.
+  file(READ "out.txt" out)
+else()
+  include(${CMAKE_CURRENT_LIST_DIR}/Encoding-common.cmake)
+endif()
 message("${out}")
 message("${out}")

+ 2 - 0
Tests/RunCMake/execute_process/EncodingAUTO-stderr.txt

@@ -0,0 +1,2 @@
+Chinese
+注意

+ 3 - 0
Tests/RunCMake/execute_process/EncodingAUTO.cmake

@@ -0,0 +1,3 @@
+set(ENCODING AUTO)
+set(CODEPAGE 54936)
+include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)

+ 2 - 0
Tests/RunCMake/execute_process/EncodingDefault-stderr.txt

@@ -0,0 +1,2 @@
+Chinese
+注意

+ 3 - 0
Tests/RunCMake/execute_process/EncodingDefault.cmake

@@ -0,0 +1,3 @@
+# No explicit ENCODING option; fall back to default.
+set(CODEPAGE 54936)
+include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)

+ 2 - 1
Tests/RunCMake/execute_process/EncodingUTF-8-stderr.txt

@@ -1 +1,2 @@
-यूनिकोड είναι very здорово!
+Chinese Hindi  Greek English Russian
+注意    यूनिकोड είναι very    здорово!

+ 2 - 0
Tests/RunCMake/execute_process/EncodingUTF-8.cmake

@@ -0,0 +1,2 @@
+set(ENCODING UTF-8)
+include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)

+ 2 - 1
Tests/RunCMake/execute_process/EncodingUTF8-stderr.txt

@@ -1 +1,2 @@
-यूनिकोड είναι very здорово!
+Chinese Hindi  Greek English Russian
+注意    यूनिकोड είναι very    здорово!

+ 2 - 0
Tests/RunCMake/execute_process/EncodingUTF8.cmake

@@ -0,0 +1,2 @@
+set(ENCODING UTF8)
+include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)

+ 4 - 2
Tests/RunCMake/execute_process/RunCMakeTest.cmake

@@ -9,8 +9,10 @@ run_cmake_command(MergeOutputVars ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/Mer
 
 
 run_cmake(EncodingMissing)
 run_cmake(EncodingMissing)
 if(TEST_ENCODING_EXE)
 if(TEST_ENCODING_EXE)
-  run_cmake_command(EncodingUTF8 ${CMAKE_COMMAND} -DTEST_ENCODING=UTF8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE} -P ${RunCMake_SOURCE_DIR}/Encoding.cmake)
-  run_cmake_command(EncodingUTF-8 ${CMAKE_COMMAND} -DTEST_ENCODING=UTF-8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE} -P ${RunCMake_SOURCE_DIR}/Encoding.cmake)
+  run_cmake_script(EncodingDefault -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE})
+  run_cmake_script(EncodingAUTO -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE})
+  run_cmake_script(EncodingUTF-8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE})
+  run_cmake_script(EncodingUTF8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE})
 endif()
 endif()
 
 
 if(EXIT_CODE_EXE)
 if(EXIT_CODE_EXE)