[Cmake-commits] [cmake-commits] king committed CMakeLists.txt 1.412 1.413 cmAddTestCommand.cxx 1.29 1.30 cmLocalGenerator.cxx 1.297 1.298 cmMakefile.cxx 1.505 1.506 cmMakefile.h 1.253 1.254 cmTestGenerator.cxx NONE 1.1 cmTestGenerator.h NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Mar 16 10:40:48 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv28617/Source

Modified Files:
	CMakeLists.txt cmAddTestCommand.cxx cmLocalGenerator.cxx 
	cmMakefile.cxx cmMakefile.h 
Added Files:
	cmTestGenerator.cxx cmTestGenerator.h 
Log Message:
ENH: Refactor generation of CTestTestfile content

This moves code which generates ADD_TEST and SET_TESTS_PROPERTIES calls
into CTestTestfile.cmake files out of cmLocalGenerator and into a
cmTestGenerator class.  This will allow more advanced generation without
cluttering cmLocalGenerator.  The cmTestGenerator class derives from
cmScriptGenerator to get support for per-configuration script
generation (not yet enabled).


--- NEW FILE: cmTestGenerator.cxx ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmTestGenerator.cxx,v $
  Language:  C++
  Date:      $Date: 2009-03-16 14:40:33 $
  Version:   $Revision: 1.1 $

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "cmTestGenerator.h"

#include "cmTest.h"

//----------------------------------------------------------------------------
cmTestGenerator
::cmTestGenerator(cmTest* test,
                  std::vector<std::string> const& configurations):
  cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations),
  Test(test)
{
  this->ActionsPerConfig = false;
  this->TestGenerated = false;
}

//----------------------------------------------------------------------------
cmTestGenerator
::~cmTestGenerator()
{
}

//----------------------------------------------------------------------------
void cmTestGenerator::GenerateScriptConfigs(std::ostream& os,
                                            Indent const& indent)
{
  // First create the tests.
  this->cmScriptGenerator::GenerateScriptConfigs(os, indent);

  // Now generate the test properties.
  if(this->TestGenerated)
    {
    cmTest* test = this->Test;
    std::ostream& fout = os;
    cmPropertyMap::const_iterator pit;
    cmPropertyMap* mpit = &test->GetProperties();
    if ( mpit->size() )
      {
      fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
      for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
        {
        fout << " " << pit->first.c_str() << " \"";
        const char* value = pit->second.GetValue();
        for ( ; *value; ++ value )
          {
          switch ( *value )
            {
            case '\\':
            case '"':
            case ' ':
            case '#':
            case '(':
            case ')':
            case '$':
            case '^':
              fout << "\\" << *value;
              break;
            case '\t':
              fout << "\\t";
              break;
            case '\n':
              fout << "\\n";
              break;
            case '\r':
              fout << "\\r";
              break;
            default:
              fout << *value;
            }
          }
        fout << "\"";
        }
      fout << ")" << std::endl;
      }
    }
}

//----------------------------------------------------------------------------
void cmTestGenerator::GenerateScriptActions(std::ostream& fout,
                                            Indent const& indent)
{
  this->TestGenerated = true;

  cmTest* test = this->Test;
  fout << indent;
  fout << "ADD_TEST(";
  fout << test->GetName() << " \"" << test->GetCommand() << "\"";

  std::vector<cmStdString>::const_iterator argit;
  for (argit = test->GetArguments().begin();
       argit != test->GetArguments().end(); ++argit)
    {
    // Just double-quote all arguments so they are re-parsed
    // correctly by the test system.
    fout << " \"";
    for(std::string::const_iterator c = argit->begin();
        c != argit->end(); ++c)
      {
      // Escape quotes within arguments.  We should escape
      // backslashes too but we cannot because it makes the result
      // inconsistent with previous behavior of this command.
      if((*c == '"'))
        {
        fout << '\\';
        }
      fout << *c;
      }
    fout << "\"";
    }
  fout << ")" << std::endl;
}

Index: cmLocalGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalGenerator.cxx,v
retrieving revision 1.297
retrieving revision 1.298
diff -C 2 -d -r1.297 -r1.298
*** cmLocalGenerator.cxx	5 Mar 2009 20:17:06 -0000	1.297
--- cmLocalGenerator.cxx	16 Mar 2009 14:40:23 -0000	1.298
***************
*** 27,30 ****
--- 27,31 ----
  #include "cmSourceFile.h"
  #include "cmTest.h"
+ #include "cmTestGenerator.h"
  #include "cmVersion.h"
  #include "cmake.h"
***************
*** 213,216 ****
--- 214,231 ----
      return;
      }
+ 
+   // Compute the set of configurations.
+   std::vector<std::string> configurationTypes;
+   if(const char* types =
+      this->Makefile->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
+     {
+     cmSystemTools::ExpandListArgument(types, configurationTypes);
+     }
+   const char* config = 0;
+   if(configurationTypes.empty())
+     {
+     config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
+     }
+ 
    std::string file = this->Makefile->GetStartOutputDirectory();
    file += "/";
***************
*** 239,313 ****
      fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
      }
!   
!   const std::vector<cmTest*> *tests = this->Makefile->GetTests();
!   std::vector<cmTest*>::const_iterator it;
!   for ( it = tests->begin(); it != tests->end(); ++ it )
      {
!     cmTest* test = *it;
!     fout << "ADD_TEST(";
!     fout << test->GetName() << " \"" << test->GetCommand() << "\"";
!     
!     std::vector<cmStdString>::const_iterator argit;
!     for (argit = test->GetArguments().begin();
!          argit != test->GetArguments().end(); ++argit)
!       {
!       // Just double-quote all arguments so they are re-parsed
!       // correctly by the test system.
!       fout << " \"";
!       for(std::string::const_iterator c = argit->begin(); 
!           c != argit->end(); ++c)
!         {
!         // Escape quotes within arguments.  We should escape
!         // backslashes too but we cannot because it makes the result
!         // inconsistent with previous behavior of this command.
!         if((*c == '"'))
!           {
!           fout << '\\';
!           }
!         fout << *c;
!         }
!       fout << "\"";
!       }
!     fout << ")" << std::endl;
!     cmPropertyMap::const_iterator pit;
!     cmPropertyMap* mpit = &test->GetProperties();
!     if ( mpit->size() )
!       {
!       fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
!       for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
!         {
!         fout << " " << pit->first.c_str() << " \"";
!         const char* value = pit->second.GetValue();
!         for ( ; *value; ++ value )
!           {
!           switch ( *value )
!             {
!           case '\\':
!           case '"':
!           case ' ':
!           case '#':
!           case '(':
!           case ')':
!           case '$':
!           case '^':
!             fout << "\\" << *value;
!             break;
!           case '\t':
!             fout << "\\t";
!             break;
!           case '\n':
!             fout << "\\n";
!             break;
!           case '\r':
!             fout << "\\r";
!             break;
!           default:
!             fout << *value;
!             }
!           }
!         fout << "\"";
!         }
!       fout << ")" << std::endl;
!       }
      }
    if ( this->Children.size())
--- 254,265 ----
      fout << "INCLUDE(\"" << testIncludeFile << "\")" << std::endl;
      }
! 
!   // Ask each test generator to write its code.
!   std::vector<cmTestGenerator*> const&
!     testers = this->Makefile->GetTestGenerators();
!   for(std::vector<cmTestGenerator*>::const_iterator gi = testers.begin();
!       gi != testers.end(); ++gi)
      {
!     (*gi)->Generate(fout, config, configurationTypes);
      }
    if ( this->Children.size())

--- NEW FILE: cmTestGenerator.h ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmTestGenerator.h,v $
  Language:  C++
  Date:      $Date: 2009-03-16 14:40:37 $
  Version:   $Revision: 1.1 $

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef cmTestGenerator_h
#define cmTestGenerator_h

#include "cmScriptGenerator.h"

class cmTest;

/** \class cmTestGenerator
 * \brief Support class for generating install scripts.
 *
 */
class cmTestGenerator: public cmScriptGenerator
{
public:
  cmTestGenerator(cmTest* test,
                  std::vector<std::string> const&
                  configurations = std::vector<std::string>());
  virtual ~cmTestGenerator();

protected:
  virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
  virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);

  cmTest* Test;
  bool TestGenerated;
};

#endif

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.253
retrieving revision 1.254
diff -C 2 -d -r1.253 -r1.254
*** cmMakefile.h	22 Jan 2009 18:18:39 -0000	1.253
--- cmMakefile.h	16 Mar 2009 14:40:31 -0000	1.254
***************
*** 42,45 ****
--- 42,46 ----
  class cmSourceFile;
  class cmTest;
+ class cmTestGenerator;
  class cmVariableWatch;
  class cmake;
***************
*** 770,774 ****
     */
    cmTest* GetTest(const char* testName) const;
-   const std::vector<cmTest*> *GetTests() const;
  
    /**
--- 771,774 ----
***************
*** 806,809 ****
--- 806,814 ----
      { return this->InstallGenerators; }
  
+   void AddTestGenerator(cmTestGenerator* g)
+     { if(g) this->TestGenerators.push_back(g); }
+   std::vector<cmTestGenerator*>& GetTestGenerators()
+     { return this->TestGenerators; }
+ 
    // Define the properties
    static void DefineProperties(cmake *cm);
***************
*** 851,855 ****
    // Tests
    std::map<cmStdString, cmTest*> Tests;
-   std::vector<cmTest*> OrderedTests;
    
    // The include and link-library paths.  These may have order
--- 856,859 ----
***************
*** 869,872 ****
--- 873,877 ----
  
    std::vector<cmInstallGenerator*> InstallGenerators;
+   std::vector<cmTestGenerator*> TestGenerators;
  
    std::string IncludeFileRegularExpression;

Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CMakeLists.txt,v
retrieving revision 1.412
retrieving revision 1.413
diff -C 2 -d -r1.412 -r1.413
*** CMakeLists.txt	16 Mar 2009 14:39:46 -0000	1.412
--- CMakeLists.txt	16 Mar 2009 14:40:18 -0000	1.413
***************
*** 216,219 ****
--- 216,221 ----
    cmTest.cxx
    cmTest.h
+   cmTestGenerator.cxx
+   cmTestGenerator.h
    cmVariableWatch.cxx
    cmVariableWatch.h

Index: cmAddTestCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmAddTestCommand.cxx,v
retrieving revision 1.29
retrieving revision 1.30
diff -C 2 -d -r1.29 -r1.30
*** cmAddTestCommand.cxx	23 Jan 2008 15:27:59 -0000	1.29
--- cmAddTestCommand.cxx	16 Mar 2009 14:40:22 -0000	1.30
***************
*** 17,20 ****
--- 17,22 ----
  #include "cmAddTestCommand.h"
  
+ #include "cmTestGenerator.h"
+ 
  #include "cmTest.h"
  
***************
*** 43,47 ****
      }
  
!   cmTest* test = this->Makefile->CreateTest(args[0].c_str());
    test->SetCommand(args[1].c_str());
    test->SetArguments(arguments);
--- 45,56 ----
      }
  
!   // Create the test but add a generator only the first time it is
!   // seen.  This preserves behavior from before test generators.
!   cmTest* test = this->Makefile->GetTest(args[0].c_str());
!   if(!test)
!     {
!     test = this->Makefile->CreateTest(args[0].c_str());
!     this->Makefile->AddTestGenerator(new cmTestGenerator(test));
!     }
    test->SetCommand(args[1].c_str());
    test->SetArguments(arguments);

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.505
retrieving revision 1.506
diff -C 2 -d -r1.505 -r1.506
*** cmMakefile.cxx	27 Feb 2009 16:23:14 -0000	1.505
--- cmMakefile.cxx	16 Mar 2009 14:40:26 -0000	1.506
***************
*** 33,36 ****
--- 33,37 ----
  #endif
  #include "cmInstallGenerator.h"
+ #include "cmTestGenerator.h"
  #include "cmake.h"
  #include <stdlib.h> // required for atoi
***************
*** 109,113 ****
    this->SourceFiles = mf.SourceFiles;
    this->Tests = mf.Tests;
-   this->OrderedTests = mf.OrderedTests;
    this->IncludeDirectories = mf.IncludeDirectories;
    this->LinkDirectories = mf.LinkDirectories;
--- 110,113 ----
***************
*** 117,120 ****
--- 117,121 ----
    this->LinkLibraries = mf.LinkLibraries;
    this->InstallGenerators = mf.InstallGenerators;
+   this->TestGenerators = mf.TestGenerators;
    this->IncludeFileRegularExpression = mf.IncludeFileRegularExpression;
    this->ComplainFileRegularExpression = mf.ComplainFileRegularExpression;
***************
*** 182,185 ****
--- 183,192 ----
      delete *i;
      }
+   for(std::vector<cmTestGenerator*>::iterator
+         i = this->TestGenerators.begin();
+       i != this->TestGenerators.end(); ++i)
+     {
+     delete *i;
+     }
    for(std::vector<cmSourceFile*>::iterator i = this->SourceFiles.begin();
        i != this->SourceFiles.end(); ++i)
***************
*** 3325,3329 ****
    test->SetMakefile(this);
    this->Tests[testName] = test;
-   this->OrderedTests.push_back(test);
    return test;
  }
--- 3332,3335 ----
***************
*** 3344,3353 ****
  }
  
- //----------------------------------------------------------------------------
- const std::vector<cmTest*> *cmMakefile::GetTests() const
- {
-   return &this->OrderedTests;
- }
- 
  std::string cmMakefile::GetListFileStack()
  {
--- 3350,3353 ----



More information about the Cmake-commits mailing list