cmState: Compute and store directory components.

There is no need to duplicate these in all cmLocalGenerators.

Rename the symbols according to current conventions.

Add explicit calls to Set{Source,Binary}Directory with empty strings
in order to trigger the population of the components containers with
the current working directory in cmLocalGenerator.  Having
directories set to empty is a special case in CMake, which is relied
on for the `if(CMAKE_BINARY_DIR)` condition at the end of
CMakeDetermineSystem.cmake.
This commit is contained in:
Stephen Kelly 2015-05-04 23:01:29 +02:00
parent ebf8a41984
commit 57bdc1a2f7
17 changed files with 62 additions and 14 deletions

View File

@ -711,6 +711,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
}
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.AddCMakePaths();
cm.SetProgressCallback(cmCPackGeneratorProgress, this);
cmGlobalGenerator gg;

View File

@ -198,6 +198,8 @@ int main (int argc, char const* const* argv)
"Read CPack config file: " << cpackConfigFile << std::endl);
cmake cminst;
cminst.SetHomeDirectory("");
cminst.SetHomeOutputDirectory("");
cminst.GetState()->RemoveUnscriptableCommands();
cmGlobalGenerator cmgg;
cmgg.SetCMakeInstance(&cminst);

View File

@ -204,6 +204,8 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
std::string cmakeOutString;
cmCTestBuildAndTestCaptureRAII captureRAII(cm, cmakeOutString);
static_cast<void>(captureRAII);

View File

@ -750,6 +750,8 @@ int cmCTestLaunch::Main(int argc, const char* const argv[])
void cmCTestLaunch::LoadConfig()
{
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());

View File

@ -336,6 +336,8 @@ void cmCTestScriptHandler::CreateCMake()
delete this->LocalGenerator;
}
this->CMake = new cmake;
this->CMake->SetHomeDirectory("");
this->CMake->SetHomeOutputDirectory("");
this->CMake->AddCMakePaths();
this->GlobalGenerator = new cmGlobalGenerator;
this->GlobalGenerator->SetCMakeInstance(this->CMake);

View File

@ -1571,6 +1571,8 @@ void cmCTestTestHandler::GetListOfTests()
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Constructing a list of tests" << std::endl, this->Quiet);
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());

View File

@ -104,6 +104,8 @@ int main(int argc, char const* const* argv)
if(doc.CheckOptions(argc, argv))
{
cmake hcm;
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
std::vector<cmDocumentationEntry> generators;
hcm.GetGeneratorDocumentation(generators);

View File

@ -64,6 +64,8 @@ int main(int argc, char** argv)
{
// Construct and print requested documentation.
cmake hcm;
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
std::vector<cmDocumentationEntry> generators;

View File

@ -510,6 +510,8 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
}
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());

View File

@ -65,6 +65,8 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
const char* fallbackSettingsFileName)
{
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmGlobalGenerator ggi;
ggi.SetCMakeInstance(&cm);
cmsys::auto_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator());

View File

@ -201,18 +201,11 @@ void cmLocalGenerator::SetupPathConversions()
// Setup the current output directory components for use by
// Convert
std::string outdir;
outdir =
cmSystemTools::CollapseFullPath(this->GetState()->GetSourceDirectory());
cmSystemTools::SplitPath(outdir, this->HomeDirectoryComponents);
outdir = cmSystemTools::CollapseFullPath(
this->StateSnapshot.GetCurrentSourceDirectory());
cmSystemTools::SplitPath(outdir, this->StartDirectoryComponents);
outdir = cmSystemTools::CollapseFullPath
(this->GetState()->GetBinaryDirectory());
cmSystemTools::SplitPath(outdir,
this->HomeOutputDirectoryComponents);
outdir = cmSystemTools::CollapseFullPath
(this->StateSnapshot.GetCurrentBinaryDirectory());
cmSystemTools::SplitPath(outdir,
@ -2721,8 +2714,8 @@ std::string cmLocalGenerator::Convert(const std::string& source,
{
case HOME:
//result = cmSystemTools::CollapseFullPath(result.c_str());
result = this->ConvertToRelativePath(this->HomeDirectoryComponents,
result);
result = this->ConvertToRelativePath(
this->GetState()->GetSourceDirectoryComponents(), result);
break;
case START:
//result = cmSystemTools::CollapseFullPath(result.c_str());
@ -2732,8 +2725,8 @@ std::string cmLocalGenerator::Convert(const std::string& source,
case HOME_OUTPUT:
//result = cmSystemTools::CollapseFullPath(result.c_str());
result =
this->ConvertToRelativePath(this->HomeOutputDirectoryComponents,
result);
this->ConvertToRelativePath(
this->GetState()->GetBinaryDirectoryComponents(), result);
break;
case START_OUTPUT:
//result = cmSystemTools::CollapseFullPath(result.c_str());

View File

@ -458,9 +458,7 @@ protected:
cmMakefile *Makefile;
cmState::Snapshot StateSnapshot;
cmGlobalGenerator *GlobalGenerator;
std::vector<std::string> HomeDirectoryComponents;
std::vector<std::string> StartDirectoryComponents;
std::vector<std::string> HomeOutputDirectoryComponents;
std::vector<std::string> StartOutputDirectoryComponents;
cmLocalGenerator* Parent;
std::vector<cmLocalGenerator*> Children;

View File

@ -458,6 +458,10 @@ void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
this->SourceDirectory = sourceDirectory;
cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
cmSystemTools::SplitPath(
cmSystemTools::CollapseFullPath(this->SourceDirectory),
this->SourceDirectoryComponents);
}
const char* cmState::GetSourceDirectory() const
@ -465,10 +469,19 @@ const char* cmState::GetSourceDirectory() const
return this->SourceDirectory.c_str();
}
std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
{
return this->SourceDirectoryComponents;
}
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
this->BinaryDirectory = binaryDirectory;
cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
cmSystemTools::SplitPath(
cmSystemTools::CollapseFullPath(this->BinaryDirectory),
this->BinaryDirectoryComponents);
}
const char* cmState::GetBinaryDirectory() const
@ -476,6 +489,11 @@ const char* cmState::GetBinaryDirectory() const
return this->BinaryDirectory.c_str();
}
std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
{
return this->BinaryDirectoryComponents;
}
cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot)
{
PositionType pos = this->ParentPositions.size();

View File

@ -123,6 +123,9 @@ public:
const char* GetBinaryDirectory() const;
void SetBinaryDirectory(std::string const& binaryDirectory);
std::vector<std::string> const& GetSourceDirectoryComponents() const;
std::vector<std::string> const& GetBinaryDirectoryComponents() const;
private:
std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
std::vector<std::string> EnabledLanguages;
@ -132,6 +135,9 @@ private:
std::vector<std::string> Locations;
std::vector<std::string> OutputLocations;
std::vector<PositionType> ParentPositions;
std::vector<std::string> SourceDirectoryComponents;
std::vector<std::string> BinaryDirectoryComponents;
std::string SourceDirectory;
std::string BinaryDirectory;
bool IsInTryCompile;

View File

@ -1925,6 +1925,8 @@ int cmake::CheckBuildSystem()
// Read the rerun check file and use it to decide whether to do the
// global generate.
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
@ -2580,6 +2582,9 @@ int cmake::Build(const std::string& dir,
const std::vector<std::string>& nativeOptions,
bool clean)
{
this->SetHomeDirectory("");
this->SetHomeOutputDirectory("");
if(!cmSystemTools::FileIsDirectory(dir))
{
std::cerr << "Error: " << dir << " is not a directory\n";

View File

@ -214,6 +214,8 @@ int do_cmake(int ac, char const* const* av)
{
// Construct and print requested documentation.
cmake hcm;
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
// the command line args are processed here so that you can do
@ -317,10 +319,14 @@ int do_cmake(int ac, char const* const* av)
if (sysinfo)
{
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
int ret = cm.GetSystemInformation(args);
return ret;
}
cmake cm;
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void *)&cm);
cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm);
cm.SetWorkingMode(workingMode);

View File

@ -160,6 +160,8 @@ int main (int argc, char const* const* argv)
if(doc.CheckOptions(argc, argv))
{
cmake hcm;
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
// Construct and print requested documentation.