Browse Source

ENH: Improve syntax

Andy Cedilnik 20 years ago
parent
commit
9619d54003

+ 51 - 10
Source/CTest/cmCTestBuildCommand.cxx

@@ -24,16 +24,55 @@
 bool cmCTestBuildCommand::InitialPass(
 bool cmCTestBuildCommand::InitialPass(
   std::vector<std::string> const& args)
   std::vector<std::string> const& args)
 {
 {
-  if (args.size() != 2)
+  const char* build_dir = 0;
+  const char* res_var = 0;
+
+  bool havereturn_variable = false;
+  bool havesource = false;
+  for(size_t i=0; i < args.size(); ++i)
     {
     {
-    this->SetError("called with incorrect number of arguments");
-    return false;
+    if ( havereturn_variable )
+      {
+      res_var = args[i].c_str();
+      havereturn_variable = false;
+      }
+    else if ( havesource )
+      {
+      build_dir = args[i].c_str();
+      havesource = false;
+      }
+    else if(args[i] == "RETURN_VALUE")
+      {
+      if ( res_var )
+        {
+        this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
+        return false;
+        }
+      havereturn_variable = true;
+      }    
+    else if(args[i] == "BUILD")
+      {
+      if ( build_dir )
+        {
+        this->SetError("called with incorrect number of arguments. BUILD specified twice.");
+        return false;
+        }
+      havesource = true;
+      }
+    else
+      {
+      cmOStringStream str;
+      str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
+      this->SetError(str.str().c_str());
+      return false;
+      }
     }
     }
 
 
-  const char* build_dir = args[0].c_str();
-  const char* res_var = args[1].c_str();
+  if ( build_dir )
+    {
+    m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
+    }
 
 
-  m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
   cmCTestGenericHandler* handler = m_CTest->GetHandler("build");
   cmCTestGenericHandler* handler = m_CTest->GetHandler("build");
   if ( !handler )
   if ( !handler )
     {
     {
@@ -62,7 +101,6 @@ bool cmCTestBuildCommand::InitialPass(
         m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName);
         m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName);
       gen->FindMakeProgram(m_Makefile);
       gen->FindMakeProgram(m_Makefile);
       const char* cmakeMakeProgram = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
       const char* cmakeMakeProgram = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
-      std::cout << "CMake Make program is: " << cmakeMakeProgram << std::endl;
       std::string buildCommand = gen->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName,
       std::string buildCommand = gen->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName,
         0, cmakeBuildConfiguration, true);
         0, cmakeBuildConfiguration, true);
 
 
@@ -78,9 +116,12 @@ bool cmCTestBuildCommand::InitialPass(
     }
     }
   
   
   int res = handler->ProcessHandler();
   int res = handler->ProcessHandler();
-  cmOStringStream str;
-  str << res;
-  m_Makefile->AddDefinition(res_var, str.str().c_str());
+  if ( res_var )
+    {
+    cmOStringStream str;
+    str << res;
+    m_Makefile->AddDefinition(res_var, str.str().c_str());
+    }
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Source/CTest/cmCTestBuildCommand.h

@@ -66,7 +66,7 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
     return
     return
-      "  CTEST_BUILD(build_dir res)\n"
+      "  CTEST_BUILD([BUILD build_dir] [RETURN_VALUE res])\n"
       "Builds the given build directory and stores results in Build.xml.";
       "Builds the given build directory and stores results in Build.xml.";
     }
     }
 
 

+ 52 - 10
Source/CTest/cmCTestConfigureCommand.cxx

@@ -22,17 +22,56 @@
 bool cmCTestConfigureCommand::InitialPass(
 bool cmCTestConfigureCommand::InitialPass(
   std::vector<std::string> const& args)
   std::vector<std::string> const& args)
 {
 {
-  if (args.size() != 2)
+  const char* build_dir = 0;
+  const char* res_var = 0;
+
+  bool havereturn_variable = false;
+  bool havesource = false;
+  for(size_t i=0; i < args.size(); ++i)
     {
     {
-    this->SetError("called with incorrect number of arguments");
-    return false;
+    if ( havereturn_variable )
+      {
+      res_var = args[i].c_str();
+      havereturn_variable = false;
+      }
+    else if ( havesource )
+      {
+      build_dir = args[i].c_str();
+      havesource = false;
+      }
+    else if(args[i] == "RETURN_VALUE")
+      {
+      if ( res_var )
+        {
+        this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
+        return false;
+        }
+      havereturn_variable = true;
+      }    
+    else if(args[i] == "BUILD")
+      {
+      if ( build_dir )
+        {
+        this->SetError("called with incorrect number of arguments. BUILD specified twice.");
+        return false;
+        }
+      havesource = true;
+      }
+    else
+      {
+      cmOStringStream str;
+      str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
+      this->SetError(str.str().c_str());
+      return false;
+      }
     }
     }
 
 
-  const char* build_dir = args[0].c_str();
-  const char* res_var = args[1].c_str();
-
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "ConfigureCommand", "CTEST_CONFIGURE_COMMAND");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "ConfigureCommand", "CTEST_CONFIGURE_COMMAND");
-  m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
+
+  if ( build_dir )
+    {
+    m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
+    }
 
 
   cmCTestGenericHandler* handler = m_CTest->GetHandler("configure");
   cmCTestGenericHandler* handler = m_CTest->GetHandler("configure");
   if ( !handler )
   if ( !handler )
@@ -41,9 +80,12 @@ bool cmCTestConfigureCommand::InitialPass(
     return false;
     return false;
     }
     }
   int res = handler->ProcessHandler();
   int res = handler->ProcessHandler();
-  cmOStringStream str;
-  str << res;
-  m_Makefile->AddDefinition(res_var, str.str().c_str());
+  if ( res_var )
+    {
+    cmOStringStream str;
+    str << res;
+    m_Makefile->AddDefinition(res_var, str.str().c_str());
+    }
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Source/CTest/cmCTestConfigureCommand.h

@@ -66,7 +66,7 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
     return
     return
-      "  CTEST_CONFIGURE(build_dir res)\n"
+      "  CTEST_CONFIGURE(BUILD build_dir RETURN_VALUE res)\n"
       "Configures the given build directory and stores results in Configure.xml. The "
       "Configures the given build directory and stores results in Configure.xml. The "
       "second argument is a variable that will hold return value.";
       "second argument is a variable that will hold return value.";
     }
     }

+ 4 - 4
Source/CTest/cmCTestCoverageHandler.cxx

@@ -165,8 +165,8 @@ int cmCTestCoverageHandler::ProcessHandler()
   cmSystemTools::ConvertToUnixSlashes(sourceDir);
   cmSystemTools::ConvertToUnixSlashes(sourceDir);
   cmSystemTools::ConvertToUnixSlashes(binaryDir);
   cmSystemTools::ConvertToUnixSlashes(binaryDir);
 
 
-  std::string asfGlob = sourceDir + "/*";
-  std::string abfGlob = binaryDir + "/*";
+  //std::string asfGlob = sourceDir + "/*";
+  //std::string abfGlob = binaryDir + "/*";
   std::string daGlob = binaryDir + "/*.da";
   std::string daGlob = binaryDir + "/*.da";
   std::string gcovOutputRex = "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$";
   std::string gcovOutputRex = "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$";
   std::string gcovOutputRex2 = "^Creating (.*\\.gcov)\\.";
   std::string gcovOutputRex2 = "^Creating (.*\\.gcov)\\.";
@@ -347,8 +347,8 @@ int cmCTestCoverageHandler::ProcessHandler()
   int cnt = 0;
   int cnt = 0;
   long total_tested = 0;
   long total_tested = 0;
   long total_untested = 0;
   long total_untested = 0;
-  std::string fullSourceDir = sourceDir + "/";
-  std::string fullBinaryDir = binaryDir + "/";
+  //std::string fullSourceDir = sourceDir + "/";
+  //std::string fullBinaryDir = binaryDir + "/";
   for ( fileIterator = totalCoverage.begin();
   for ( fileIterator = totalCoverage.begin();
     fileIterator != totalCoverage.end();
     fileIterator != totalCoverage.end();
     ++fileIterator )
     ++fileIterator )

+ 31 - 8
Source/CTest/cmCTestSubmitCommand.cxx

@@ -22,14 +22,34 @@
 bool cmCTestSubmitCommand::InitialPass(
 bool cmCTestSubmitCommand::InitialPass(
   std::vector<std::string> const& args)
   std::vector<std::string> const& args)
 {
 {
-  if (args.size() != 1)
+  const char* res_var = 0;
+
+  bool havereturn_variable = false;
+  for(size_t i=0; i < args.size(); ++i)
     {
     {
-    this->SetError("called with incorrect number of arguments");
-    return false;
+    if ( havereturn_variable )
+      {
+      res_var = args[i].c_str();
+      havereturn_variable = false;
+      }
+    else if(args[i] == "RETURN_VALUE")
+      {
+      if ( res_var )
+        {
+        this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
+        return false;
+        }
+      havereturn_variable = true;
+      }    
+    else
+      {
+      cmOStringStream str;
+      str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
+      this->SetError(str.str().c_str());
+      return false;
+      }
     }
     }
 
 
-  const char* res_var = args[0].c_str();
-
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropMethod", "CTEST_DROP_METHOD");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropMethod", "CTEST_DROP_METHOD");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropSite", "CTEST_DROP_SITE");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropSite", "CTEST_DROP_SITE");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropLocation", "CTEST_DROP_LOCATION");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropLocation", "CTEST_DROP_LOCATION");
@@ -45,9 +65,12 @@ bool cmCTestSubmitCommand::InitialPass(
     return false;
     return false;
     }
     }
   int res = handler->ProcessHandler();
   int res = handler->ProcessHandler();
-  cmOStringStream str;
-  str << res;
-  m_Makefile->AddDefinition(res_var, str.str().c_str());
+  if ( res_var )
+    {
+    cmOStringStream str;
+    str << res;
+    m_Makefile->AddDefinition(res_var, str.str().c_str());
+    }
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Source/CTest/cmCTestSubmitCommand.h

@@ -66,7 +66,7 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
     return
     return
-      "  CTEST_SUBMIT(res)\n"
+      "  CTEST_SUBMIT([RETURN_VALUE res])\n"
       "Submits the test results for the project.";
       "Submits the test results for the project.";
     }
     }
 
 

+ 52 - 11
Source/CTest/cmCTestTestCommand.cxx

@@ -22,16 +22,54 @@
 bool cmCTestTestCommand::InitialPass(
 bool cmCTestTestCommand::InitialPass(
   std::vector<std::string> const& args)
   std::vector<std::string> const& args)
 {
 {
-  if (args.size() != 2)
+  const char* build_dir = 0;
+  const char* res_var = 0;
+
+  bool havereturn_variable = false;
+  bool havesource = false;
+  for(size_t i=0; i < args.size(); ++i)
     {
     {
-    this->SetError("called with incorrect number of arguments");
-    return false;
+    if ( havereturn_variable )
+      {
+      res_var = args[i].c_str();
+      havereturn_variable = false;
+      }
+    else if ( havesource )
+      {
+      build_dir = args[i].c_str();
+      havesource = false;
+      }
+    else if(args[i] == "RETURN_VALUE")
+      {
+      if ( res_var )
+        {
+        this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
+        return false;
+        }
+      havereturn_variable = true;
+      }    
+    else if(args[i] == "BUILD")
+      {
+      if ( build_dir )
+        {
+        this->SetError("called with incorrect number of arguments. BUILD specified twice.");
+        return false;
+        }
+      havesource = true;
+      }
+    else
+      {
+      cmOStringStream str;
+      str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
+      this->SetError(str.str().c_str());
+      return false;
+      }
     }
     }
 
 
-  const char* build_dir = args[0].c_str();
-  const char* res_var = args[1].c_str();
-
-  m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
+  if ( build_dir )
+    {
+    m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
+    }
 
 
   cmCTestGenericHandler* handler = m_CTest->GetHandler("test");
   cmCTestGenericHandler* handler = m_CTest->GetHandler("test");
   if ( !handler )
   if ( !handler )
@@ -40,12 +78,15 @@ bool cmCTestTestCommand::InitialPass(
     return false;
     return false;
     }
     }
   std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
   std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
-  cmSystemTools::ChangeDirectory(build_dir);
+  cmSystemTools::ChangeDirectory(m_CTest->GetCTestConfiguration("BuildDirectory").c_str());
   int res = handler->ProcessHandler();
   int res = handler->ProcessHandler();
+  if ( res_var )
+    {
+    cmOStringStream str;
+    str << res;
+    m_Makefile->AddDefinition(res_var, str.str().c_str());
+    }
   cmSystemTools::ChangeDirectory(current_dir.c_str());
   cmSystemTools::ChangeDirectory(current_dir.c_str());
-  cmOStringStream str;
-  str << res;
-  m_Makefile->AddDefinition(res_var, str.str().c_str());
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Source/CTest/cmCTestTestCommand.h

@@ -66,7 +66,7 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
     return
     return
-      "  CTEST_TEST(build_dir res)\n"
+      "  CTEST_TEST([BUILD build_dir] [RETURN_VALUE res])\n"
       "Tests the given build directory and stores results in Test.xml. The "
       "Tests the given build directory and stores results in Test.xml. The "
       "second argument is a variable that will hold value.";
       "second argument is a variable that will hold value.";
     }
     }

+ 51 - 10
Source/CTest/cmCTestUpdateCommand.cxx

@@ -22,15 +22,50 @@
 bool cmCTestUpdateCommand::InitialPass(
 bool cmCTestUpdateCommand::InitialPass(
   std::vector<std::string> const& args)
   std::vector<std::string> const& args)
 {
 {
-  if (args.size() != 2)
+  const char* source_dir = 0;
+  const char* res_var = 0;
+
+  bool havereturn_variable = false;
+  bool havesource = false;
+  for(size_t i=0; i < args.size(); ++i)
     {
     {
-    this->SetError("called with incorrect number of arguments");
-    return false;
+    if ( havereturn_variable )
+      {
+      res_var = args[i].c_str();
+      havereturn_variable = false;
+      }
+    else if ( havesource )
+      {
+      source_dir = args[i].c_str();
+      havesource = false;
+      }
+    else if(args[i] == "RETURN_VALUE")
+      {
+      if ( res_var )
+        {
+        this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
+        return false;
+        }
+      havereturn_variable = true;
+      }    
+    else if(args[i] == "SOURCE")
+      {
+      if ( source_dir )
+        {
+        this->SetError("called with incorrect number of arguments. SOURCE specified twice.");
+        return false;
+        }
+      havesource = true;
+      }
+    else
+      {
+      cmOStringStream str;
+      str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
+      this->SetError(str.str().c_str());
+      return false;
+      }
     }
     }
 
 
-  const char* source_dir = args[0].c_str();
-  const char* res_var = args[1].c_str();
-
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND");
   m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND");
 
 
@@ -40,11 +75,17 @@ bool cmCTestUpdateCommand::InitialPass(
     this->SetError("internal CTest error. Cannot instantiate update handler");
     this->SetError("internal CTest error. Cannot instantiate update handler");
     return false;
     return false;
     }
     }
-  handler->SetOption("SourceDirectory", source_dir);
+  if ( source_dir )
+    {
+    handler->SetOption("SourceDirectory", source_dir);
+    }
   int res = handler->ProcessHandler();
   int res = handler->ProcessHandler();
-  cmOStringStream str;
-  str << res;
-  m_Makefile->AddDefinition(res_var, str.str().c_str());
+  if ( res_var )
+    {
+    cmOStringStream str;
+    str << res;
+    m_Makefile->AddDefinition(res_var, str.str().c_str());
+    }
   return true;
   return true;
 }
 }
 
 

+ 1 - 1
Source/CTest/cmCTestUpdateCommand.h

@@ -66,7 +66,7 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
     return
     return
-      "  CTEST_UPDATE(source res)\n"
+      "  CTEST_UPDATE([SOURCE source] [RETURN_VALUE res])\n"
       "Updates the given source directory and stores results in Update.xml. The "
       "Updates the given source directory and stores results in Update.xml. The "
       "second argument is a variable that will hold the number of files "
       "second argument is a variable that will hold the number of files "
       "modified. If there is a problem, the variable will be -1.";
       "modified. If there is a problem, the variable will be -1.";