cmLocalGenerator: Require a valid cmState::Snapshot in the ctor.

Refactor the local generator creation API to accept a
cmState::Snapshot.  Adjust MakeLocalGenerator to use the 'current'
snapshot in cases where there is no parent.  Create the snapshot
for subdirectories in cmMakefile::AddSubdirectory.

This means that snapshots are now created at the point of extending the tree,
as appropriate, and independently of the cmLocalGenerator and cmMakefile they
represent the state for.
This commit is contained in:
Stephen Kelly 2015-05-24 11:50:55 +02:00 committed by Brad King
parent e12afe766e
commit 3b880a0741
38 changed files with 111 additions and 64 deletions

View File

@ -44,10 +44,10 @@ void cmGlobalBorlandMakefileGenerator
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalBorlandMakefileGenerator::CreateLocalGenerator(
cmLocalGenerator* parent)
cmLocalGenerator* parent, cmState::Snapshot snapshot)
{
cmLocalUnixMakefileGenerator3* lg =
new cmLocalUnixMakefileGenerator3(this, parent);
new cmLocalUnixMakefileGenerator3(this, parent, snapshot);
lg->SetMakefileVariableSize(32);
lg->SetMakeCommandEscapeTargetTwice(true);
lg->SetBorlandMakeCurlyHack(true);

View File

@ -36,7 +36,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/**
* Try to determine system information such as shared library

View File

@ -1884,15 +1884,22 @@ void cmGlobalGenerator::EnableInstallTarget()
}
cmLocalGenerator *
cmGlobalGenerator::MakeLocalGenerator(cmLocalGenerator *parent)
cmGlobalGenerator::MakeLocalGenerator(cmState::Snapshot snapshot,
cmLocalGenerator *parent)
{
return this->CreateLocalGenerator(parent);
if (!snapshot.IsValid())
{
snapshot = this->CMakeInstance->GetCurrentSnapshot();
}
return this->CreateLocalGenerator(parent, snapshot);
}
cmLocalGenerator *
cmGlobalGenerator::CreateLocalGenerator(cmLocalGenerator *parent)
cmLocalGenerator*
cmGlobalGenerator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalGenerator(this, parent);
return new cmLocalGenerator(this, parent, snapshot);
}
void cmGlobalGenerator::EnableLanguagesFromGenerator(cmGlobalGenerator *gen,

View File

@ -21,6 +21,7 @@
#include "cmExportSetMap.h" // For cmExportSetMap
#include "cmGeneratorTarget.h"
#include "cmGeneratorExpression.h"
#include "cmState.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include "cmFileLockPool.h"
@ -56,7 +57,9 @@ public:
cmGlobalGenerator(cmake* cm);
virtual ~cmGlobalGenerator();
cmLocalGenerator* MakeLocalGenerator(cmLocalGenerator* parent = 0);
cmLocalGenerator* MakeLocalGenerator(
cmState::Snapshot snapshot = cmState::Snapshot(),
cmLocalGenerator* parent = 0);
///! Get the name for this generator
virtual std::string GetName() const { return "Generic"; }
@ -441,7 +444,8 @@ protected:
private:
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
cmMakefile* TryCompileOuterMakefile;
float FirstTimeProgress;

View File

@ -33,9 +33,10 @@ cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator()
}
cmLocalGenerator *
cmGlobalGhsMultiGenerator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalGhsMultiGenerator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalGhsMultiGenerator(this, parent);
return new cmLocalGhsMultiGenerator(this, parent, snapshot);
}
void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry &entry)

View File

@ -31,7 +31,8 @@ public:
{ return new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>(); }
///! create the correct local generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/// @return the name of this generator.
static std::string GetActualName() { return "Green Hills MULTI"; }

View File

@ -529,9 +529,10 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
// Virtual public methods.
cmLocalGenerator*
cmGlobalNinjaGenerator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalNinjaGenerator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalNinjaGenerator(this, parent);
return new cmLocalNinjaGenerator(this, parent, snapshot);
}
void cmGlobalNinjaGenerator

View File

@ -170,7 +170,8 @@ public:
virtual ~cmGlobalNinjaGenerator() { }
/// Overloaded methods. @see cmGlobalGenerator::CreateLocalGenerator()
virtual cmLocalGenerator* CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator* CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/// Overloaded methods. @see cmGlobalGenerator::GetName().
virtual std::string GetName() const {

View File

@ -60,9 +60,10 @@ void cmGlobalUnixMakefileGenerator3
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *
cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalUnixMakefileGenerator3(this, parent);
return new cmLocalUnixMakefileGenerator3(this, parent, snapshot);
}
//----------------------------------------------------------------------------

View File

@ -68,7 +68,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
///! Create a local generator appropriate to this Global Generator3
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/**
* Try to determine system information such as shared library

View File

@ -307,9 +307,10 @@ void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *
cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalVisualStudio10Generator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalVisualStudio10Generator(this, parent);
return new cmLocalVisualStudio10Generator(this, parent, snapshot);
}
//----------------------------------------------------------------------------

View File

@ -46,7 +46,8 @@ public:
);
///! create the correct local generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/**
* Try to determine system information such as shared library

View File

@ -173,9 +173,10 @@ cmGlobalVisualStudio6Generator::GenerateBuildCommand(
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *
cmGlobalVisualStudio6Generator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalVisualStudio6Generator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalVisualStudio6Generator(this, parent);
return new cmLocalVisualStudio6Generator(this, parent, snapshot);
}

View File

@ -39,7 +39,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/**
* Try to determine system information such as shared library

View File

@ -279,10 +279,11 @@ void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *
cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
cmLocalVisualStudio7Generator *lg =
new cmLocalVisualStudio7Generator(this, parent);
new cmLocalVisualStudio7Generator(this, parent, snapshot);
return lg;
}

View File

@ -43,7 +43,8 @@ public:
std::string const& GetPlatformName() const;
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual bool SetSystemName(std::string const& s, cmMakefile* mf);

View File

@ -371,9 +371,10 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
//----------------------------------------------------------------------------
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *
cmGlobalXCodeGenerator::CreateLocalGenerator(cmLocalGenerator* parent)
cmGlobalXCodeGenerator::CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot)
{
return new cmLocalXCodeGenerator(this, parent);
return new cmLocalXCodeGenerator(this, parent, snapshot);
}
//----------------------------------------------------------------------------

View File

@ -41,7 +41,8 @@ public:
static void GetDocumentation(cmDocumentationEntry& entry);
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent = 0);
virtual cmLocalGenerator *CreateLocalGenerator(cmLocalGenerator* parent,
cmState::Snapshot snapshot);
/**
* Try to determine system information such as shared library

View File

@ -44,19 +44,16 @@
#endif
cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: StateSnapshot(snapshot)
{
assert(snapshot.IsValid());
this->GlobalGenerator = gg;
this->Parent = parent;
if (parent)
{
parent->AddChild(this);
this->StateSnapshot =
this->GetState()->CreateSnapshot(parent->StateSnapshot);
}
else
{
this->StateSnapshot = gg->GetCMakeInstance()->GetCurrentSnapshot();
}
this->Makefile = new cmMakefile(this);

View File

@ -34,7 +34,8 @@ class cmCustomCommandGenerator;
class cmLocalGenerator
{
public:
cmLocalGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent);
cmLocalGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalGenerator();
/// @return whether we are processing the top CMakeLists.txt file.

View File

@ -17,8 +17,9 @@
#include "cmGeneratedFileStream.h"
cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent)
: cmLocalGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: cmLocalGenerator(gg, parent, snapshot)
{
}

View File

@ -25,7 +25,8 @@ class cmGeneratedFileStream;
class cmLocalGhsMultiGenerator : public cmLocalGenerator
{
public:
cmLocalGhsMultiGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent);
cmLocalGhsMultiGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalGhsMultiGenerator();

View File

@ -23,8 +23,9 @@
#include <assert.h>
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent)
: cmLocalGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: cmLocalGenerator(gg, parent, snapshot)
, ConfigName("")
, HomeRelativeOutputPath("")
{

View File

@ -31,7 +31,8 @@ class cmake;
class cmLocalNinjaGenerator : public cmLocalGenerator
{
public:
cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent);
cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalNinjaGenerator();

View File

@ -80,8 +80,9 @@ static std::string cmSplitExtension(std::string const& in, std::string& base)
//----------------------------------------------------------------------------
cmLocalUnixMakefileGenerator3::
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmLocalGenerator* parent)
: cmLocalGenerator(gg, parent)
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: cmLocalGenerator(gg, parent, snapshot)
{
this->MakefileVariableSize = 0;
this->ColorMakefile = false;

View File

@ -35,7 +35,8 @@ class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
{
public:
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg,
cmLocalGenerator* parent);
cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalUnixMakefileGenerator3();
/**

View File

@ -63,8 +63,9 @@ class cmVS10XMLParser : public cmXMLParser
//----------------------------------------------------------------------------
cmLocalVisualStudio10Generator
::cmLocalVisualStudio10Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent):
cmLocalVisualStudio7Generator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot):
cmLocalVisualStudio7Generator(gg, parent, snapshot)
{
}

View File

@ -26,7 +26,8 @@ class cmLocalVisualStudio10Generator : public cmLocalVisualStudio7Generator
public:
///! Set cache only and recurse to false by default.
cmLocalVisualStudio10Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent);
cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalVisualStudio10Generator();

View File

@ -25,8 +25,9 @@
cmLocalVisualStudio6Generator
::cmLocalVisualStudio6Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent):
cmLocalVisualStudioGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot):
cmLocalVisualStudioGenerator(gg, parent, snapshot)
{
}

View File

@ -30,7 +30,8 @@ class cmLocalVisualStudio6Generator : public cmLocalVisualStudioGenerator
public:
///! Set cache only and recurse to false by default.
cmLocalVisualStudio6Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent);
cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalVisualStudio6Generator();

View File

@ -56,8 +56,9 @@ static void cmConvertToWindowsSlash(std::string& s)
//----------------------------------------------------------------------------
cmLocalVisualStudio7Generator
::cmLocalVisualStudio7Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent):
cmLocalVisualStudioGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot):
cmLocalVisualStudioGenerator(gg, parent, snapshot)
{
this->Internal = new cmLocalVisualStudio7GeneratorInternals(this);
}

View File

@ -36,7 +36,8 @@ class cmLocalVisualStudio7Generator : public cmLocalVisualStudioGenerator
public:
///! Set cache only and recurse to false by default.
cmLocalVisualStudio7Generator(cmGlobalGenerator* gg,
cmLocalGenerator* parent);
cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalVisualStudio7Generator();

View File

@ -20,8 +20,9 @@
//----------------------------------------------------------------------------
cmLocalVisualStudioGenerator
::cmLocalVisualStudioGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent)
: cmLocalGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: cmLocalGenerator(gg, parent, snapshot)
{
}

View File

@ -32,7 +32,8 @@ class cmLocalVisualStudioGenerator : public cmLocalGenerator
{
public:
cmLocalVisualStudioGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent);
cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalVisualStudioGenerator();
/** Construct a script from the given list of command lines. */

View File

@ -16,8 +16,9 @@
//----------------------------------------------------------------------------
cmLocalXCodeGenerator::cmLocalXCodeGenerator(cmGlobalGenerator* gg,
cmLocalGenerator* parent)
: cmLocalGenerator(gg, parent)
cmLocalGenerator* parent,
cmState::Snapshot snapshot)
: cmLocalGenerator(gg, parent, snapshot)
{
// the global generator does this, so do not
// put these flags into the language flags

View File

@ -24,7 +24,8 @@ class cmLocalXCodeGenerator : public cmLocalGenerator
{
public:
///! Set cache only and recurse to false by default.
cmLocalXCodeGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent);
cmLocalXCodeGenerator(cmGlobalGenerator* gg, cmLocalGenerator* parent,
cmState::Snapshot snapshot);
virtual ~cmLocalXCodeGenerator();
virtual std::string GetTargetDirectory(cmTarget const& target) const;

View File

@ -1625,9 +1625,12 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
return;
}
cmState::Snapshot newSnapshot = this->GetState()
->CreateSnapshot(this->StateSnapshot);
// create a new local generator and set its parent
cmLocalGenerator *lg2 = this->GetGlobalGenerator()
->MakeLocalGenerator(this->LocalGenerator);
->MakeLocalGenerator(newSnapshot, this->LocalGenerator);
this->GetGlobalGenerator()->AddLocalGenerator(lg2);
// set the subdirs start dirs

View File

@ -661,6 +661,10 @@ void cmState::Snapshot::ComputeRelativePathTopBinary()
cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot)
{
if (!originSnapshot.IsValid())
{
originSnapshot.State = this;
}
PositionType pos = this->ParentPositions.size();
this->ParentPositions.push_back(originSnapshot.Position);
this->Locations.resize(this->Locations.size() + 1);