From 84bd7c9e4914bc1781eef3d5c6d05e6f12e17b48 Mon Sep 17 00:00:00 2001 From: Ben Boeckel <ben.boeckel@kitware.com> Date: Wed, 7 Oct 2015 11:50:18 -0400 Subject: [PATCH] SystemTools: support hiding the translation map When determining full paths, CMake would treat the as-called path for the source and build directories as real paths even if they were symlinks. This causes problems when determining the relative path between the source and build directories when they are symlinks. Take the following setup as an example: /mnt/src/project/ src/ build/ -> /mnt/builds/project/build With the translation map and /mnt/src/project/build/ as the build directory, CMake would use ../src as the relative path to the source tree from the build tree rather than ../../../src/project/src and lookups using ../src would fail. If the build directory were instead used *as* /mnt/builds/project/build, everything would work just fine. This patch makes the core logic which does this logic optional so that it can be experimented with in CMake itself. --- CMakeLists.txt | 8 ++++++++ Configure.hxx.in | 5 +++++ SystemTools.cxx | 10 +++++++++- SystemTools.hxx.in | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8577506c..1f2f9aa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,6 +462,14 @@ IF(KWSYS_USE_DynamicLoader) ENDIF() IF(KWSYS_USE_SystemTools) + if (NOT DEFINED KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP) + set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 1) + endif () + if (KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP) + set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 1) + else () + set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 0) + endif () KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_SETENV "Checking whether CXX compiler has setenv" DIRECT) KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UNSETENV diff --git a/Configure.hxx.in b/Configure.hxx.in index d1e7464f..92ffea3c 100644 --- a/Configure.hxx.in +++ b/Configure.hxx.in @@ -11,6 +11,9 @@ /* Whether <ext/stdio_filebuf.h> is available. */ #define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H \ @KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@ +/* Whether the translation map is available or not. */ +#define @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP \ + @KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP@ #if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute) # define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_attribute(x) @@ -56,6 +59,8 @@ @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H # define KWSYS_FALLTHROUGH @KWSYS_NAMESPACE@_FALLTHROUGH # define KWSYS_NULLPTR @KWSYS_NAMESPACE@_NULLPTR +# define KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP \ + @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP #endif #endif diff --git a/SystemTools.cxx b/SystemTools.cxx index b736ed47..ae5374ea 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -453,11 +453,13 @@ class SystemToolsStatic { public: typedef std::map<std::string, std::string> StringMap; +#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP /** * Path translation table from dir to refdir * Each time 'dir' will be found it will be replace by 'refdir' */ StringMap TranslationMap; +#endif #ifdef _WIN32 static std::string GetCasePathName(std::string const& pathIn); static std::string GetActualCaseForPathCached(std::string const& path); @@ -3349,6 +3351,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_relative) return SystemTools::CollapseFullPath(in_relative, KWSYS_NULLPTR); } +#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP void SystemTools::AddTranslationPath(const std::string& a, const std::string& b) { @@ -3412,6 +3415,7 @@ void SystemTools::CheckTranslationPath(std::string& path) // Remove the trailing slash we added before. path.pop_back(); } +#endif static void SystemToolsAppendComponents( std::vector<std::string>& out_components, @@ -3482,6 +3486,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path, // Transform the path back to a string. std::string newPath = SystemTools::JoinPath(out_components); +#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP // Update the translation table with this potentially new path. I am not // sure why this line is here, it seems really questionable, but yet I // would put good money that if I remove it something will break, basically @@ -3497,6 +3502,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path, // SystemTools::AddTranslationPath(newPath, in_path); SystemTools::CheckTranslationPath(newPath); +#endif #ifdef _WIN32 newPath = SystemTools::Statics->GetActualCaseForPathCached(newPath); SystemTools::ConvertToUnixSlashes(newPath); @@ -4737,10 +4743,11 @@ void SystemTools::ClassInitialize() // Create statics singleton instance SystemTools::Statics = new SystemToolsStatic; +#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP // Add some special translation paths for unix. These are not added // for windows because drive letters need to be maintained. Also, // there are not sym-links and mount points on windows anyway. -#if !defined(_WIN32) || defined(__CYGWIN__) +# if !defined(_WIN32) || defined(__CYGWIN__) // The tmp path is frequently a logical path so always keep it: SystemTools::AddKeepPath("/tmp/"); @@ -4778,6 +4785,7 @@ void SystemTools::ClassInitialize() } } } +# endif #endif } diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index cdc9483a..dd1266be 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -891,6 +891,7 @@ public: */ static int GetTerminalWidth(); +#if @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP /** * Add an entry in the path translation table. */ @@ -907,6 +908,7 @@ public: * Update path by going through the Path Translation table; */ static void CheckTranslationPath(std::string& path); +#endif /** * Delay the execution for a specified amount of time specified -- GitLab