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 <kwrobot@kitware.com>
Merge-request: !9816
This commit is contained in:
Brad King
2024-09-16 10:25:11 +00:00
committed by Kitware Robot
13 changed files with 68 additions and 14 deletions
+15 -5
View File
@@ -140,20 +140,30 @@ Options:
``NONE``
Perform no decoding. This assumes that the process output is encoded
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``
Use the current active console's codepage or if that isn't
available then use ANSI.
This is the default since CMake 3.15.
``ANSI``
Use the ANSI codepage.
``OEM``
Use the original equipment manufacturer (OEM) code page.
``UTF8`` or ``UTF-8``
``UTF-8``
.. versionadded:: 3.11
Use the UTF-8 codepage.
.. versionadded:: 3.11
Accept ``UTF-8`` spelling for consistency with the
`UTF-8 RFC <https://www.ietf.org/rfc/rfc3629>`_ naming convention.
``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>``
.. versionadded:: 3.19
@@ -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}
)
@@ -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
View File
@@ -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}")
@@ -0,0 +1,2 @@
Chinese
注意
@@ -0,0 +1,3 @@
set(ENCODING AUTO)
set(CODEPAGE 54936)
include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)
@@ -0,0 +1,2 @@
Chinese
注意
@@ -0,0 +1,3 @@
# No explicit ENCODING option; fall back to default.
set(CODEPAGE 54936)
include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)
@@ -1 +1,2 @@
यूनिकोड είναι very здорово!
Chinese Hindi Greek English Russian
注意 यूनिकोड είναι very здорово!
@@ -0,0 +1,2 @@
set(ENCODING UTF-8)
include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)
@@ -1 +1,2 @@
यूनिकोड είναι very здорово!
Chinese Hindi Greek English Russian
注意 यूनिकोड είναι very здорово!
@@ -0,0 +1,2 @@
set(ENCODING UTF8)
include(${CMAKE_CURRENT_LIST_DIR}/Encoding.cmake)
@@ -9,8 +9,10 @@ run_cmake_command(MergeOutputVars ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/Mer
run_cmake(EncodingMissing)
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()
if(EXIT_CODE_EXE)