[Cmake-commits] [cmake-commits] king committed cmCTestHandlerCommand.cxx 1.13 1.14 cmCTestHandlerCommand.h 1.4 1.5

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Jan 12 09:10:49 EST 2009


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

Modified Files:
	cmCTestHandlerCommand.cxx cmCTestHandlerCommand.h 
Log Message:
ENH: Refactor CTest command argument handling

The previous approach to handling of arguments to ctest_* commands
worked only for keyword/value arguments with a single value.  This
refactors the approach to allow some commands to define alternative
argument forms.


Index: cmCTestHandlerCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestHandlerCommand.cxx,v
retrieving revision 1.13
retrieving revision 1.14
diff -C 2 -d -r1.13 -r1.14
*** cmCTestHandlerCommand.cxx	26 Dec 2008 20:27:01 -0000	1.13
--- cmCTestHandlerCommand.cxx	12 Jan 2009 14:10:47 -0000	1.14
***************
*** 39,46 ****
  ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  {
!   if ( !this->ProcessArguments(args, (unsigned int)this->Last, 
!                                &*this->Arguments.begin(),this->Values) )
      {
!     return false;
      }
  
--- 39,65 ----
  ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  {
!   // Allocate space for argument values.
!   this->Values.clear();
!   this->Values.resize(this->Last, 0);
! 
!   // Process input arguments.
!   this->ArgumentDoing = ArgumentDoingNone;
!   for(unsigned int i=0; i < args.size(); ++i)
      {
!     // Check this argument.
!     if(!this->CheckArgumentKeyword(args[i]) &&
!        !this->CheckArgumentValue(args[i]))
!       {
!       cmOStringStream e;
!       e << "called with unknown argument \"" << args[i] << "\".";
!       this->SetError(e.str().c_str());
!       return false;
!       }
! 
!     // Quit if an argument is invalid.
!     if(this->ArgumentDoing == ArgumentDoingError)
!       {
!       return false;
!       }
      }
  
***************
*** 122,177 ****
  }
  
! bool cmCTestHandlerCommand::ProcessArguments(
!   std::vector<std::string> const& args, int last, const char** strings,
!   std::vector<const char*>& values)
  {
!   int state = 0;
!   int cc;
!   values.resize(last);
!   for ( cc = 0; cc < last; ++ cc )
      {
!     values[cc] = 0;
      }
  
!   for(size_t i=0; i < args.size(); ++i)
      {
!     if ( state > 0 && state < last )
!       {
!       values[state] = args[i].c_str();
!       cmCTestLog(this->CTest, DEBUG, "Set " << strings[state] << " to "
!         << args[i].c_str() << std::endl);
!       state = 0;
!       }
!     else
        {
!       bool found = false;
!       for ( cc = 0; cc < last; ++ cc )
!         {
!         if ( strings[cc] && args[i] == strings[cc] )
!           {
!           state = cc;
!           if ( values[state] )
!             {
!             cmOStringStream ostr;
!             ostr << "called with incorrect number of arguments. "
!               << strings[state] << " specified twice.";
!             this->SetError(ostr.str().c_str());
!             return false;
!             }
!           found = true;
!           break;
!           }
!         }
!       if ( !found )
!         {
!         cmOStringStream str;
!         str
!           << "called with incorrect number of arguments. Extra argument is: "
!           << args[i].c_str() << ".";
!         this->SetError(str.str().c_str());
!         return false;
!         }
        }
      }
!   return true;
  }
--- 141,180 ----
  }
  
! //----------------------------------------------------------------------------
! bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
  {
!   // Check for a keyword in our argument/value table.
!   for(unsigned int k=0; k < this->Arguments.size(); ++k)
      {
!     if(this->Arguments[k] && arg == this->Arguments[k])
!       {
!       this->ArgumentDoing = ArgumentDoingKeyword;
!       this->ArgumentIndex = k;
!       return true;
!       }
      }
+   return false;
+ }
  
! //----------------------------------------------------------------------------
! bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
! {
!   if(this->ArgumentDoing == ArgumentDoingKeyword)
      {
!     this->ArgumentDoing = ArgumentDoingNone;
!     unsigned int k = this->ArgumentIndex;
!     if(this->Values[k])
        {
!       cmOStringStream e;
!       e << "Called with more than one value for " << this->Arguments[k];
!       this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
!       this->ArgumentDoing = ArgumentDoingError;
!       return true;
        }
+     this->Values[k] = arg.c_str();
+     cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k]
+                << " to " << arg << "\n");
+     return true;
      }
!   return false;
  }

Index: cmCTestHandlerCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestHandlerCommand.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -d -r1.4 -r1.5
*** cmCTestHandlerCommand.h	23 Jan 2008 15:28:01 -0000	1.4
--- cmCTestHandlerCommand.h	12 Jan 2009 14:10:47 -0000	1.5
***************
*** 53,58 ****
  protected:
    virtual cmCTestGenericHandler* InitializeHandler() = 0;
!   bool ProcessArguments(std::vector<std::string> const& args,
!     int last, const char** strings, std::vector<const char*>& values);
  
    std::string ReturnVariable;
--- 53,69 ----
  protected:
    virtual cmCTestGenericHandler* InitializeHandler() = 0;
! 
!   // Command argument handling.
!   virtual bool CheckArgumentKeyword(std::string const& arg);
!   virtual bool CheckArgumentValue(std::string const& arg);
!   enum
!   {
!     ArgumentDoingNone,
!     ArgumentDoingError,
!     ArgumentDoingKeyword,
!     ArgumentDoingLast1
!   };
!   int ArgumentDoing;
!   unsigned int ArgumentIndex;
  
    std::string ReturnVariable;



More information about the Cmake-commits mailing list