From f3e58aeb7d6d63c6c0a21a8f0ba58226bdfb602a Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Tue, 3 Aug 2004 08:13:54 -0400 Subject: [PATCH] BUG: When regular expression failes to compile, produce error: Fixes part of Bug #1025 - CMake silently ignores regular expression failure --- Source/cmIfCommand.cxx | 32 ++++++++++++++++++++++---------- Source/cmIfCommand.h | 5 +++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index d9d4446be..763bcf578 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -101,15 +101,15 @@ ScopeEnded(cmMakefile &mf) bool cmIfCommand::InvokeInitialPass(const std::vector& args) { - bool isValid; + char* errorString = 0; std::vector expandedArguments; m_Makefile->ExpandArguments(args, expandedArguments); - bool isTrue = cmIfCommand::IsTrue(expandedArguments,isValid,m_Makefile); + bool isTrue = cmIfCommand::IsTrue(expandedArguments,&errorString,m_Makefile); - if (!isValid) + if (errorString) { - std::string err = "An IF command had incorrect arguments: "; + std::string err = "had incorrect arguments: "; unsigned int i; for(i =0; i < args.size(); ++i) { @@ -118,6 +118,9 @@ bool cmIfCommand::InvokeInitialPass(const std::vector& args) err += (args[i].Quoted?"\"":""); err += " "; } + err += "("; + err += errorString; + err += ")."; this->SetError(err.c_str()); return false; } @@ -146,17 +149,17 @@ bool cmIfCommand::InvokeInitialPass(const std::vector& args) bool cmIfCommand::IsTrue(const std::vector &args, - bool &isValid, const cmMakefile *makefile) + char **errorString, const cmMakefile *makefile) { // check for the different signatures - isValid = false; + *errorString = "Unknown arguments specified"; const char *def; const char *def2; // handle empty invocation if (args.size() < 1) { - isValid = true; + *errorString = 0; return false; } @@ -171,7 +174,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, args[0] == "CMAKE_MINOR_VERSION" && args[1] == "MATCHES") { - isValid = true; + *errorString = 0; return true; } @@ -279,7 +282,16 @@ bool cmIfCommand::IsTrue(const std::vector &args, *(argP1) == "MATCHES") { def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile); - cmsys::RegularExpression regEntry((argP2)->c_str()); + const char* rex = (argP2)->c_str(); + cmsys::RegularExpression regEntry; + if ( !regEntry.compile(rex) ) + { + cmOStringStream error; + error << "Regular expression \"" << rex << "\" cannot compile"; + *errorString = new char[error.str().size() + 1]; + strcpy(*errorString, error.str().c_str()); + return false; + } if (regEntry.find(def)) { *arg = "1"; @@ -499,7 +511,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, // now at the end there should only be one argument left if (newArgs.size() == 1) { - isValid = true; + *errorString = 0; if (*newArgs.begin() == "0") { return false; diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 4dcf8847f..af6dc7b36 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -159,9 +159,10 @@ public: } // this is a shared function for both If and Else to determine if - // the arguments were valid, and if so, was the response true + // the arguments were valid, and if so, was the response true. If there is an + // error, the errorString will be set. static bool IsTrue(const std::vector &args, - bool &isValid, const cmMakefile *mf); + char** errorString, const cmMakefile *mf); // Get a definition from the makefile. If it doesn't exist, // return the original string.