From 57bdc1a2f7d416c106c4bef8f3543eec74c3c391 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 May 2015 23:01:29 +0200 Subject: [PATCH] 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. --- Source/CPack/cmCPackGenerator.cxx | 2 ++ Source/CPack/cpack.cxx | 2 ++ Source/CTest/cmCTestBuildAndTestHandler.cxx | 2 ++ Source/CTest/cmCTestLaunch.cxx | 2 ++ Source/CTest/cmCTestScriptHandler.cxx | 2 ++ Source/CTest/cmCTestTestHandler.cxx | 2 ++ Source/CursesDialog/ccmake.cxx | 2 ++ Source/QtDialog/CMakeSetup.cxx | 2 ++ Source/cmCTest.cxx | 2 ++ Source/cmGraphVizWriter.cxx | 2 ++ Source/cmLocalGenerator.cxx | 17 +++++------------ Source/cmLocalGenerator.h | 2 -- Source/cmState.cxx | 18 ++++++++++++++++++ Source/cmState.h | 6 ++++++ Source/cmake.cxx | 5 +++++ Source/cmakemain.cxx | 6 ++++++ Source/ctest.cxx | 2 ++ 17 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index e254e9a84..f8a531cf6 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -711,6 +711,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } cmake cm; + cm.SetHomeDirectory(""); + cm.SetHomeOutputDirectory(""); cm.AddCMakePaths(); cm.SetProgressCallback(cmCPackGeneratorProgress, this); cmGlobalGenerator gg; diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 2207873aa..d08b5de94 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -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); diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index 586070b87..20d303d82 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -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(captureRAII); diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index de6ecde3a..1e6713632 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -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 lg(gg.CreateLocalGenerator()); diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 0a34be88e..322855a08 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -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); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 95cdf3b51..0b7ff3368 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -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 lg(gg.CreateLocalGenerator()); diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index e013f8167..5236e57d5 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -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 generators; hcm.GetGeneratorDocumentation(generators); diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 8a72a2479..349269ee2 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -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 generators; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 403a45937..42453521b 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -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 lg(gg.CreateLocalGenerator()); diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 99542a904..bffcb7c74 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -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 lg(ggi.CreateLocalGenerator()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 74362aeda..a26a90f61 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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()); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index fa2f712b4..f08c97308 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -458,9 +458,7 @@ protected: cmMakefile *Makefile; cmState::Snapshot StateSnapshot; cmGlobalGenerator *GlobalGenerator; - std::vector HomeDirectoryComponents; std::vector StartDirectoryComponents; - std::vector HomeOutputDirectoryComponents; std::vector StartOutputDirectoryComponents; cmLocalGenerator* Parent; std::vector Children; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 82a293973..aa690dc56 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -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 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 const& cmState::GetBinaryDirectoryComponents() const +{ + return this->BinaryDirectoryComponents; +} + cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot) { PositionType pos = this->ParentPositions.size(); diff --git a/Source/cmState.h b/Source/cmState.h index ed58c64c3..956b4f487 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -123,6 +123,9 @@ public: const char* GetBinaryDirectory() const; void SetBinaryDirectory(std::string const& binaryDirectory); + std::vector const& GetSourceDirectoryComponents() const; + std::vector const& GetBinaryDirectoryComponents() const; + private: std::map PropertyDefinitions; std::vector EnabledLanguages; @@ -132,6 +135,9 @@ private: std::vector Locations; std::vector OutputLocations; std::vector ParentPositions; + + std::vector SourceDirectoryComponents; + std::vector BinaryDirectoryComponents; std::string SourceDirectory; std::string BinaryDirectory; bool IsInTryCompile; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5c5c42824..706f50f36 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -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 lg(gg.CreateLocalGenerator()); @@ -2580,6 +2582,9 @@ int cmake::Build(const std::string& dir, const std::vector& nativeOptions, bool clean) { + + this->SetHomeDirectory(""); + this->SetHomeOutputDirectory(""); if(!cmSystemTools::FileIsDirectory(dir)) { std::cerr << "Error: " << dir << " is not a directory\n"; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index d82087f07..577dcd9f7 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -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); diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 0fc47b71e..e7847592d 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -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.