mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-30 10:20:56 -06:00
Merge topic 'block-var-scope'
96ddcbee60cmState: Clarify name of member tracking the active scope in a directorycb53d9309eblock: Fix variable scope protection from modification by subdirectories Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7885
This commit is contained in:
@@ -281,7 +281,7 @@ cmStateSnapshot cmState::Reset()
|
||||
it->CompileOptions.clear();
|
||||
it->LinkOptions.clear();
|
||||
it->LinkDirectories.clear();
|
||||
it->DirectoryEnd = pos;
|
||||
it->CurrentScope = pos;
|
||||
it->NormalTargetNames.clear();
|
||||
it->ImportedTargetNames.clear();
|
||||
it->Properties.Clear();
|
||||
@@ -821,7 +821,7 @@ cmStateSnapshot cmState::CreateBaseSnapshot()
|
||||
pos->CompileOptionsPosition = 0;
|
||||
pos->LinkOptionsPosition = 0;
|
||||
pos->LinkDirectoriesPosition = 0;
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->Policies = this->PolicyStack.Root();
|
||||
pos->PolicyRoot = this->PolicyStack.Root();
|
||||
pos->PolicyScope = this->PolicyStack.Root();
|
||||
@@ -848,7 +848,7 @@ cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
|
||||
originSnapshot.Position->BuildSystemDirectory);
|
||||
pos->ExecutionListFile =
|
||||
this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->Policies = originSnapshot.Position->Policies;
|
||||
pos->PolicyRoot = originSnapshot.Position->Policies;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
@@ -878,7 +878,7 @@ cmStateSnapshot cmState::CreateDeferCallSnapshot(
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Push(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return { this, pos };
|
||||
}
|
||||
@@ -893,7 +893,7 @@ cmStateSnapshot cmState::CreateFunctionCallSnapshot(
|
||||
pos->Keep = false;
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Push(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
|
||||
@@ -912,7 +912,7 @@ cmStateSnapshot cmState::CreateMacroCallSnapshot(
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Push(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return { this, pos };
|
||||
}
|
||||
@@ -927,7 +927,7 @@ cmStateSnapshot cmState::CreateIncludeFileSnapshot(
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Push(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return { this, pos };
|
||||
}
|
||||
@@ -940,6 +940,7 @@ cmStateSnapshot cmState::CreateVariableScopeSnapshot(
|
||||
pos->ScopeParent = originSnapshot.Position;
|
||||
pos->SnapshotType = cmStateEnums::VariableScopeType;
|
||||
pos->Keep = false;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
|
||||
@@ -959,7 +960,7 @@ cmStateSnapshot cmState::CreateInlineListFileSnapshot(
|
||||
pos->Keep = true;
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Push(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return { this, pos };
|
||||
}
|
||||
@@ -971,7 +972,7 @@ cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
|
||||
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
|
||||
pos->SnapshotType = cmStateEnums::PolicyScopeType;
|
||||
pos->Keep = false;
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->BuildSystemDirectory->CurrentScope = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return { this, pos };
|
||||
}
|
||||
@@ -991,7 +992,7 @@ cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
|
||||
prevPos->BuildSystemDirectory->LinkOptions.size();
|
||||
prevPos->LinkDirectoriesPosition =
|
||||
prevPos->BuildSystemDirectory->LinkDirectories.size();
|
||||
prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
|
||||
prevPos->BuildSystemDirectory->CurrentScope = prevPos;
|
||||
|
||||
if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
|
||||
if (pos->Vars != prevPos->Vars) {
|
||||
|
||||
@@ -62,7 +62,7 @@ struct cmStateDetail::PolicyStackEntry : public cmPolicies::PolicyMap
|
||||
|
||||
struct cmStateDetail::BuildsystemDirectoryStateType
|
||||
{
|
||||
cmStateDetail::PositionType DirectoryEnd;
|
||||
cmStateDetail::PositionType CurrentScope;
|
||||
|
||||
std::string Location;
|
||||
std::string OutputLocation;
|
||||
|
||||
@@ -64,7 +64,7 @@ bool cmStateSnapshot::IsValid() const
|
||||
|
||||
cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectory() const
|
||||
{
|
||||
return { this->State, this->Position->BuildSystemDirectory->DirectoryEnd };
|
||||
return { this->State, this->Position->BuildSystemDirectory->CurrentScope };
|
||||
}
|
||||
|
||||
cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectoryParent() const
|
||||
@@ -76,7 +76,7 @@ cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectoryParent() const
|
||||
cmStateDetail::PositionType parentPos = this->Position->DirectoryParent;
|
||||
if (parentPos != this->State->SnapshotData.Root()) {
|
||||
snapshot = cmStateSnapshot(this->State,
|
||||
parentPos->BuildSystemDirectory->DirectoryEnd);
|
||||
parentPos->BuildSystemDirectory->CurrentScope);
|
||||
}
|
||||
|
||||
return snapshot;
|
||||
@@ -177,9 +177,9 @@ cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
|
||||
while (true) {
|
||||
assert(dir.IsValid());
|
||||
cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator leaf =
|
||||
dir->DirectoryEnd->Policies;
|
||||
dir->CurrentScope->Policies;
|
||||
cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator root =
|
||||
dir->DirectoryEnd->PolicyRoot;
|
||||
dir->CurrentScope->PolicyRoot;
|
||||
for (; leaf != root; ++leaf) {
|
||||
if (parent_scope) {
|
||||
parent_scope = false;
|
||||
@@ -190,7 +190,7 @@ cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
|
||||
return status;
|
||||
}
|
||||
}
|
||||
cmStateDetail::PositionType e = dir->DirectoryEnd;
|
||||
cmStateDetail::PositionType e = dir->CurrentScope;
|
||||
cmStateDetail::PositionType p = e->DirectoryParent;
|
||||
if (p == this->State->SnapshotData.Root()) {
|
||||
break;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
set(VAR1 "OUTER1")
|
||||
set(VAR2 "OUTER2")
|
||||
|
||||
set(VARSUB1 "OUTERSUB1")
|
||||
set(VARSUB2 "OUTERSUB2")
|
||||
|
||||
cmake_policy(SET CMP0139 NEW)
|
||||
|
||||
# create a block with a new scope for policies
|
||||
@@ -9,6 +12,7 @@ block(SCOPE_FOR POLICIES)
|
||||
set(VAR1 "INNER1")
|
||||
unset(VAR2)
|
||||
set(VAR3 "INNER3")
|
||||
add_subdirectory(Scope)
|
||||
|
||||
cmake_policy(SET CMP0139 OLD)
|
||||
endblock()
|
||||
@@ -23,6 +27,12 @@ endif()
|
||||
if(NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "INNER3")
|
||||
message(SEND_ERROR "block/endblock: VAR3 has unexpected value: ${VAR3}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB1 OR NOT VARSUB1 STREQUAL "SUBDIR1")
|
||||
message(SEND_ERROR "block/endblock: VARSUB1 has unexpected value: ${VARSUB1}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB2 OR NOT VARSUB2 STREQUAL "SUBDIR2")
|
||||
message(SEND_ERROR "block/endblock: VARSUB2 has unexpected value: ${VARSUB2}")
|
||||
endif()
|
||||
|
||||
cmake_policy(GET CMP0139 CMP0139_STATUS)
|
||||
if(NOT CMP0139_STATUS STREQUAL "NEW")
|
||||
|
||||
@@ -8,16 +8,20 @@ set(VAR5 "OUTER5")
|
||||
set(VAR6 "CACHE6" CACHE STRING "")
|
||||
set(VAR6 "OUTER6")
|
||||
|
||||
set(VARSUB1 "OUTERSUB1")
|
||||
set(VARSUB2 "OUTERSUB2")
|
||||
|
||||
cmake_policy(SET CMP0139 NEW)
|
||||
|
||||
# create a block with a new scope for variables
|
||||
block(SCOPE_FOR VARIABLES PROPAGATE VAR3 VAR4 VAR5 VAR6 VAR7)
|
||||
block(SCOPE_FOR VARIABLES PROPAGATE VAR3 VAR4 VAR5 VAR6 VAR7 VARSUB2)
|
||||
set(VAR1 "INNER1")
|
||||
set(VAR2 "INNER2" PARENT_SCOPE)
|
||||
set(VAR3 "INNER3")
|
||||
unset(VAR4)
|
||||
unset(VAR6)
|
||||
set(VAR7 "INNER7")
|
||||
add_subdirectory(Scope)
|
||||
|
||||
cmake_policy(SET CMP0139 OLD)
|
||||
endblock()
|
||||
@@ -45,6 +49,12 @@ endif()
|
||||
if(NOT DEFINED VAR7 OR NOT VAR7 STREQUAL "INNER7")
|
||||
message(SEND_ERROR "block/endblock: VAR7 has unexpected value: ${VAR7}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB1 OR NOT VARSUB1 STREQUAL "OUTERSUB1")
|
||||
message(SEND_ERROR "block/endblock: VARSUB1 has unexpected value: ${VARSUB1}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB2 OR NOT VARSUB2 STREQUAL "SUBDIR2")
|
||||
message(SEND_ERROR "block/endblock: VARSUB2 has unexpected value: ${VARSUB2}")
|
||||
endif()
|
||||
|
||||
cmake_policy(GET CMP0139 CMP0139_STATUS)
|
||||
if(NOT CMP0139_STATUS STREQUAL "OLD")
|
||||
|
||||
@@ -8,16 +8,20 @@ set(VAR5 "OUTER5")
|
||||
set(VAR6 "CACHE6" CACHE STRING "")
|
||||
set(VAR6 "OUTER6")
|
||||
|
||||
set(VARSUB1 "OUTERSUB1")
|
||||
set(VARSUB2 "OUTERSUB2")
|
||||
|
||||
cmake_policy(SET CMP0139 NEW)
|
||||
|
||||
# create a block with a new scope for variables and policies
|
||||
block(PROPAGATE VAR3 VAR4 VAR5 VAR6 VAR7)
|
||||
block(PROPAGATE VAR3 VAR4 VAR5 VAR6 VAR7 VARSUB2)
|
||||
set(VAR1 "INNER1")
|
||||
set(VAR2 "INNER2" PARENT_SCOPE)
|
||||
set(VAR3 "INNER3")
|
||||
unset(VAR4)
|
||||
unset(VAR6)
|
||||
set(VAR7 "INNER7")
|
||||
add_subdirectory(Scope)
|
||||
|
||||
cmake_policy(SET CMP0139 OLD)
|
||||
endblock()
|
||||
@@ -45,6 +49,12 @@ endif()
|
||||
if(NOT DEFINED VAR7 OR NOT VAR7 STREQUAL "INNER7")
|
||||
message(SEND_ERROR "block/endblock: VAR6 has unexpected value: ${VAR7}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB1 OR NOT VARSUB1 STREQUAL "OUTERSUB1")
|
||||
message(SEND_ERROR "block/endblock: VARSUB1 has unexpected value: ${VARSUB1}")
|
||||
endif()
|
||||
if(NOT DEFINED VARSUB2 OR NOT VARSUB2 STREQUAL "SUBDIR2")
|
||||
message(SEND_ERROR "block/endblock: VARSUB2 has unexpected value: ${VARSUB2}")
|
||||
endif()
|
||||
|
||||
cmake_policy(GET CMP0139 CMP0139_STATUS)
|
||||
if(NOT CMP0139_STATUS STREQUAL "NEW")
|
||||
|
||||
2
Tests/RunCMake/block/Scope/CMakeLists.txt
Normal file
2
Tests/RunCMake/block/Scope/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
set(VARSUB1 "SUBDIR1" PARENT_SCOPE)
|
||||
set(VARSUB2 "SUBDIR2" PARENT_SCOPE)
|
||||
Reference in New Issue
Block a user