Sfoglia il codice sorgente

added enable testing deprecated some commands

Ken Martin 24 anni fa
parent
commit
37801ddaae

+ 39 - 4
Source/cmAddTestCommand.cxx

@@ -48,22 +48,57 @@ bool cmAddTestCommand::InitialPass(std::vector<std::string>& args)
   // Second argument is the name of the executable to run (a target or external
   //    program)
   // Remaining arguments are the arguments to pass to the executable
-  
   if(args.size() < 2 )
     {
     this->SetError("called with incorrect number of arguments");
     return false;
     }
+  
+  // store the aruments for the final pass
+  std::copy(args.begin(),args.end(),m_Args.begin());
+  return true;
+}
+
+// we append to the file in the final pass because Enable Testing command
+// creates the file in the final pass.
+void cmAddTestCommand::FinalPass()
+{
 
   // Expand any CMake variables
   std::vector<std::string>::iterator s;
-  for (s = args.begin(); s != args.end(); ++s)
+  for (s = m_Args.begin(); s != m_Args.end(); ++s)
     {
     m_Makefile->ExpandVariablesInString(*s);
     }
 
-  m_Makefile->AddTest(args);
+  // Create a full path filename for output Testfile
+  std::string fname;
+  fname = m_Makefile->GetStartOutputDirectory();
+  fname += "/";
+  fname += "CMakeTestfile.txt";
   
-  return true;
+  // Open the output Testfile
+  std::ofstream fout(fname.c_str());
+  if (!fout)
+    {
+    cmSystemTools::Error("Error Writing ", fname.c_str());
+    return;
+    }
+
+  std::vector<std::string>::iterator it;
+
+  // for each arg in the test
+  fout << "ADD_TEST(";
+  it = m_Args.begin();
+  fout << (*it).c_str();
+  ++it;
+  for (; it != m_Args.end(); ++it)
+    {
+    fout << " " << (*it).c_str();
+    }
+  fout << ")" << std::endl;
+  fout.close();
+  
+  return;
 }
 

+ 9 - 0
Source/cmAddTestCommand.h

@@ -66,6 +66,12 @@ public:
    */
   virtual bool InitialPass(std::vector<std::string>& args);
 
+  /**
+   * This is called at the end after all the information
+   * specified by the command is accumulated. 
+   */
+  virtual void FinalPass();
+
   /**
    * The name of the command as specified in CMakeList.txt.
    */
@@ -94,6 +100,9 @@ public:
     }
   
   cmTypeMacro(cmAddTestCommand, cmCommand);
+
+private:
+  std::vector<std::string> m_Args;
 };
 
 

+ 2 - 0
Source/cmCommands.cxx

@@ -29,6 +29,7 @@
 #include "cmConfigureFileCommand.cxx"
 #include "cmConfigureFileNoAutoconf.cxx"
 #include "cmElseCommand.cxx"
+#include "cmEnableTestingCommand.cxx"
 #include "cmEndIfCommand.cxx"
 #include "cmExecProgramCommand.cxx"
 #include "cmFindFileCommand.cxx"
@@ -87,6 +88,7 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
   commands.push_back(new cmConfigureFileCommand);
   commands.push_back(new cmConfigureFileNoAutoconf);
   commands.push_back(new cmElseCommand);
+  commands.push_back(new cmEnableTestingCommand);  
   commands.push_back(new cmEndIfCommand);
   commands.push_back(new cmExecProgramCommand);
   commands.push_back(new cmFindFileCommand);

+ 2 - 8
Source/cmConfigureFileNoAutoconf.cxx

@@ -43,14 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // cmConfigureFileNoAutoconf
 bool cmConfigureFileNoAutoconf::InitialPass(std::vector<std::string>& args)
 {
-  if(args.size() != 2 )
-    {
-    this->SetError("called with incorrect number of arguments, expected 2");
-    return false;
-    }
-  m_InputFile = args[0];
-  m_OuputFile = args[1];
-  return true;
+  this->SetError("The CONFIGURE_FILE_NO_AUTOCONF method is deprecated, please use CONFIGURE_FILE instead.");
+  return false;
 }
 
 void cmConfigureFileNoAutoconf::FinalPass()

+ 96 - 0
Source/cmEnableTestingCommand.cxx

@@ -0,0 +1,96 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+Copyright (c) 2001 Insight Consortium
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+ * The name of the Insight Consortium, nor the names of any consortium members,
+   nor of any contributors, may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+  * Modified source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=========================================================================*/
+#include "cmEnableTestingCommand.h"
+#include "cmCacheManager.h"
+
+// we do this in the final pass so that we now the subdirs have all 
+// been defined
+void cmEnableTestingCommand::FinalPass()
+{
+  // Create a full path filename for output Testfile
+  std::string fname;
+  fname = m_Makefile->GetStartOutputDirectory();
+  fname += "/";
+  fname += "CMakeTestfile.txt";
+  
+  // Open the output Testfile
+  std::ofstream fout(fname.c_str());
+  if (!fout)
+    {
+    cmSystemTools::Error("Error Writing ", fname.c_str());
+    return;
+    }
+  
+  fout << "# CMake generated Testfile for " << std::endl
+       << "#\tSource directory: "
+       << m_Makefile->GetStartDirectory()
+       << std::endl
+       << "#\tBuild directory: " << m_Makefile->GetStartOutputDirectory()
+       << std::endl
+       << "# " << std::endl
+       << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
+       << std::endl
+       << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
+       << std::endl
+       << "# that are excluded by CMake control structures, i.e. IF() commands."
+       << std::endl
+       << "#" 
+       << std::endl << std::endl;
+
+  // write out the subdirs for the current directory
+  if (!m_Makefile->GetSubDirectories().empty())
+    {
+    fout << "SUBDIRS(";
+    const std::vector<std::string>& subdirs = m_Makefile->GetSubDirectories();
+    std::vector<std::string>::const_iterator i = subdirs.begin();
+    fout << (*i).c_str();
+    ++i;
+    for(; i != subdirs.end(); ++i)
+      {
+      fout << " " << (*i).c_str();
+      }
+    fout << ")" << std::endl << std::endl;;
+    }
+  fout.close();  
+
+  return;
+}
+

+ 117 - 0
Source/cmEnableTestingCommand.h

@@ -0,0 +1,117 @@
+/*=========================================================================
+
+  Program:   Insight Segmentation & Registration Toolkit
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+Copyright (c) 2001 Insight Consortium
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+ * The name of the Insight Consortium, nor the names of any consortium members,
+   nor of any contributors, may be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+  * Modified source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=========================================================================*/
+#ifndef cmEnableTestingCommand_h
+#define cmEnableTestingCommand_h
+
+#include "cmStandardIncludes.h"
+#include "cmCommand.h"
+
+/** \class cmEnableTestingCommand
+ * \brief Enable testing for this directory and below.
+ *
+ * Produce the output testfile. This produces a file in the build directory
+ * called CMakeTestfile with a syntax similar to CMakeLists.txt.  It contains
+ * the SUBDIRS() and ADD_TEST() commands from the source CMakeLists.txt
+ * file with CMake variables expanded.  Only the subdirs and tests
+ * within the valid control structures are replicated in Testfile
+ * (i.e. SUBDIRS() and ADD_TEST() commands within IF() commands that are
+ * not entered by CMake are not replicated in Testfile).
+ */
+class cmEnableTestingCommand : public cmCommand
+{
+public:
+  /**
+   * This is a virtual constructor for the command.
+   */
+  virtual cmCommand* Clone() 
+    {
+    return new cmEnableTestingCommand;
+    }
+
+  /**
+   * This determines if the command gets propagated down
+   * to makefiles located in subdirectories.
+   */
+  virtual bool IsInherited() {return true;}
+
+  /**
+   * This is called when the command is first encountered in
+   * the CMakeLists.txt file.
+   */
+  virtual bool InitialPass(std::vector<std::string>& args) {
+    return true;};
+
+  /**
+   * This is called at the end after all the information
+   * specified by the command is accumulated. Most commands do
+   * not implement this method.  At this point, reading and
+   * writing to the cache can be done.
+   */
+  virtual void FinalPass();
+
+  /**
+   * The name of the command as specified in CMakeList.txt.
+   */
+  virtual const char* GetName() { return "ENABLE_TESTING";}
+
+  /**
+   * Succinct documentation.
+   */
+  virtual const char* GetTerseDocumentation() 
+    {
+    return "Enable testing for this directory and below.";
+    }
+  
+  /**
+   * More documentation.
+   */
+  virtual const char* GetFullDocumentation()
+    {
+    return
+      "ENABLE_TESTING()\n"
+      "Enables testing for this directory and below. See also the ADD_TEST command.";
+    }
+  
+  cmTypeMacro(cmEnableTestingCommand, cmCommand);
+};
+
+
+#endif

+ 0 - 86
Source/cmMakefile.cxx

@@ -383,89 +383,8 @@ void cmMakefile::GenerateMakefile()
     }
   // now do the generation
   m_MakefileGenerator->GenerateMakefile();
-
-  // generate any testing files
-  this->GenerateTestfile();
 }
 
-void cmMakefile::GenerateTestfile()
-{
-  if (m_Tests.empty() && this->GetSubDirectories().empty())
-    {
-    return;
-    }
-
-  // Create a full path filename for output Testfile
-  std::string fname;
-  fname = this->GetCurrentOutputDirectory();
-  fname += "/";
-  fname += "CMakeTestfile.txt";
-
-  // Open the output Testfile
-  std::ofstream fout(fname.c_str());
-  if (!fout)
-    {
-    cmSystemTools::Error("Error Writing ", fname.c_str());
-    return;
-    }
-  
-  fout << "# CMake generated Testfile for " << std::endl
-            << "#\tSource directory: "
-            << this->GetCurrentDirectory()
-            << std::endl
-            << "#\tBuild directory: " << this->GetCurrentOutputDirectory()
-            << std::endl
-            << "# " << std::endl
-            << "# This file replicates the SUBDIRS() and ADD_TEST() commands from the source"
-            << std::endl
-            << "# tree CMakeLists.txt file, skipping any SUBDIRS() or ADD_TEST() commands"
-            << std::endl
-            << "# that are excluded by CMake control structures, i.e. IF() commands."
-            << std::endl
-            << "#" 
-            << std::endl << std::endl;
-
-  // write out the subdirs for the current directory
-  if (!this->GetSubDirectories().empty())
-    {
-    fout << "SUBDIRS(";
-    const std::vector<std::string>& subdirs = this->GetSubDirectories();
-    std::vector<std::string>::const_iterator i = subdirs.begin();
-    fout << (*i).c_str();
-    ++i;
-    for(; i != subdirs.end(); ++i)
-      {
-      fout << " " << (*i).c_str();
-      }
-    fout << ")" << std::endl << std::endl;;
-    }
-
-  
-  // write out each test
-  std::vector<std::vector<std::string> >::iterator testIt;
-  std::vector<std::string>::iterator it;
-
-  // for each test
-  for (testIt = m_Tests.begin(); testIt != m_Tests.end(); ++testIt)
-    {
-    if (!(*testIt).empty())
-      {
-      // for each arg in the test
-      fout << "ADD_TEST(";
-      it = (*testIt).begin();
-      fout << (*it).c_str();
-      ++it;
-      for (; it != (*testIt).end(); ++it)
-        {
-        fout << " " << (*it).c_str();
-        }
-      fout << ")" << std::endl;
-      }
-    }
-
-  fout << std::endl;
-  fout.close();
-}
 
 void cmMakefile::AddSource(cmSourceFile& cmfile, const char *srclist)
 {
@@ -571,11 +490,6 @@ void cmMakefile::AddDefinition(const char* name, bool value)
     }
 }
 
-void cmMakefile::AddTest(const std::vector<std::string> &args)
-{
-  m_Tests.push_back(args);
-}
-
 void cmMakefile::SetProjectName(const char* p)
 {
   m_ProjectName = p;

+ 0 - 17
Source/cmMakefile.h

@@ -111,17 +111,6 @@ public:
    */
   void GenerateMakefile();
 
-  /**
-   * Produce the output testfile. This produces a file in the build directory
-   * called Testfile with a syntax similar to CMakeLists.txt.  It contains
-   * the SUBDIRS() and ADD_TEST() commands from the source CMakeLists.txt
-   * file with CMake variables expanded.  Only the subdirs and tests
-   * within the valid control structures are replicated in Testfile
-   * (i.e. SUBDIRS() and ADD_TEST() commands within IF() commands that are
-   * not entered by CMake are not replicated in Testfile).
-   */
-  void GenerateTestfile();
-  
   /**
    * Print the object state to std::cout.
    */
@@ -222,11 +211,6 @@ public:
    */
   void AddDefinition(const char* name, bool);
 
-  /**
-   * Add a test to the build.
-   */
-  void AddTest(const std::vector<std::string> &args);
-
   /**
    * Specify the name of the project for this build.
    */
@@ -526,7 +510,6 @@ protected:
   std::vector<std::string> m_Utilities;
   std::vector<std::string> m_UtilityDirectories;
   std::vector<std::string> m_ListFiles; // list of command files loaded
-  std::vector<std::vector<std::string> > m_Tests; // list of tests and args
   
   
   cmTarget::LinkLibraries m_LinkLibraries;

+ 1 - 0
Source/cmTestsCommand.cxx

@@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 bool cmTestsCommand::InitialPass(std::vector<std::string>& args)
 {
   // does nothing in CMake
+  this->SetError("The TEST command is deprecated, please use ADD_TEST instead.");  
   return true;
 }