Merge topic 'revert-definition-map-lookup'
d1b62185
Merge branch 'parent-scope-tests' into variable-pull-failure5f414cef
Revert "cmDefinitions: Don't store parent lookups"e0c0b1ac
test: add a test for PARENT_SCOPE with multiple scopes064c415d
test: add test for PARENT_SCOPE behavior
This commit is contained in:
commit
8eb64831be
|
@ -29,7 +29,7 @@ void cmDefinitions::Reset(cmDefinitions* parent)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDefinitions::Def const&
|
cmDefinitions::Def const&
|
||||||
cmDefinitions::GetInternal(const std::string& key) const
|
cmDefinitions::GetInternal(const std::string& key)
|
||||||
{
|
{
|
||||||
MapType::const_iterator i = this->Map.find(key);
|
MapType::const_iterator i = this->Map.find(key);
|
||||||
if(i != this->Map.end())
|
if(i != this->Map.end())
|
||||||
|
@ -38,8 +38,9 @@ cmDefinitions::GetInternal(const std::string& key) const
|
||||||
}
|
}
|
||||||
if(cmDefinitions* up = this->Up)
|
if(cmDefinitions* up = this->Up)
|
||||||
{
|
{
|
||||||
// Query the parent scope.
|
// Query the parent scope and store the result locally.
|
||||||
return up->GetInternal(key);
|
Def def = up->GetInternal(key);
|
||||||
|
return this->Map.insert(MapType::value_type(key, def)).first->second;
|
||||||
}
|
}
|
||||||
return this->NoDef;
|
return this->NoDef;
|
||||||
}
|
}
|
||||||
|
@ -62,25 +63,12 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmDefinitions::Get(const std::string& key) const
|
const char* cmDefinitions::Get(const std::string& key)
|
||||||
{
|
{
|
||||||
Def const& def = this->GetInternal(key);
|
Def const& def = this->GetInternal(key);
|
||||||
return def.Exists? def.c_str() : 0;
|
return def.Exists? def.c_str() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
void cmDefinitions::Pull(const std::string& key)
|
|
||||||
{
|
|
||||||
if (this->Up)
|
|
||||||
{
|
|
||||||
Def const& def = this->Up->GetInternal(key);
|
|
||||||
if (def.Exists)
|
|
||||||
{
|
|
||||||
this->SetInternal(key, def);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
const char* cmDefinitions::Set(const std::string& key, const char* value)
|
const char* cmDefinitions::Set(const std::string& key, const char* value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,11 +36,9 @@ public:
|
||||||
/** Returns the parent scope, if any. */
|
/** Returns the parent scope, if any. */
|
||||||
cmDefinitions* GetParent() const { return this->Up; }
|
cmDefinitions* GetParent() const { return this->Up; }
|
||||||
|
|
||||||
/** Get the value associated with a key; null if none. */
|
/** Get the value associated with a key; null if none.
|
||||||
const char* Get(const std::string& key) const;
|
Store the result locally if it came from a parent. */
|
||||||
|
const char* Get(const std::string& key);
|
||||||
/** Pull a variable from the parent. */
|
|
||||||
void Pull(const std::string& key);
|
|
||||||
|
|
||||||
/** Set (or unset if null) a value associated with a key. */
|
/** Set (or unset if null) a value associated with a key. */
|
||||||
const char* Set(const std::string& key, const char* value);
|
const char* Set(const std::string& key, const char* value);
|
||||||
|
@ -82,7 +80,7 @@ private:
|
||||||
MapType Map;
|
MapType Map;
|
||||||
|
|
||||||
// Internal query and update methods.
|
// Internal query and update methods.
|
||||||
Def const& GetInternal(const std::string& key) const;
|
Def const& GetInternal(const std::string& key);
|
||||||
Def const& SetInternal(const std::string& key, Def const& def);
|
Def const& SetInternal(const std::string& key, Def const& def);
|
||||||
|
|
||||||
// Implementation of Closure() method.
|
// Implementation of Closure() method.
|
||||||
|
|
|
@ -4476,7 +4476,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
||||||
if(cmDefinitions* up = cur.GetParent())
|
if(cmDefinitions* up = cur.GetParent())
|
||||||
{
|
{
|
||||||
// First localize the definition in the current scope.
|
// First localize the definition in the current scope.
|
||||||
cur.Pull(var);
|
cur.Get(var);
|
||||||
|
|
||||||
// Now update the definition in the parent scope.
|
// Now update the definition in the parent scope.
|
||||||
up->Set(var, varDef);
|
up->Set(var, varDef);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
^before PARENT_SCOPE blah=value2
|
||||||
|
after PARENT_SCOPE blah=value2
|
||||||
|
in parent scope, blah=value2$
|
|
@ -0,0 +1,13 @@
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
project(Minimal NONE)
|
||||||
|
|
||||||
|
function(test_set)
|
||||||
|
set(blah "value2")
|
||||||
|
message("before PARENT_SCOPE blah=${blah}")
|
||||||
|
set(blah ${blah} PARENT_SCOPE)
|
||||||
|
message("after PARENT_SCOPE blah=${blah}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
set(blah value1)
|
||||||
|
test_set()
|
||||||
|
message("in parent scope, blah=${blah}")
|
|
@ -0,0 +1,144 @@
|
||||||
|
----------
|
||||||
|
variable values at top before calls:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->top<--
|
||||||
|
top_explicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_tounset: -->top<--
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: <undefined>
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: <undefined>
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: <undefined>
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at outer start:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->top<--
|
||||||
|
top_explicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_tounset: -->top<--
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: <undefined>
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: <undefined>
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: <undefined>
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at outer before inner:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->top<--
|
||||||
|
top_explicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_tounset: -->top<--
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: -->outer<--
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: -->outer<--
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: -->outer<--
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at inner start:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->top<--
|
||||||
|
top_explicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_tounset: -->top<--
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: -->outer<--
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: -->outer<--
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: -->outer<--
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at inner end:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->top<--
|
||||||
|
top_explicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_tounset: -->top<--
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: -->outer<--
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: -->outer<--
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: -->outer<--
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at outer after inner:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->inner<--
|
||||||
|
top_explicit_inner_unset: -->inner<--
|
||||||
|
top_explicit_inner_tounset: <undefined>
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: -->outer<--
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: -->inner<--
|
||||||
|
outer_explicit_inner_unset: -->inner<--
|
||||||
|
outer_explicit_inner_tounset: <undefined>
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at outer end:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->inner<--
|
||||||
|
top_explicit_inner_unset: -->inner<--
|
||||||
|
top_explicit_inner_tounset: <undefined>
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: <undefined>
|
||||||
|
top_explicit_outer_tounset: -->top<--
|
||||||
|
outer_implicit_inner_set: -->outer<--
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: -->inner<--
|
||||||
|
outer_explicit_inner_unset: -->inner<--
|
||||||
|
outer_explicit_inner_tounset: <undefined>
|
||||||
|
----------
|
||||||
|
----------
|
||||||
|
variable values at top after calls:
|
||||||
|
top_implicit_inner_set: -->top<--
|
||||||
|
top_implicit_inner_unset: <undefined>
|
||||||
|
top_explicit_inner_set: -->outer<--
|
||||||
|
top_explicit_inner_unset: -->outer<--
|
||||||
|
top_explicit_inner_tounset: <undefined>
|
||||||
|
top_implicit_outer_set: -->top<--
|
||||||
|
top_explicit_outer_unset: -->outer<--
|
||||||
|
top_explicit_outer_set: -->outer<--
|
||||||
|
top_explicit_outer_unset: -->outer<--
|
||||||
|
top_explicit_outer_tounset: <undefined>
|
||||||
|
outer_implicit_inner_set: <undefined>
|
||||||
|
outer_implicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_set: <undefined>
|
||||||
|
outer_explicit_inner_unset: <undefined>
|
||||||
|
outer_explicit_inner_tounset: <undefined>
|
||||||
|
----------
|
|
@ -0,0 +1,104 @@
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
project(Minimal NONE)
|
||||||
|
|
||||||
|
function(report where)
|
||||||
|
message("----------")
|
||||||
|
message("variable values at ${where}:")
|
||||||
|
foreach(var IN ITEMS
|
||||||
|
top_implicit_inner_set top_implicit_inner_unset
|
||||||
|
top_explicit_inner_set top_explicit_inner_unset top_explicit_inner_tounset
|
||||||
|
top_implicit_outer_set top_explicit_outer_unset
|
||||||
|
top_explicit_outer_set top_explicit_outer_unset top_explicit_outer_tounset
|
||||||
|
|
||||||
|
outer_implicit_inner_set outer_implicit_inner_unset
|
||||||
|
outer_explicit_inner_set outer_explicit_inner_unset outer_explicit_inner_tounset)
|
||||||
|
if(DEFINED ${var})
|
||||||
|
message("${var}: -->${${var}}<--")
|
||||||
|
else()
|
||||||
|
message("${var}: <undefined>")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
message("----------")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
macro(set_values upscope downscope value)
|
||||||
|
# Pull the value in implicitly.
|
||||||
|
set(dummy ${${upscope}_implicit_${downscope}_set})
|
||||||
|
set(dummy ${${upscope}_implicit_${downscope}_unset})
|
||||||
|
# Pull it down explicitly.
|
||||||
|
set(${upscope}_explicit_${downscope}_set "${value}" PARENT_SCOPE)
|
||||||
|
set(${upscope}_explicit_${downscope}_unset "${value}" PARENT_SCOPE)
|
||||||
|
set(${upscope}_explicit_${downscope}_tounset PARENT_SCOPE)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
function(inner)
|
||||||
|
report("inner start")
|
||||||
|
|
||||||
|
set_values(top inner inner)
|
||||||
|
set_values(outer inner inner)
|
||||||
|
|
||||||
|
report("inner end")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(outer)
|
||||||
|
report("outer start")
|
||||||
|
|
||||||
|
set_values(top outer outer)
|
||||||
|
|
||||||
|
# Set values for inner to manipulate.
|
||||||
|
set(outer_implicit_inner_set outer)
|
||||||
|
set(outer_implicit_inner_unset)
|
||||||
|
set(outer_explicit_inner_set outer)
|
||||||
|
set(outer_explicit_inner_unset)
|
||||||
|
set(outer_explicit_inner_tounset outer)
|
||||||
|
|
||||||
|
report("outer before inner")
|
||||||
|
|
||||||
|
inner()
|
||||||
|
|
||||||
|
report("outer after inner")
|
||||||
|
|
||||||
|
# Do what inner does so that we can test the values that inner should have
|
||||||
|
# pulled through to here.
|
||||||
|
set_values(top inner outer)
|
||||||
|
|
||||||
|
report("outer end")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# variable name is:
|
||||||
|
#
|
||||||
|
# <upscope>_<pulltype>_<downscope>_<settype>
|
||||||
|
#
|
||||||
|
# where the value is the name of the scope it was set in. The scopes available
|
||||||
|
# are "top", "outer", and "inner". The pull type may either be "implicit" or
|
||||||
|
# "explicit" based on whether the pull is due to a variable dereference or a
|
||||||
|
# PARENT_SCOPE setting. The settype is "set" where both scopes set a value,
|
||||||
|
# "unset" where upscope unsets it and downscope sets it, and "tounset" where
|
||||||
|
# upscope sets it and downscope unsets it.
|
||||||
|
#
|
||||||
|
# We test the following combinations:
|
||||||
|
#
|
||||||
|
# - outer overriding top's values;
|
||||||
|
# - inner overriding top's values;
|
||||||
|
# - inner overriding outer's values; and
|
||||||
|
# - outer overriding inner's values in top after inner has run.
|
||||||
|
|
||||||
|
# Set values for inner to manipulate.
|
||||||
|
set(top_implicit_inner_set top)
|
||||||
|
set(top_implicit_inner_unset)
|
||||||
|
set(top_explicit_inner_set top)
|
||||||
|
set(top_explicit_inner_unset)
|
||||||
|
set(top_explicit_inner_tounset top)
|
||||||
|
|
||||||
|
# Set values for outer to manipulate.
|
||||||
|
set(top_implicit_outer_set top)
|
||||||
|
set(top_implicit_outer_unset)
|
||||||
|
set(top_explicit_outer_set top)
|
||||||
|
set(top_explicit_outer_unset)
|
||||||
|
set(top_explicit_outer_tounset top)
|
||||||
|
|
||||||
|
report("top before calls")
|
||||||
|
|
||||||
|
outer()
|
||||||
|
|
||||||
|
report("top after calls")
|
|
@ -1,3 +1,5 @@
|
||||||
include(RunCMake)
|
include(RunCMake)
|
||||||
|
|
||||||
run_cmake(ParentScope)
|
run_cmake(ParentScope)
|
||||||
|
run_cmake(ParentPulling)
|
||||||
|
run_cmake(ParentPullingRecursive)
|
||||||
|
|
Loading…
Reference in New Issue