Explorar el Código

Merge topic 'configure_file-unicode'

98383f80 Unicode: check encoding of files given to configure_file.
Brad King hace 11 años
padre
commit
565213c1fd

+ 14 - 0
Source/cmMakefile.cxx

@@ -3526,6 +3526,20 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
       return 0;
       }
 
+    cmsys::FStream::BOM bom = cmsys::FStream::ReadBOM(fin);
+    if(bom != cmsys::FStream::BOM_None &&
+       bom != cmsys::FStream::BOM_UTF8)
+      {
+      cmOStringStream e;
+      e << "File starts with a Byte-Order-Mark that is not UTF-8:\n  "
+        << sinfile;
+      this->IssueMessage(cmake::FATAL_ERROR, e.str());
+      return 0;
+      }
+    // rewind to copy BOM to output file
+    fin.seekg(0);
+
+
     // now copy input to output and expand variables in the
     // input file at the same time
     std::string inLine;

+ 1 - 0
Tests/RunCMake/CMakeLists.txt

@@ -96,6 +96,7 @@ add_RunCMake_test(TargetPolicies)
 add_RunCMake_test(alias_targets)
 add_RunCMake_test(interface_library)
 add_RunCMake_test(no_install_prefix)
+add_RunCMake_test(configure_file)
 
 find_package(Qt4 QUIET)
 find_package(Qt5Core QUIET)

+ 3 - 0
Tests/RunCMake/configure_file/CMakeLists.txt

@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.0)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)

+ 2 - 0
Tests/RunCMake/configure_file/NO-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(NO-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/NO-BOM.txt)

+ 1 - 0
Tests/RunCMake/configure_file/NO-BOM.txt.in

@@ -0,0 +1 @@
+Hello World

+ 8 - 0
Tests/RunCMake/configure_file/RunCMakeTest.cmake

@@ -0,0 +1,8 @@
+include(RunCMake)
+
+run_cmake(NO-BOM)
+run_cmake(UTF8-BOM)
+run_cmake(UTF16LE-BOM)
+run_cmake(UTF16BE-BOM)
+run_cmake(UTF32LE-BOM)
+run_cmake(UTF32BE-BOM)

+ 1 - 0
Tests/RunCMake/configure_file/UTF16BE-BOM-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/configure_file/UTF16BE-BOM-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at UTF16BE-BOM.cmake:2 \(configure_file\):
+  File starts with a Byte-Order-Mark that is not UTF-8:
+
+    .*/Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/configure_file/UTF16BE-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(UTF16BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16BE-BOM.txt)

BIN
Tests/RunCMake/configure_file/UTF16BE-BOM.txt.in


+ 1 - 0
Tests/RunCMake/configure_file/UTF16LE-BOM-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/configure_file/UTF16LE-BOM-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at UTF16LE-BOM.cmake:2 \(configure_file\):
+  File starts with a Byte-Order-Mark that is not UTF-8:
+
+    .*/Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/configure_file/UTF16LE-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(UTF16LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF16LE-BOM.txt)

BIN
Tests/RunCMake/configure_file/UTF16LE-BOM.txt.in


+ 1 - 0
Tests/RunCMake/configure_file/UTF32BE-BOM-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/configure_file/UTF32BE-BOM-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at UTF32BE-BOM.cmake:2 \(configure_file\):
+  File starts with a Byte-Order-Mark that is not UTF-8:
+
+    .*/Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/configure_file/UTF32BE-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(UTF32BE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32BE-BOM.txt)

BIN
Tests/RunCMake/configure_file/UTF32BE-BOM.txt.in


+ 1 - 0
Tests/RunCMake/configure_file/UTF32LE-BOM-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/configure_file/UTF32LE-BOM-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at UTF32LE-BOM.cmake:2 \(configure_file\):
+  File starts with a Byte-Order-Mark that is not UTF-8:
+
+    .*/Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 2 - 0
Tests/RunCMake/configure_file/UTF32LE-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(UTF32LE-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF32LE-BOM.txt)

BIN
Tests/RunCMake/configure_file/UTF32LE-BOM.txt.in


+ 2 - 0
Tests/RunCMake/configure_file/UTF8-BOM.cmake

@@ -0,0 +1,2 @@
+
+configure_file(UTF8-BOM.txt.in ${CMAKE_CURRENT_BINARY_DIR}/UTF8-BOM.txt)

+ 1 - 0
Tests/RunCMake/configure_file/UTF8-BOM.txt.in

@@ -0,0 +1 @@
+Hello World

+ 1 - 0
bootstrap

@@ -329,6 +329,7 @@ fi
 KWSYS_CXX_SOURCES="\
   Directory \
   EncodingCXX \
+  FStream \
   Glob \
   RegularExpression \
   SystemTools"