Hi,

the attached patch adds support for the CTEST_INITIAL_CACHE variable when 
using new-style ctest commands.
Now ctest_configure() checks the CTEST_INITIAL_CACHE variable and if it is not 
empty, AND there is no CMakeCache.txt yet, it writes the initial 
CMakeCache.txt
I had a look at the code of the old-style ctest script, it seems there any 
existing CMakeCache.txt is overwritten if CTEST_INITIAL_CACHE is set. Is this 
correct ? Is this behaviour also wanted for the new-style commands ?
I think it is not necessary, because if I want to have a fresh cmake run, I 
can use ctest_empty_binary_directory() before, then I will also get the 
initial cache again.

What do you think ?
Ok to commit ?

Alex
Index: CTest/cmCTestConfigureCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestConfigureCommand.cxx,v
retrieving revision 1.11
diff -b -u -p -r1.11 cmCTestConfigureCommand.cxx
--- CTest/cmCTestConfigureCommand.cxx	11 Jul 2006 19:58:07 -0000	1.11
+++ CTest/cmCTestConfigureCommand.cxx	13 Nov 2008 00:20:26 -0000
@@ -3,7 +3,7 @@
   Program:   CMake - Cross-Platform Makefile Generator
   Module:    $RCSfile: cmCTestConfigureCommand.cxx,v $
   Language:  C++
-  Date:      $Date: 2006-07-11 19:58:07 $
+  Date:      $Date: 2006/07/11 19:58:07 $
   Version:   $Revision: 1.11 $
 
   Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
@@ -53,6 +53,14 @@ cmCTestGenericHandler* cmCTestConfigureC
     return 0;
     }
 
+  const char* ctestInitialCache
+    = this->Makefile->GetDefinition("CTEST_INITIAL_CACHE");
+  if ( ctestInitialCache && *ctestInitialCache )
+    {
+    this->CTest->SetCTestConfiguration("InitialCache",
+      ctestInitialCache);
+    }
+
   const char* ctestConfigureCommand
     = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
   if ( ctestConfigureCommand && *ctestConfigureCommand )
Index: CTest/cmCTestConfigureHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestConfigureHandler.cxx,v
retrieving revision 1.14
diff -b -u -p -r1.14 cmCTestConfigureHandler.cxx
--- CTest/cmCTestConfigureHandler.cxx	30 Jan 2008 16:17:36 -0000	1.14
+++ CTest/cmCTestConfigureHandler.cxx	13 Nov 2008 00:20:26 -0000
@@ -3,7 +3,7 @@
   Program:   CMake - Cross-Platform Makefile Generator
   Module:    $RCSfile: cmCTestConfigureHandler.cxx,v $
   Language:  C++
-  Date:      $Date: 2008-01-30 16:17:36 $
+  Date:      $Date: 2008/01/30 16:17:36 $
   Version:   $Revision: 1.14 $
 
   Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
@@ -18,6 +18,7 @@
 #include "cmCTestConfigureHandler.h"
 
 #include "cmCTest.h"
+#include "cmCTestScriptHandler.h"
 #include "cmGeneratedFileStream.h"
 #include "cmake.h"
 #include <cmsys/Process.h>
@@ -79,6 +80,28 @@ int cmCTestConfigureHandler::ProcessHand
 
     cmGeneratedFileStream ofs;
     this->StartLogFile("Configure", ofs);
+
+  // write the initial cache if
+  // * CTEST_INITIAL_CACHE was set and
+  // * CMakeCache.txt doesn't exist yet
+  std::string initialCache
+    = this->CTest->GetCTestConfiguration("InitialCache");
+  if (initialCache.size() != 0)
+    {
+    if (!cmSystemTools::FileExists((buildDirectory+"/CMakeCache.txt").c_str()))
+      {
+      cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, 
+                 "Creating initial CMakeCache.txt" << std::endl);
+      if (!cmCTestScriptHandler::WriteInitialCache(buildDirectory.c_str(), 
+                                                   initialCache.c_str()))
+        {
+        cmCTestLog(this->CTest, ERROR_MESSAGE,
+                   "Cannot write initial CMakeCache.txt" << std::endl);
+        return -1;
+        }
+      }
+    }
+
     cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: "
       << cCommand.c_str() << std::endl);
     res = this->CTest->RunMakeCommand(cCommand.c_str(), &output,
Index: CTest/cmCTestScriptHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestScriptHandler.cxx,v
retrieving revision 1.44
diff -b -u -p -r1.44 cmCTestScriptHandler.cxx
--- CTest/cmCTestScriptHandler.cxx	7 Nov 2008 20:56:54 -0000	1.44
+++ CTest/cmCTestScriptHandler.cxx	13 Nov 2008 00:20:26 -0000
@@ -117,7 +117,7 @@ void cmCTestScriptHandler::Initialize()
   this->CTestCmd = "";
   this->UpdateCmd = "";
   this->CTestEnv = "";
-  this->InitCache = "";
+  this->InitialCache = "";
   this->CMakeCmd = "";
   this->CMOutFile = "";
   this->ExtraUpdates.clear();
@@ -443,7 +443,7 @@ int cmCTestScriptHandler::ExtractVariabl
     }
   this->CTestEnv
     = this->Makefile->GetSafeDefinition("CTEST_ENVIRONMENT");
-  this->InitCache
+  this->InitialCache
     = this->Makefile->GetSafeDefinition("CTEST_INITIAL_CACHE");
   this->CMakeCmd
     = this->Makefile->GetSafeDefinition("CTEST_CMAKE_COMMAND");
@@ -834,24 +834,14 @@ int cmCTestScriptHandler::RunConfigurati
     }
 
   // put the initial cache into the bin dir
-  if (!this->InitCache.empty())
+  if (!this->InitialCache.empty())
     {
-    std::string cacheFile = this->BinaryDir;
-    cacheFile += "/CMakeCache.txt";
-    cmGeneratedFileStream fout(cacheFile.c_str());
-    if(!fout)
+    if (!this->WriteInitialCache(this->BinaryDir.c_str(), 
+         this->InitialCache.c_str()))
       {
       this->RestoreBackupDirectories();
       return 9;
       }
-
-    fout.write(this->InitCache.c_str(), this->InitCache.size());
-
-    // Make sure the operating system has finished writing the file
-    // before closing it.  This will ensure the file is finished before
-    // the check below.
-    fout.flush();
-    fout.close();
     }
 
   // do an initial cmake to setup the DartConfig file
@@ -950,6 +940,30 @@ int cmCTestScriptHandler::RunConfigurati
   return 0;
 }
 
+//-------------------------------------------------------------------------
+bool cmCTestScriptHandler::WriteInitialCache(const char* directory, 
+                                             const char* text)
+{
+  std::string cacheFile = directory;
+  cacheFile += "/CMakeCache.txt";
+  cmGeneratedFileStream fout(cacheFile.c_str());
+  if(!fout)
+    {
+    return false;
+    }
+
+  if (text!=0)
+    {
+    fout.write(text, strlen(text));
+    }
+
+  // Make sure the operating system has finished writing the file
+  // before closing it.  This will ensure the file is finished before
+  // the check below.
+  fout.flush();
+  fout.close();
+  return true;
+}
 
 //-------------------------------------------------------------------------
 void cmCTestScriptHandler::RestoreBackupDirectories()
Index: CTest/cmCTestScriptHandler.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestScriptHandler.h,v
retrieving revision 1.19
diff -b -u -p -r1.19 cmCTestScriptHandler.h
--- CTest/cmCTestScriptHandler.h	8 Jun 2007 20:06:33 -0000	1.19
+++ CTest/cmCTestScriptHandler.h	13 Nov 2008 00:20:26 -0000
@@ -3,7 +3,7 @@
   Program:   CMake - Cross-Platform Makefile Generator
   Module:    $RCSfile: cmCTestScriptHandler.h,v $
   Language:  C++
-  Date:      $Date: 2007-06-08 20:06:33 $
+  Date:      $Date: 2007/06/08 20:06:33 $
   Version:   $Revision: 1.19 $
 
   Copyright (c) 2002 Kitware, Inc. All rights reserved.
@@ -91,6 +91,11 @@ public:
   static bool EmptyBinaryDirectory(const char *dir);
 
   /*
+   * Write an initial CMakeCache.txt from the given contents.
+   */
+  static bool WriteInitialCache(const char* directory, const char* text);
+
+  /*
    * Some elapsed time handling functions
    */
   static void SleepInSeconds(unsigned int secondsToWait);
@@ -151,7 +156,7 @@ private:
   cmStdString CTestCmd;
   cmStdString UpdateCmd;
   cmStdString CTestEnv;
-  cmStdString InitCache;
+  cmStdString InitialCache;
   cmStdString CMakeCmd;
   cmStdString CMOutFile;
   std::vector<cmStdString> ExtraUpdates;
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to