From bf73264694234c4e82b31689b64b8a33d61552a9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 6 Aug 2013 15:48:28 -0400 Subject: Warn about unquoted arguments that look like long brackets In the future CMake will introduce Lua-style long bracket syntax. Warn about unquoted arguments that in the future will be treated as opening long brackets. Teach the RunCMake.Syntax test to cover such cases and ensure that the warning appears. --- Source/cmListFileCache.cxx | 21 +++++++++++++++++ Tests/RunCMake/Syntax/BracketWarn-stderr.txt | 35 ++++++++++++++++++++++++++++ Tests/RunCMake/Syntax/BracketWarn-stdout.txt | 1 + Tests/RunCMake/Syntax/BracketWarn.cmake | 1 + Tests/RunCMake/Syntax/RunCMakeTest.cmake | 1 + 5 files changed, 59 insertions(+) create mode 100644 Tests/RunCMake/Syntax/BracketWarn-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketWarn-stdout.txt create mode 100644 Tests/RunCMake/Syntax/BracketWarn.cmake diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index c499b6f..c02866c 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -343,6 +343,27 @@ void cmListFileParser::AddArgument(cmListFileLexer_Token* token, { cmListFileArgument a(token->text, delim, this->FileName, token->line); this->Function.Arguments.push_back(a); + if(delim == cmListFileArgument::Unquoted) + { + // Warn about a future behavior change. + const char* c = a.Value.c_str(); + if(*c++ == '[') + { + while(*c == '=') + { ++c; } + if(*c == '[') + { + cmOStringStream m; + m << "Syntax Warning in cmake code at\n" + << " " << this->FileName << ":" << token->line << ":" + << token->column << "\n" + << "A future version of CMake may treat unquoted argument:\n" + << " " << a.Value << "\n" + << "as an opening long bracket. Double-quote the argument."; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); + } + } + } if(this->Separation == SeparationOkay) { return; diff --git a/Tests/RunCMake/Syntax/BracketWarn-stderr.txt b/Tests/RunCMake/Syntax/BracketWarn-stderr.txt new file mode 100644 index 0000000..4a9cca6 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketWarn-stderr.txt @@ -0,0 +1,35 @@ +CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): + Syntax Warning in cmake code at + + .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:16 + + A future version of CMake may treat unquoted argument: + + \[\[ + + as an opening long bracket. Double-quote the argument. +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): + Syntax Warning in cmake code at + + .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:19 + + A future version of CMake may treat unquoted argument: + + \[=\[ + + as an opening long bracket. Double-quote the argument. +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): + Syntax Warning in cmake code at + + .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:27 + + A future version of CMake may treat unquoted argument: + + \[==\[x + + as an opening long bracket. Double-quote the argument. +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/Syntax/BracketWarn-stdout.txt b/Tests/RunCMake/Syntax/BracketWarn-stdout.txt new file mode 100644 index 0000000..01b2caa --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketWarn-stdout.txt @@ -0,0 +1 @@ +-- \[\[\[=\[\[=x\[==\[x diff --git a/Tests/RunCMake/Syntax/BracketWarn.cmake b/Tests/RunCMake/Syntax/BracketWarn.cmake new file mode 100644 index 0000000..8f33946 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketWarn.cmake @@ -0,0 +1 @@ +message(STATUS [[ [=[ [=x [==[x) diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index b1eeff9..8975b25 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -14,3 +14,4 @@ run_cmake(Unquoted1) run_cmake(UnterminatedCall1) run_cmake(UnterminatedCall2) run_cmake(UnterminatedString) +run_cmake(BracketWarn) -- cgit v0.12