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.
This commit is contained in:
Stephen Kelly 2015-05-24 13:00:20 +02:00
parent f69dcdfc38
commit 01e1cd5c1f
5 changed files with 42 additions and 19 deletions

View File

@ -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);
}
};

View File

@ -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;
}

View File

@ -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,

View File

@ -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();
}

View File

@ -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();