tests: test CMP0053 in WARN mode when watching variables
When CMP0053 is in WARN mode, variables get expanded twice, leaking the fact that the string was expanded twice and changing behavior. Instead, suppress variable watches when running the expansion to trigger the CMP0053 warning.
This commit is contained in:
parent
3ea9bde845
commit
9ba91463e6
@ -103,6 +103,7 @@ cmMakefile::cmMakefile(): Internal(new Internals)
|
|||||||
this->GeneratingBuildSystem = false;
|
this->GeneratingBuildSystem = false;
|
||||||
|
|
||||||
this->NumLastMatches = 0;
|
this->NumLastMatches = 0;
|
||||||
|
this->SuppressWatches = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
||||||
@ -153,6 +154,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
|||||||
this->OutputToSource = mf.OutputToSource;
|
this->OutputToSource = mf.OutputToSource;
|
||||||
|
|
||||||
this->NumLastMatches = mf.NumLastMatches;
|
this->NumLastMatches = mf.NumLastMatches;
|
||||||
|
this->SuppressWatches = mf.SuppressWatches;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -2463,7 +2465,7 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
|
|||||||
}
|
}
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
cmVariableWatch* vv = this->GetVariableWatch();
|
cmVariableWatch* vv = this->GetVariableWatch();
|
||||||
if ( vv )
|
if ( vv && !this->SuppressWatches )
|
||||||
{
|
{
|
||||||
if ( def )
|
if ( def )
|
||||||
{
|
{
|
||||||
@ -2570,10 +2572,14 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source,
|
|||||||
original = source;
|
original = source;
|
||||||
newResult = source;
|
newResult = source;
|
||||||
compareResults = true;
|
compareResults = true;
|
||||||
|
// Suppress variable watches to avoid calling hooks twice. Suppress new
|
||||||
|
// dereferences since the OLD behavior is still what is actually used.
|
||||||
|
this->SuppressWatches = true;
|
||||||
newError =
|
newError =
|
||||||
ExpandVariablesInStringNew(newErrorstr, newResult, escapeQuotes,
|
ExpandVariablesInStringNew(newErrorstr, newResult, escapeQuotes,
|
||||||
noEscapes, atOnly, filename, line,
|
noEscapes, atOnly, filename, line,
|
||||||
removeEmpty, replaceAt);
|
removeEmpty, replaceAt);
|
||||||
|
this->SuppressWatches = false;
|
||||||
}
|
}
|
||||||
case cmPolicies::OLD:
|
case cmPolicies::OLD:
|
||||||
mtype = ExpandVariablesInStringOld(errorstr, source, escapeQuotes,
|
mtype = ExpandVariablesInStringOld(errorstr, source, escapeQuotes,
|
||||||
|
@ -1127,6 +1127,8 @@ private:
|
|||||||
const std::string& feature) const;
|
const std::string& feature) const;
|
||||||
bool HaveCxxFeatureAvailable(cmTarget const* target,
|
bool HaveCxxFeatureAvailable(cmTarget const* target,
|
||||||
const std::string& feature) const;
|
const std::string& feature) const;
|
||||||
|
|
||||||
|
mutable bool SuppressWatches;
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
2
Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt
Normal file
2
Tests/RunCMake/CMP0053/CMP0053-NEW-stderr.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
^called
|
||||||
|
--><--$
|
8
Tests/RunCMake/CMP0053/CMP0053-NEW.cmake
Normal file
8
Tests/RunCMake/CMP0053/CMP0053-NEW.cmake
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
cmake_policy(SET CMP0053 NEW)
|
||||||
|
|
||||||
|
function (watch_callback)
|
||||||
|
message("called")
|
||||||
|
endfunction ()
|
||||||
|
|
||||||
|
variable_watch(test watch_callback)
|
||||||
|
message("-->${test}<--")
|
2
Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
Normal file
2
Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
^called
|
||||||
|
--><--$
|
8
Tests/RunCMake/CMP0053/CMP0053-OLD.cmake
Normal file
8
Tests/RunCMake/CMP0053/CMP0053-OLD.cmake
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
cmake_policy(SET CMP0053 OLD)
|
||||||
|
|
||||||
|
function (watch_callback)
|
||||||
|
message("called")
|
||||||
|
endfunction ()
|
||||||
|
|
||||||
|
variable_watch(test watch_callback)
|
||||||
|
message("-->${test}<--")
|
2
Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt
Normal file
2
Tests/RunCMake/CMP0053/CMP0053-WARN-stderr.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
^called
|
||||||
|
--><--$
|
6
Tests/RunCMake/CMP0053/CMP0053-WARN.cmake
Normal file
6
Tests/RunCMake/CMP0053/CMP0053-WARN.cmake
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function (watch_callback)
|
||||||
|
message("called")
|
||||||
|
endfunction ()
|
||||||
|
|
||||||
|
variable_watch(test watch_callback)
|
||||||
|
message("-->${test}<--")
|
3
Tests/RunCMake/CMP0053/CMakeLists.txt
Normal file
3
Tests/RunCMake/CMP0053/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
project(${RunCMake_TEST} CXX)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
5
Tests/RunCMake/CMP0053/RunCMakeTest.cmake
Normal file
5
Tests/RunCMake/CMP0053/RunCMakeTest.cmake
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(CMP0053-OLD)
|
||||||
|
run_cmake(CMP0053-NEW)
|
||||||
|
run_cmake(CMP0053-WARN)
|
@ -35,6 +35,7 @@ add_RunCMake_test(CMP0046)
|
|||||||
add_RunCMake_test(CMP0049)
|
add_RunCMake_test(CMP0049)
|
||||||
add_RunCMake_test(CMP0050)
|
add_RunCMake_test(CMP0050)
|
||||||
add_RunCMake_test(CMP0051)
|
add_RunCMake_test(CMP0051)
|
||||||
|
add_RunCMake_test(CMP0053)
|
||||||
add_RunCMake_test(CTest)
|
add_RunCMake_test(CTest)
|
||||||
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles")
|
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles")
|
||||||
add_RunCMake_test(CompilerChange)
|
add_RunCMake_test(CompilerChange)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user