From 57bdc1a2f7d416c106c4bef8f3543eec74c3c391 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 May 2015 23:01:29 +0200 Subject: 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 e254e9a..f8a531c 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 2207873..d08b5de 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 586070b..20d303d 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 de6ecde..1e67136 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 0a34be8..322855a 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 95cdf3b..0b7ff33 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 e013f81..5236e57 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 8a72a24..349269e 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 403a459..4245352 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 99542a9..bffcb7c 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 74362ae..a26a90f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -201,19 +201,12 @@ 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, this->StartOutputDirectoryComponents); @@ -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 fa2f712..f08c973 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 82a2939..aa690dc 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 ed58c64..956b4f4 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 5c5c428..706f50f 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 d82087f..577dcd9 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 0fc47b7..e784759 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. -- cgit v0.12 From 991f5e4968ce7b86aea12224b4cecc1be3ed92d9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 May 2015 23:08:19 +0200 Subject: cmState::Snapshot: Store components for current directories. Remove this responsibility from cmLocalGenerator. --- Source/cmLocalGenerator.cxx | 38 ++++++-------------------------------- Source/cmLocalGenerator.h | 4 ---- Source/cmState.cxx | 26 ++++++++++++++++++++++++++ Source/cmState.h | 6 ++++++ 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a26a90f..4e4970d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -67,7 +67,6 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, this->Configured = false; this->EmitUniversalBinaryFlags = true; this->RelativePathsConfigured = false; - this->PathConversionsSetup = false; this->BackwardsCompatibility = 0; this->BackwardsCompatibilityFinal = false; } @@ -196,22 +195,6 @@ void cmLocalGenerator::ReadInputFile() this->Makefile->ProcessBuildsystemFile(currentStart.c_str()); } -void cmLocalGenerator::SetupPathConversions() -{ - // Setup the current output directory components for use by - // Convert - std::string outdir; - - outdir = cmSystemTools::CollapseFullPath( - this->StateSnapshot.GetCurrentSourceDirectory()); - cmSystemTools::SplitPath(outdir, this->StartDirectoryComponents); - - outdir = cmSystemTools::CollapseFullPath - (this->StateSnapshot.GetCurrentBinaryDirectory()); - cmSystemTools::SplitPath(outdir, - this->StartOutputDirectoryComponents); -} - void cmLocalGenerator::ConfigureFinalPass() { this->Makefile->ConfigureFinalPass(); @@ -2698,13 +2681,6 @@ std::string cmLocalGenerator::Convert(const std::string& source, OutputFormat output, bool optional) { - // Make sure the relative path conversion components are set. - if(!this->PathConversionsSetup) - { - this->SetupPathConversions(); - this->PathConversionsSetup = true; - } - // Convert the path to a relative path. std::string result = source; @@ -2719,20 +2695,18 @@ std::string cmLocalGenerator::Convert(const std::string& source, break; case START: //result = cmSystemTools::CollapseFullPath(result.c_str()); - result = this->ConvertToRelativePath(this->StartDirectoryComponents, - result); + result = this->ConvertToRelativePath( + this->StateSnapshot.GetCurrentSourceDirectoryComponents(), result); break; case HOME_OUTPUT: //result = cmSystemTools::CollapseFullPath(result.c_str()); - result = - this->ConvertToRelativePath( - this->GetState()->GetBinaryDirectoryComponents(), result); + result = this->ConvertToRelativePath( + this->GetState()->GetBinaryDirectoryComponents(), result); break; case START_OUTPUT: //result = cmSystemTools::CollapseFullPath(result.c_str()); - result = - this->ConvertToRelativePath(this->StartOutputDirectoryComponents, - result); + result = this->ConvertToRelativePath( + this->StateSnapshot.GetCurrentBinaryDirectoryComponents(), result); break; case FULL: result = cmSystemTools::CollapseFullPath(result); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f08c973..e4d4444 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -443,7 +443,6 @@ protected: void ConfigureRelativePaths(); std::string FindRelativePathTopSource(); std::string FindRelativePathTopBinary(); - void SetupPathConversions(); virtual std::string ConvertToLinkReference(std::string const& lib, OutputFormat format = SHELL); @@ -458,8 +457,6 @@ protected: cmMakefile *Makefile; cmState::Snapshot StateSnapshot; cmGlobalGenerator *GlobalGenerator; - std::vector StartDirectoryComponents; - std::vector StartOutputDirectoryComponents; cmLocalGenerator* Parent; std::vector Children; std::map UniqueObjectNamesMap; @@ -484,7 +481,6 @@ protected: std::string RelativePathTopSource; std::string RelativePathTopBinary; bool RelativePathsConfigured; - bool PathConversionsSetup; cmIML_INT_uint64_t BackwardsCompatibility; bool BackwardsCompatibilityFinal; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index aa690dc..27a36bc 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -197,6 +197,8 @@ void cmState::Initialize() this->Locations.clear(); this->OutputLocations.clear(); this->ParentPositions.clear(); + this->CurrentSourceDirectoryComponents.clear(); + this->CurrentBinaryDirectoryComponents.clear(); this->CreateSnapshot(Snapshot()); this->DefineProperty @@ -500,6 +502,10 @@ cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot) this->ParentPositions.push_back(originSnapshot.Position); this->Locations.resize(this->Locations.size() + 1); this->OutputLocations.resize(this->OutputLocations.size() + 1); + this->CurrentSourceDirectoryComponents.resize( + this->CurrentSourceDirectoryComponents.size() + 1); + this->CurrentBinaryDirectoryComponents.resize( + this->CurrentBinaryDirectoryComponents.size() + 1); return cmState::Snapshot(this, pos); } @@ -523,6 +529,10 @@ void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) this->State->Locations[this->Position]); this->State->Locations[this->Position] = cmSystemTools::CollapseFullPath(this->State->Locations[this->Position]); + + cmSystemTools::SplitPath( + this->State->Locations[this->Position], + this->State->CurrentSourceDirectoryComponents[this->Position]); } const char* cmState::Snapshot::GetCurrentBinaryDirectory() const @@ -539,6 +549,22 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) this->State->OutputLocations[this->Position] = cmSystemTools::CollapseFullPath( this->State->OutputLocations[this->Position]); + + cmSystemTools::SplitPath( + this->State->OutputLocations[this->Position], + this->State->CurrentBinaryDirectoryComponents[this->Position]); +} + +std::vector const& +cmState::Snapshot::GetCurrentSourceDirectoryComponents() +{ + return this->State->CurrentSourceDirectoryComponents[this->Position]; +} + +std::vector const& +cmState::Snapshot::GetCurrentBinaryDirectoryComponents() +{ + return this->State->CurrentBinaryDirectoryComponents[this->Position]; } bool cmState::Snapshot::IsValid() const diff --git a/Source/cmState.h b/Source/cmState.h index 956b4f4..faf0739 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -36,6 +36,9 @@ public: const char* GetCurrentBinaryDirectory() const; void SetCurrentBinaryDirectory(std::string const& dir); + std::vector const& GetCurrentSourceDirectoryComponents(); + std::vector const& GetCurrentBinaryDirectoryComponents(); + bool IsValid() const; Snapshot GetParent() const; @@ -136,6 +139,9 @@ private: std::vector OutputLocations; std::vector ParentPositions; + std::vector > CurrentSourceDirectoryComponents; + std::vector > CurrentBinaryDirectoryComponents; + std::vector SourceDirectoryComponents; std::vector BinaryDirectoryComponents; std::string SourceDirectory; -- cgit v0.12 From 9e4b6cc2cebc7af40432f5027d2960c0cc68515f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 4 May 2015 23:30:29 +0200 Subject: cmState: Store computed relative paths to to current directories. --- Source/cmLocalGenerator.cxx | 107 ++----------------------------- Source/cmLocalGenerator.h | 13 ---- Source/cmLocalUnixMakefileGenerator3.cxx | 11 ++-- Source/cmState.cxx | 106 ++++++++++++++++++++++++++++++ Source/cmState.h | 16 +++++ 5 files changed, 132 insertions(+), 121 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 4e4970d..ea840c5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -66,7 +66,6 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, this->UseRelativePaths = false; this->Configured = false; this->EmitUniversalBinaryFlags = true; - this->RelativePathsConfigured = false; this->BackwardsCompatibility = 0; this->BackwardsCompatibilityFinal = false; } @@ -2779,97 +2778,6 @@ std::string cmLocalGenerator::Convert(RelativeRoot remote, } //---------------------------------------------------------------------------- -std::string cmLocalGenerator::FindRelativePathTopSource() -{ - cmState::Snapshot snapshot = this->StateSnapshot; - std::vector snapshots; - snapshots.push_back(snapshot); - while (true) - { - snapshot = snapshot.GetParent(); - if (snapshot.IsValid()) - { - snapshots.push_back(snapshot); - } - else - { - break; - } - } - - std::string result = snapshots.front().GetCurrentSourceDirectory(); - - for (std::vector::const_iterator it = - snapshots.begin() + 1; it != snapshots.end(); ++it) - { - std::string currentSource = it->GetCurrentSourceDirectory(); - if(cmSystemTools::IsSubDirectory(result, currentSource)) - { - result = currentSource; - } - } - - return result; -} - -//---------------------------------------------------------------------------- -std::string cmLocalGenerator::FindRelativePathTopBinary() -{ - cmState::Snapshot snapshot = this->StateSnapshot; - std::vector snapshots; - snapshots.push_back(snapshot); - while (true) - { - snapshot = snapshot.GetParent(); - if (snapshot.IsValid()) - { - snapshots.push_back(snapshot); - } - else - { - break; - } - } - - std::string result = snapshots.front().GetCurrentBinaryDirectory(); - - for (std::vector::const_iterator it = - snapshots.begin() + 1; it != snapshots.end(); ++it) - { - std::string currentBinary = it->GetCurrentBinaryDirectory(); - if(cmSystemTools::IsSubDirectory(result, currentBinary)) - { - result = currentBinary; - } - } - - return result; -} - -//---------------------------------------------------------------------------- -void cmLocalGenerator::ConfigureRelativePaths() -{ - // Relative path conversion inside the source tree is not used to - // construct relative paths passed to build tools so it is safe to - // even when the source is a network path. - std::string source = this->FindRelativePathTopSource(); - this->RelativePathTopSource = source; - - // The current working directory on Windows cannot be a network - // path. Therefore relative paths cannot work when the binary tree - // is a network path. - std::string binary = this->FindRelativePathTopBinary(); - if(binary.size() < 2 || binary.substr(0, 2) != "//") - { - this->RelativePathTopBinary = binary; - } - else - { - this->RelativePathTopBinary = ""; - } -} - -//---------------------------------------------------------------------------- static bool cmLocalGeneratorNotAbove(const char* a, const char* b) { return (cmSystemTools::ComparePath(a, b) || @@ -2894,26 +2802,19 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector& local, return in_remote; } - // Make sure relative path conversion is configured. - if(!this->RelativePathsConfigured) - { - this->ConfigureRelativePaths(); - this->RelativePathsConfigured = true; - } - if(!force) { // Skip conversion if the path and local are not both in the source // or both in the binary tree. std::string local_path = cmSystemTools::JoinPath(local); if(!((cmLocalGeneratorNotAbove(local_path.c_str(), - this->RelativePathTopBinary.c_str()) && + this->StateSnapshot.GetRelativePathTopBinary()) && cmLocalGeneratorNotAbove(in_remote.c_str(), - this->RelativePathTopBinary.c_str())) || + this->StateSnapshot.GetRelativePathTopBinary())) || (cmLocalGeneratorNotAbove(local_path.c_str(), - this->RelativePathTopSource.c_str()) && + this->StateSnapshot.GetRelativePathTopSource()) && cmLocalGeneratorNotAbove(in_remote.c_str(), - this->RelativePathTopSource.c_str())))) + this->StateSnapshot.GetRelativePathTopSource())))) { return in_remote; } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index e4d4444..5e32794 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -440,10 +440,6 @@ protected: std::string const& dir_max); void ComputeObjectMaxPath(); - void ConfigureRelativePaths(); - std::string FindRelativePathTopSource(); - std::string FindRelativePathTopBinary(); - virtual std::string ConvertToLinkReference(std::string const& lib, OutputFormat format = SHELL); @@ -473,15 +469,6 @@ protected: // committed. std::string TargetImplib; - // The top-most directories for relative path conversion. Both the - // source and destination location of a relative path conversion - // must be underneath one of these directories (both under source or - // both under binary) in order for the relative path to be evaluated - // safely by the build tools. - std::string RelativePathTopSource; - std::string RelativePathTopBinary; - bool RelativePathsConfigured; - cmIML_INT_uint64_t BackwardsCompatibility; bool BackwardsCompatibilityFinal; private: diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index f11c79e..54bff7f 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -545,9 +545,11 @@ void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile() // Setup relative path conversion tops. infoFileStream << "# Relative path conversion top directories.\n" - << "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"" << this->RelativePathTopSource + << "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \"" + << this->StateSnapshot.GetRelativePathTopSource() << "\")\n" - << "set(CMAKE_RELATIVE_PATH_TOP_BINARY \"" << this->RelativePathTopBinary + << "set(CMAKE_RELATIVE_PATH_TOP_BINARY \"" + << this->StateSnapshot.GetRelativePathTopBinary() << "\")\n" << "\n"; @@ -1613,16 +1615,15 @@ cmLocalUnixMakefileGenerator3 } // Setup relative path top directories. - this->RelativePathsConfigured = true; if(const char* relativePathTopSource = mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE")) { - this->RelativePathTopSource = relativePathTopSource; + this->StateSnapshot.SetRelativePathTopSource(relativePathTopSource); } if(const char* relativePathTopBinary = mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY")) { - this->RelativePathTopBinary = relativePathTopBinary; + this->StateSnapshot.SetRelativePathTopBinary(relativePathTopBinary); } } else diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 27a36bc..4965ae3 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -199,6 +199,8 @@ void cmState::Initialize() this->ParentPositions.clear(); this->CurrentSourceDirectoryComponents.clear(); this->CurrentBinaryDirectoryComponents.clear(); + this->RelativePathTopSource.clear(); + this->RelativePathTopBinary.clear(); this->CreateSnapshot(Snapshot()); this->DefineProperty @@ -496,6 +498,86 @@ std::vector const& cmState::GetBinaryDirectoryComponents() const return this->BinaryDirectoryComponents; } +void cmState::Snapshot::ComputeRelativePathTopSource() +{ + // Relative path conversion inside the source tree is not used to + // construct relative paths passed to build tools so it is safe to use + // even when the source is a network path. + + cmState::Snapshot snapshot = *this; + std::vector snapshots; + snapshots.push_back(snapshot); + while (true) + { + snapshot = snapshot.GetParent(); + if (snapshot.IsValid()) + { + snapshots.push_back(snapshot); + } + else + { + break; + } + } + + std::string result = snapshots.front().GetCurrentSourceDirectory(); + + for (std::vector::const_iterator it = + snapshots.begin() + 1; it != snapshots.end(); ++it) + { + std::string currentSource = it->GetCurrentSourceDirectory(); + if(cmSystemTools::IsSubDirectory(result, currentSource)) + { + result = currentSource; + } + } + this->State->RelativePathTopSource[this->Position] = result; +} + +void cmState::Snapshot::ComputeRelativePathTopBinary() +{ + cmState::Snapshot snapshot = *this; + std::vector snapshots; + snapshots.push_back(snapshot); + while (true) + { + snapshot = snapshot.GetParent(); + if (snapshot.IsValid()) + { + snapshots.push_back(snapshot); + } + else + { + break; + } + } + + std::string result = + snapshots.front().GetCurrentBinaryDirectory(); + + for (std::vector::const_iterator it = + snapshots.begin() + 1; it != snapshots.end(); ++it) + { + std::string currentBinary = it->GetCurrentBinaryDirectory(); + if(cmSystemTools::IsSubDirectory(result, currentBinary)) + { + result = currentBinary; + } + } + + // The current working directory on Windows cannot be a network + // path. Therefore relative paths cannot work when the binary tree + // is a network path. + if(result.size() < 2 || result.substr(0, 2) != "//") + { + this->State->RelativePathTopBinary[this->Position] = result; + } + else + { + this->State->RelativePathTopBinary[this->Position] = ""; + } +} + cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot) { PositionType pos = this->ParentPositions.size(); @@ -506,6 +588,8 @@ cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot) this->CurrentSourceDirectoryComponents.size() + 1); this->CurrentBinaryDirectoryComponents.resize( this->CurrentBinaryDirectoryComponents.size() + 1); + this->RelativePathTopSource.resize(this->RelativePathTopSource.size() + 1); + this->RelativePathTopBinary.resize(this->RelativePathTopBinary.size() + 1); return cmState::Snapshot(this, pos); } @@ -533,6 +617,7 @@ void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) cmSystemTools::SplitPath( this->State->Locations[this->Position], this->State->CurrentSourceDirectoryComponents[this->Position]); + this->ComputeRelativePathTopSource(); } const char* cmState::Snapshot::GetCurrentBinaryDirectory() const @@ -553,6 +638,7 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) cmSystemTools::SplitPath( this->State->OutputLocations[this->Position], this->State->CurrentBinaryDirectoryComponents[this->Position]); + this->ComputeRelativePathTopBinary(); } std::vector const& @@ -567,6 +653,26 @@ cmState::Snapshot::GetCurrentBinaryDirectoryComponents() return this->State->CurrentBinaryDirectoryComponents[this->Position]; } +const char* cmState::Snapshot::GetRelativePathTopSource() const +{ + return this->State->RelativePathTopSource[this->Position].c_str(); +} + +const char* cmState::Snapshot::GetRelativePathTopBinary() const +{ + return this->State->RelativePathTopBinary[this->Position].c_str(); +} + +void cmState::Snapshot::SetRelativePathTopSource(const char* dir) +{ + this->State->RelativePathTopSource[this->Position] = dir; +} + +void cmState::Snapshot::SetRelativePathTopBinary(const char* dir) +{ + this->State->RelativePathTopBinary[this->Position] = dir; +} + bool cmState::Snapshot::IsValid() const { return this->State ? true : false; diff --git a/Source/cmState.h b/Source/cmState.h index faf0739..23d3f0d 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -39,10 +39,19 @@ public: std::vector const& GetCurrentSourceDirectoryComponents(); std::vector const& GetCurrentBinaryDirectoryComponents(); + const char* GetRelativePathTopSource() const; + const char* GetRelativePathTopBinary() const; + void SetRelativePathTopSource(const char* dir); + void SetRelativePathTopBinary(const char* dir); + bool IsValid() const; Snapshot GetParent() const; private: + void ComputeRelativePathTopSource(); + void ComputeRelativePathTopBinary(); + + private: friend class cmState; cmState* State; cmState::PositionType Position; @@ -141,6 +150,13 @@ private: std::vector > CurrentSourceDirectoryComponents; std::vector > CurrentBinaryDirectoryComponents; + // The top-most directories for relative path conversion. Both the + // source and destination location of a relative path conversion + // must be underneath one of these directories (both under source or + // both under binary) in order for the relative path to be evaluated + // safely by the build tools. + std::vector RelativePathTopSource; + std::vector RelativePathTopBinary; std::vector SourceDirectoryComponents; std::vector BinaryDirectoryComponents; -- cgit v0.12 From 1933f3d1a3a2be6949c439e18e03a048ef286be7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 16 May 2015 08:02:03 +0200 Subject: cmLocalGenerator: Remove redundant path conversions. The methods just called store the paths in already-converted form. --- Source/cmLocalGenerator.cxx | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ea840c5..406b6f8 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -366,9 +366,6 @@ void cmLocalGenerator::GenerateInstallRules() std::string file = this->StateSnapshot.GetCurrentBinaryDirectory(); std::string homedir = this->GetState()->GetBinaryDirectory(); std::string currdir = this->StateSnapshot.GetCurrentBinaryDirectory(); - cmSystemTools::ConvertToUnixSlashes(file); - cmSystemTools::ConvertToUnixSlashes(homedir); - cmSystemTools::ConvertToUnixSlashes(currdir); int toplevel_install = 0; if ( currdir == homedir ) { -- cgit v0.12 From fa9eb814b36894635e22ffdcac3103ee980b0398 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 16 May 2015 08:03:04 +0200 Subject: cmLocalGenerator: Remove redundant path access. --- Source/cmLocalGenerator.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 406b6f8..528c84e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -365,9 +365,8 @@ void cmLocalGenerator::GenerateInstallRules() // Create the install script file. std::string file = this->StateSnapshot.GetCurrentBinaryDirectory(); std::string homedir = this->GetState()->GetBinaryDirectory(); - std::string currdir = this->StateSnapshot.GetCurrentBinaryDirectory(); int toplevel_install = 0; - if ( currdir == homedir ) + if (file == homedir) { toplevel_install = 1; } -- cgit v0.12