[Cmake-commits] CMake branch, next, updated. v3.0.0-rc4-2575-g042e42a

Stephen Kelly steveire at gmail.com
Sat Apr 26 08:26:12 EDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  042e42a388062d8d121902b9834928266a4c6c2f (commit)
       via  1b5d016df8e7e3138be7664d12a0a21fe439e4a5 (commit)
      from  c67496e058b5664da062e85522c3571252ba5025 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=042e42a388062d8d121902b9834928266a4c6c2f
commit 042e42a388062d8d121902b9834928266a4c6c2f
Merge: c67496e 1b5d016
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Apr 26 08:26:11 2014 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sat Apr 26 08:26:11 2014 -0400

    Merge topic 'file-generate-if-different' into next
    
    1b5d016d file(GENERATE): Only write the file if content is different.


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1b5d016df8e7e3138be7664d12a0a21fe439e4a5
commit 1b5d016df8e7e3138be7664d12a0a21fe439e4a5
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Fri Apr 25 20:11:05 2014 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sat Apr 26 14:25:58 2014 +0200

    file(GENERATE): Only write the file if content is different.
    
    Introduce policy CMP0053 to control this behavior.

diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 4b895fe..136cf5c 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -104,3 +104,4 @@ All Policies
    /policy/CMP0050
    /policy/CMP0051
    /policy/CMP0052
+   /policy/CMP0053
diff --git a/Help/policy/CMP0053.rst b/Help/policy/CMP0053.rst
new file mode 100644
index 0000000..cd7fa54
--- /dev/null
+++ b/Help/policy/CMP0053.rst
@@ -0,0 +1,17 @@
+CMP0053
+-------
+
+Always write the output of file(GENERATE).
+
+CMake 3.0 and lower always writes the output file specified in a
+:command:`file(GENERATE)` command, even if the content is unchanged.
+
+The OLD behavior for this policy is for the :command:`file(GENERATE)`
+command to always write the to the output file.  The NEW behavior for
+this policy is to write the output file only if the content to be written
+is different.
+
+This policy was introduced in CMake version 3.1.
+CMake version |release| warns when the policy is not set and uses
+``OLD`` behavior.  Use the :command:`cmake_policy` command to set it
+to ``OLD`` or ``NEW`` explicitly.
diff --git a/Help/release/dev/file-GENERATE-CMP0053.rst b/Help/release/dev/file-GENERATE-CMP0053.rst
new file mode 100644
index 0000000..991a0f5
--- /dev/null
+++ b/Help/release/dev/file-GENERATE-CMP0053.rst
@@ -0,0 +1,7 @@
+
+file-GENERATE-CMP0053
+---------------------
+
+* The :command:`file(GENERATE)` command changed behavior to write the
+  output file only when content is changed.  Policy :policy:`CMP0053` was
+  introduced to control the behavior.
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 5bfb664..92fe3c6 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -3265,7 +3265,8 @@ cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
 void cmFileCommand::AddEvaluationFile(const std::string &inputName,
                                       const std::string &outputExpr,
                                       const std::string &condition,
-                                      bool inputIsContent
+                                      bool inputIsContent,
+                                      bool writeAlways
                                      )
 {
   cmListFileBacktrace lfbt;
@@ -3284,7 +3285,8 @@ void cmFileCommand::AddEvaluationFile(const std::string &inputName,
                                                           outputCge,
                                                           this->Makefile,
                                                           conditionCge,
-                                                          inputIsContent);
+                                                          inputIsContent,
+                                                          writeAlways);
 }
 
 //----------------------------------------------------------------------------
@@ -3301,6 +3303,23 @@ bool cmFileCommand::HandleGenerateCommand(
     this->SetError("Incorrect arguments to GENERATE subcommand.");
     return false;
     }
+  bool writeAlways = false;
+
+  switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0053))
+    {
+    case cmPolicies::WARN:
+      this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+            this->Makefile->GetPolicies()->
+              GetPolicyWarning(cmPolicies::CMP0053));
+    case cmPolicies::OLD:
+      writeAlways = true;
+      break;
+    case cmPolicies::NEW:
+    case cmPolicies::REQUIRED_ALWAYS:
+    case cmPolicies::REQUIRED_IF_USED:
+      break;
+    }
+
   std::string condition;
   if (args.size() > 5)
     {
@@ -3331,7 +3350,8 @@ bool cmFileCommand::HandleGenerateCommand(
     }
   std::string input = args[4];
 
-  this->AddEvaluationFile(input, output, condition, inputIsContent);
+  this->AddEvaluationFile(input, output, condition,
+                          inputIsContent, writeAlways);
   return true;
 }
 
diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h
index 8d66fdf..12fa699 100644
--- a/Source/cmFileCommand.h
+++ b/Source/cmFileCommand.h
@@ -80,7 +80,8 @@ private:
   void AddEvaluationFile(const std::string &inputName,
                          const std::string &outputExpr,
                          const std::string &condition,
-                         bool inputIsContent);
+                         bool inputIsContent,
+                         bool writeAlways);
 };
 
 
diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx
index 95a946a..61c4ded 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.cxx
+++ b/Source/cmGeneratorExpressionEvaluationFile.cxx
@@ -23,12 +23,14 @@ cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile(
         cmsys::auto_ptr<cmCompiledGeneratorExpression> outputFileExpr,
         cmMakefile *makefile,
         cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
-        bool inputIsContent)
+        bool inputIsContent,
+        bool writeAlways)
   : Input(input),
     OutputFileExpr(outputFileExpr),
     Makefile(makefile),
     Condition(condition),
-    InputIsContent(inputIsContent)
+    InputIsContent(inputIsContent),
+    WriteAlways(writeAlways)
 {
 }
 
@@ -79,12 +81,16 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
   this->Files.push_back(outputFileName);
   outputFiles[outputFileName] = outputContent;
 
-  cmsys::ofstream fout(outputFileName.c_str());
+  std::string outputTempFileName = this->Makefile->GetCurrentOutputDirectory();
+  outputTempFileName += "/CMakeFiles/evaluation_file.tmp";
+
+  cmsys::ofstream fout(outputTempFileName.c_str());
 
   if(!fout)
     {
     cmOStringStream e;
-    e << "Evaluation file \"" << outputFileName << "\" cannot be written.";
+    e << "Evaluation file \"" << outputFileName << "\" cannot be written to "
+         "temporary location \"" << outputTempFileName << "\".";
     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
     return;
     }
@@ -92,6 +98,11 @@ void cmGeneratorExpressionEvaluationFile::Generate(const std::string& config,
   fout << outputContent;
 
   fout.close();
+
+  cmSystemTools::CopyAFile(outputTempFileName.c_str(),
+                           outputFileName.c_str(), this->WriteAlways);
+
+  cmSystemTools::RemoveFile(outputTempFileName.c_str());
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h
index f939916..cffc18b 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.h
+++ b/Source/cmGeneratorExpressionEvaluationFile.h
@@ -25,7 +25,8 @@ public:
         cmsys::auto_ptr<cmCompiledGeneratorExpression> outputFileExpr,
         cmMakefile *makefile,
         cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
-        bool inputIsContent);
+        bool inputIsContent,
+        bool writeAlways);
 
   void Generate();
 
@@ -43,6 +44,7 @@ private:
   const cmsys::auto_ptr<cmCompiledGeneratorExpression> Condition;
   std::vector<std::string> Files;
   const bool InputIsContent;
+  const bool WriteAlways;
 };
 
 #endif
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index f09f7b3..4314932 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -2959,12 +2959,14 @@ void cmGlobalGenerator::AddEvaluationFile(const std::string &inputFile,
                     cmsys::auto_ptr<cmCompiledGeneratorExpression> outputExpr,
                     cmMakefile *makefile,
                     cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
-                    bool inputIsContent)
+                    bool inputIsContent,
+                    bool writeAlways)
 {
   this->EvaluationFiles.push_back(
               new cmGeneratorExpressionEvaluationFile(inputFile, outputExpr,
                                                       makefile, condition,
-                                                      inputIsContent));
+                                                      inputIsContent,
+                                                      writeAlways));
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 82fb1e5..43a88e4 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -309,7 +309,8 @@ public:
                   cmsys::auto_ptr<cmCompiledGeneratorExpression> outputName,
                   cmMakefile *makefile,
                   cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
-                  bool inputIsContent);
+                  bool inputIsContent,
+                  bool writeAlways);
 
   void ProcessEvaluationFiles();
 
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 309f280..5a7700c 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -354,6 +354,11 @@ cmPolicies::cmPolicies()
     "Reject source and build dirs in installed "
     "INTERFACE_INCLUDE_DIRECTORIES.",
     3,1,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0053, "CMP0053",
+    "Always write the output of file(GENERATE).",
+    3,1,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 60f35c2..f735a67 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -107,6 +107,7 @@ public:
     CMP0051, ///< List TARGET_OBJECTS in SOURCES target property
     CMP0052, ///< Reject source and build dirs in installed
     /// INTERFACE_INCLUDE_DIRECTORIES
+    CMP0053, ///< Always write the output of file(GENERATE).
 
     /** \brief Always the last entry.
      *
diff --git a/Tests/FindPackageModeMakefileTest/CMakeLists.txt b/Tests/FindPackageModeMakefileTest/CMakeLists.txt
index 8e21c32..b7c65b4 100644
--- a/Tests/FindPackageModeMakefileTest/CMakeLists.txt
+++ b/Tests/FindPackageModeMakefileTest/CMakeLists.txt
@@ -20,6 +20,9 @@ if(UNIX  AND  "${CMAKE_GENERATOR}" MATCHES "Makefile")
 
     # now set up the test:
     if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
+      if (POLICY CMP0053)
+        cmake_policy(SET CMP0053 NEW)
+      endif()
       file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cmakeExecutable.mk"
         CONTENT "CMAKE = \"$<TARGET_FILE:cmake>\"\n"
       )
diff --git a/Tests/RunCMake/File_Generate/CMP0053-NEW-result.txt b/Tests/RunCMake/File_Generate/CMP0053-NEW-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-NEW-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/File_Generate/CMP0053-NEW-stderr.txt b/Tests/RunCMake/File_Generate/CMP0053-NEW-stderr.txt
new file mode 100644
index 0000000..10f3293
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-NEW-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/File_Generate/CMP0053-NEW.cmake b/Tests/RunCMake/File_Generate/CMP0053-NEW.cmake
new file mode 100644
index 0000000..fc6e8ca
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-NEW.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0053 NEW)
+
+file(GENERATE
+  OUTPUT output_file.txt
+  CONTENT "123"
+)
diff --git a/Tests/RunCMake/File_Generate/CMP0053-OLD-result.txt b/Tests/RunCMake/File_Generate/CMP0053-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/File_Generate/CMP0053-OLD-stderr.txt b/Tests/RunCMake/File_Generate/CMP0053-OLD-stderr.txt
new file mode 100644
index 0000000..10f3293
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/File_Generate/CMP0053-OLD.cmake b/Tests/RunCMake/File_Generate/CMP0053-OLD.cmake
new file mode 100644
index 0000000..3b4acde
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-OLD.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0053 OLD)
+
+file(GENERATE
+  OUTPUT output_file.txt
+  CONTENT "123"
+)
diff --git a/Tests/RunCMake/File_Generate/CMP0053-WARN-result.txt b/Tests/RunCMake/File_Generate/CMP0053-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/File_Generate/CMP0053-WARN-stderr.txt b/Tests/RunCMake/File_Generate/CMP0053-WARN-stderr.txt
new file mode 100644
index 0000000..e895bad
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-WARN-stderr.txt
@@ -0,0 +1,7 @@
+CMake Warning \(dev\) at CMP0053-WARN.cmake:2 \(file\):
+  Policy CMP0053 is not set: Always write the output of file\(GENERATE\).  Run
+  "cmake --help-policy CMP0053" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/File_Generate/CMP0053-WARN.cmake b/Tests/RunCMake/File_Generate/CMP0053-WARN.cmake
new file mode 100644
index 0000000..d1d832a
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/CMP0053-WARN.cmake
@@ -0,0 +1,5 @@
+
+file(GENERATE
+  OUTPUT output_file.txt
+  CONTENT "123"
+)
diff --git a/Tests/RunCMake/File_Generate/CMakeLists.txt b/Tests/RunCMake/File_Generate/CMakeLists.txt
index 12cd3c7..8f85fbf 100644
--- a/Tests/RunCMake/File_Generate/CMakeLists.txt
+++ b/Tests/RunCMake/File_Generate/CMakeLists.txt
@@ -1,3 +1,3 @@
 cmake_minimum_required(VERSION 2.8.4)
 project(${RunCMake_TEST} NONE)
-include(${RunCMake_TEST}.cmake)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
index f07431c..c055af4 100644
--- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
@@ -8,3 +8,48 @@ run_cmake(EmptyCondition1)
 run_cmake(EmptyCondition2)
 run_cmake(BadCondition)
 run_cmake(DebugEvaluate)
+
+set(timeformat "%Y%j%H%M%S")
+
+macro(prepare_CMP0053_test policyStatus)
+  file(REMOVE "${RunCMake_BINARY_DIR}/CMP0053-${policyStatus}-build/output_file.txt")
+  set(RunCMake_TEST_FILE "${RunCMake_SOURCE_DIR}/CMP0053-${policyStatus}")
+  set(RunCMake_TEST_BINARY_DIR "CMP0053-${policyStatus}-build")
+  run_cmake(CMP0053-${policyStatus}-prepare)
+  unset(RunCMake_TEST_FILE)
+  unset(RunCMake_TEST_BINARY_DIR)
+  file(TIMESTAMP "${RunCMake_BINARY_DIR}/CMP0053-${policyStatus}-build/output_file.txt" timestamp_${policyStatus} ${timeformat})
+  if(NOT timestamp_${policyStatus})
+    message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/CMP0053-${policyStatus}-build/output_file.txt\"")
+  endif()
+endmacro()
+
+prepare_CMP0053_test(OLD)
+prepare_CMP0053_test(NEW)
+prepare_CMP0053_test(WARN)
+
+execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
+
+macro(run_CMP0053_test policyStatus)
+  run_cmake(CMP0053-${policyStatus})
+  file(TIMESTAMP "${RunCMake_BINARY_DIR}/CMP0053-${policyStatus}-build/output_file.txt" timestamp_${policyStatus}_after ${timeformat})
+  if(NOT timestamp_${policyStatus}_after)
+    message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/CMP0053-${policyStatus}-build/output_file.txt\"")
+  endif()
+endmacro()
+
+set(RunCMake_TEST_NO_CLEAN ON)
+run_CMP0053_test(OLD)
+run_CMP0053_test(NEW)
+run_CMP0053_test(WARN)
+unset(RunCMake_TEST_NO_CLEAN)
+
+if (timestamp_OLD_after STREQUAL timestamp_OLD)
+  message(SEND_ERROR "CMP0053 OLD behavior did not change output file.")
+endif()
+if (NOT timestamp_NEW_after STREQUAL timestamp_NEW)
+  message(SEND_ERROR "CMP0053 NEW behavior changed output file. Before: ${timestamp_NEW}, After: ${timestamp_NEW_after}")
+endif()
+if (timestamp_WARN_after STREQUAL timestamp_WARN)
+  message(SEND_ERROR "CMP0053 WARN behavior did not change output file.")
+endif()

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list