summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-08 13:59:54 +0000
committerKitware Robot <kwrobot@kitware.com>2022-11-08 09:00:13 -0500
commitf7c29ba254abd89640c9ac2c40fc68f065017b63 (patch)
treee148a321427f9b6c7dfe73d13cde648fc1ee161e
parentdb2444200794cd459f19c22bb40cf1fb385807a7 (diff)
parent96ddcbee60ee304efd047bc0e20cf89066877ab5 (diff)
downloadcmake-f7c29ba254abd89640c9ac2c40fc68f065017b63.tar.gz
Merge topic 'block-var-scope' into release-3.25
96ddcbee60 cmState: Clarify name of member tracking the active scope in a directory cb53d9309e block: Fix variable scope protection from modification by subdirectories Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7885
-rw-r--r--Source/cmState.cxx21
-rw-r--r--Source/cmStatePrivate.h2
-rw-r--r--Source/cmStateSnapshot.cxx10
-rw-r--r--Tests/RunCMake/block/Scope-POLICIES.cmake10
-rw-r--r--Tests/RunCMake/block/Scope-VARIABLES.cmake12
-rw-r--r--Tests/RunCMake/block/Scope.cmake12
-rw-r--r--Tests/RunCMake/block/Scope/CMakeLists.txt2
7 files changed, 51 insertions, 18 deletions
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 3d38e734af..e54ccfc1a0 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -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();
@@ -819,7 +819,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();
@@ -846,7 +846,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;
@@ -876,7 +876,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 };
}
@@ -891,7 +891,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;
@@ -910,7 +910,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 };
}
@@ -925,7 +925,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 };
}
@@ -938,6 +938,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());
@@ -957,7 +958,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 };
}
@@ -969,7 +970,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 };
}
@@ -989,7 +990,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) {
diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h
index fd46eedfa2..ec14834d1d 100644
--- a/Source/cmStatePrivate.h
+++ b/Source/cmStatePrivate.h
@@ -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;
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index c51650ac64..cb5f11f930 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -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;
diff --git a/Tests/RunCMake/block/Scope-POLICIES.cmake b/Tests/RunCMake/block/Scope-POLICIES.cmake
index 789b3d9d97..9536a99755 100644
--- a/Tests/RunCMake/block/Scope-POLICIES.cmake
+++ b/Tests/RunCMake/block/Scope-POLICIES.cmake
@@ -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")
diff --git a/Tests/RunCMake/block/Scope-VARIABLES.cmake b/Tests/RunCMake/block/Scope-VARIABLES.cmake
index 140e63880f..ac8da140c0 100644
--- a/Tests/RunCMake/block/Scope-VARIABLES.cmake
+++ b/Tests/RunCMake/block/Scope-VARIABLES.cmake
@@ -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")
diff --git a/Tests/RunCMake/block/Scope.cmake b/Tests/RunCMake/block/Scope.cmake
index e1af50a256..ef43df6043 100644
--- a/Tests/RunCMake/block/Scope.cmake
+++ b/Tests/RunCMake/block/Scope.cmake
@@ -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")
diff --git a/Tests/RunCMake/block/Scope/CMakeLists.txt b/Tests/RunCMake/block/Scope/CMakeLists.txt
new file mode 100644
index 0000000000..afd79e301b
--- /dev/null
+++ b/Tests/RunCMake/block/Scope/CMakeLists.txt
@@ -0,0 +1,2 @@
+set(VARSUB1 "SUBDIR1" PARENT_SCOPE)
+set(VARSUB2 "SUBDIR2" PARENT_SCOPE)