diff options
author | Stephen Kelly <steveire@gmail.com> | 2015-05-24 11:00:20 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-05-24 11:30:24 (GMT) |
commit | 01e1cd5c1fc5e2684ec69d4916dd31ed23746055 (patch) | |
tree | 554d47feea8bc7a28abb753df88ab108c9997c9b /Source | |
parent | f69dcdfc380176a2c4365357c1ca85c0444087b0 (diff) | |
download | CMake-01e1cd5c1fc5e2684ec69d4916dd31ed23746055.zip CMake-01e1cd5c1fc5e2684ec69d4916dd31ed23746055.tar.gz CMake-01e1cd5c1fc5e2684ec69d4916dd31ed23746055.tar.bz2 |
cmState: Move snapshot creation to the cmake instance.
Don't create a snapshot in Initialize(), but leave the creation
responsibility to the cmake instance instead. Previously, the
cmState would Initialize() in its constructor, and the cmake instance
would re-Initialize() during Configure(). The end result was the
same and there would be one snapshot present. However, cmLocalGenerator
also created a snapshot on construction, and that one was used, leaving
the first snapshot unused, and potential for off-by-one errors.
Fix that by making the cmLocalGenerator use the existing snapshot
if it is top-level. Add a CurrentSnapshot to the cmake instance and
populated it while configuring a directory. This will eventually
replace the 'current local generator' concept. Fix the GetParent
implementation to be able to return the first snapshot.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmState.cxx | 45 | ||||
-rw-r--r-- | Source/cmState.h | 2 | ||||
-rw-r--r-- | Source/cmake.cxx | 3 | ||||
-rw-r--r-- | Source/cmake.h | 5 |
5 files changed, 43 insertions, 20 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c2e996c..442b9bf 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -56,9 +56,9 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, } else { - this->StateSnapshot = - this->GetState()->CreateSnapshot(cmState::Snapshot(this->GetState())); + this->StateSnapshot = gg->GetCMakeInstance()->GetCurrentSnapshot(); } + this->Makefile = new cmMakefile(this); this->LinkScriptShell = false; @@ -84,11 +84,14 @@ class cmLocalGeneratorCurrent { cmGlobalGenerator* GG; cmLocalGenerator* LG; + cmState::Snapshot Snapshot; public: cmLocalGeneratorCurrent(cmLocalGenerator* lg) { this->GG = lg->GetGlobalGenerator(); this->LG = this->GG->GetCurrentLocalGenerator(); + this->Snapshot = this->GG->GetCMakeInstance()->GetCurrentSnapshot(); + this->GG->GetCMakeInstance()->SetCurrentSnapshot(lg->GetStateSnapshot()); this->GG->SetCurrentLocalGenerator(lg); #if defined(CMAKE_BUILD_WITH_CMAKE) this->GG->GetFileLockPool().PushFileScope(); @@ -100,6 +103,7 @@ public: this->GG->GetFileLockPool().PopFileScope(); #endif this->GG->SetCurrentLocalGenerator(this->LG); + this->GG->GetCMakeInstance()->SetCurrentSnapshot(this->Snapshot); } }; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 4965ae3..389a316 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -22,7 +22,6 @@ cmState::cmState(cmake* cm) : CMakeInstance(cm), IsInTryCompile(false) { - this->Initialize(); } cmState::~cmState() @@ -190,19 +189,35 @@ void cmState::RemoveCacheEntryProperty(std::string const& key, ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0); } -void cmState::Initialize() +void cmState::Reset() { this->GlobalProperties.clear(); this->PropertyDefinitions.clear(); - this->Locations.clear(); - this->OutputLocations.clear(); - this->ParentPositions.clear(); - this->CurrentSourceDirectoryComponents.clear(); - this->CurrentBinaryDirectoryComponents.clear(); - this->RelativePathTopSource.clear(); - this->RelativePathTopBinary.clear(); - - this->CreateSnapshot(Snapshot()); + + assert(this->Locations.size() > 0); + assert(this->OutputLocations.size() > 0); + assert(this->ParentPositions.size() > 0); + assert(this->CurrentSourceDirectoryComponents.size() > 0); + assert(this->CurrentBinaryDirectoryComponents.size() > 0); + assert(this->RelativePathTopSource.size() > 0); + assert(this->RelativePathTopBinary.size() > 0); + + this->Locations.erase(this->Locations.begin() + 1, this->Locations.end()); + this->OutputLocations.erase(this->OutputLocations.begin() + 1, + this->OutputLocations.end()); + this->ParentPositions.erase(this->ParentPositions.begin() + 1, + this->ParentPositions.end()); + this->CurrentSourceDirectoryComponents.erase( + this->CurrentSourceDirectoryComponents.begin() + 1, + this->CurrentSourceDirectoryComponents.end()); + this->CurrentBinaryDirectoryComponents.erase( + this->CurrentBinaryDirectoryComponents.begin() + 1, + this->CurrentBinaryDirectoryComponents.end()); + this->RelativePathTopSource.erase(this->RelativePathTopSource.begin() + 1, + this->RelativePathTopSource.end()); + this->RelativePathTopBinary.erase(this->RelativePathTopBinary.begin() + 1, + this->RelativePathTopBinary.end()); + this->DefineProperty ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "", true); @@ -607,6 +622,7 @@ const char* cmState::Snapshot::GetCurrentSourceDirectory() const void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) { + assert(this->State); assert(this->State->Locations.size() > this->Position); this->State->Locations[this->Position] = dir; cmSystemTools::ConvertToUnixSlashes( @@ -681,15 +697,12 @@ bool cmState::Snapshot::IsValid() const cmState::Snapshot cmState::Snapshot::GetParent() const { Snapshot snapshot; - if (!this->State) + if (!this->State || this->Position == 0) { return snapshot; } PositionType parentPos = this->State->ParentPositions[this->Position]; - if (parentPos > 0) - { - snapshot = Snapshot(this->State, parentPos); - } + snapshot = Snapshot(this->State, parentPos); return snapshot; } diff --git a/Source/cmState.h b/Source/cmState.h index 23d3f0d..424fe45 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -93,7 +93,7 @@ public: void RemoveCacheEntryProperty(std::string const& key, std::string const& propertyName); - void Initialize(); + void Reset(); // Define a property void DefineProperty(const std::string& name, cmProperty::ScopeType scope, const char *ShortDescription, diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1c9842e..3ef85b6 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -134,6 +134,7 @@ cmake::cmake() this->Policies = new cmPolicies(); this->State = new cmState(this); + this->CurrentSnapshot = this->State->CreateSnapshot(cmState::Snapshot()); #ifdef __APPLE__ struct rlimit rlp; @@ -185,7 +186,7 @@ cmake::~cmake() void cmake::CleanupCommandsAndMacros() { - this->State->Initialize(); + this->State->Reset(); this->State->RemoveUserDefinedCommands(); } diff --git a/Source/cmake.h b/Source/cmake.h index c0a9b49..12b7e68 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -316,6 +316,10 @@ class cmake void WatchUnusedCli(const std::string& var); cmState* GetState() const { return this->State; } + void SetCurrentSnapshot(cmState::Snapshot snapshot) + { this->CurrentSnapshot = snapshot; } + cmState::Snapshot GetCurrentSnapshot() const + { return this->CurrentSnapshot; } protected: void RunCheckForUnusedVariables(); @@ -396,6 +400,7 @@ private: InstalledFilesMap InstalledFiles; cmState* State; + cmState::Snapshot CurrentSnapshot; void UpdateConversionPathTable(); |