diff options
author | Nils Gladitz <nilsgladitz@gmail.com> | 2015-04-09 18:56:43 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-04-13 12:59:34 (GMT) |
commit | a198839a7b110a47d76d47e342b1c63f908e6878 (patch) | |
tree | 64a03ec951d59b32d9ba4c6243a5bf072505cb20 /Source | |
parent | 48040c19d5f1bcec55a130fcf8f8d83db27291b4 (diff) | |
download | CMake-a198839a7b110a47d76d47e342b1c63f908e6878.zip CMake-a198839a7b110a47d76d47e342b1c63f908e6878.tar.gz CMake-a198839a7b110a47d76d47e342b1c63f908e6878.tar.bz2 |
CTest: Fix locale used for VCS updates
6a661f06030b85b4484733375bbb0aa23eca7446 fixed the
locale used for message output but at the same time broke the locale
used for filename encodings.
This commit preserves LC_CTYPE in the presence of LC_ALL.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/CTest/cmCTestUpdateHandler.cxx | 43 | ||||
-rw-r--r-- | Source/cmCLocaleEnvironmentScope.cxx | 67 | ||||
-rw-r--r-- | Source/cmCLocaleEnvironmentScope.h | 32 |
4 files changed, 103 insertions, 41 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 04f6a81..7af6da3 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -159,6 +159,8 @@ set(SRCS cmCacheManager.cxx cmCacheManager.h "${CMAKE_CURRENT_BINARY_DIR}/cmCommands.cxx" + cmCLocaleEnvironmentScope.h + cmCLocaleEnvironmentScope.cxx cmCommands.h cmCommandArgumentLexer.cxx cmCommandArgumentParser.cxx diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx index b9da8a0..10927e7 100644 --- a/Source/CTest/cmCTestUpdateHandler.cxx +++ b/Source/CTest/cmCTestUpdateHandler.cxx @@ -21,6 +21,7 @@ #include "cmGeneratedFileStream.h" #include "cmXMLParser.h" #include "cmXMLSafe.h" +#include "cmCLocaleEnvironmentScope.h" #include "cmCTestVC.h" #include "cmCTestCVS.h" @@ -66,46 +67,6 @@ static const char* cmCTestUpdateHandlerUpdateToString(int type) return cmCTestUpdateHandlerUpdateStrings[type]; } -class cmCTestUpdateHandlerLocale -{ -public: - cmCTestUpdateHandlerLocale(); - ~cmCTestUpdateHandlerLocale(); -private: - std::string saveLCAll; -}; - -cmCTestUpdateHandlerLocale::cmCTestUpdateHandlerLocale() -{ - const char* lcall = cmSystemTools::GetEnv("LC_ALL"); - if(lcall) - { - saveLCAll = lcall; - } - // if LC_ALL is not set to C, then - // set it, so that svn/cvs info will be in english ascii - if(! (lcall && strcmp(lcall, "C") == 0)) - { - cmSystemTools::PutEnv("LC_ALL=C"); - } -} - -cmCTestUpdateHandlerLocale::~cmCTestUpdateHandlerLocale() -{ - // restore the value of LC_ALL after running the version control - // commands - if(!saveLCAll.empty()) - { - std::string put = "LC_ALL="; - put += saveLCAll; - cmSystemTools::PutEnv(put); - } - else - { - cmSystemTools::UnsetEnv("LC_ALL"); - } -} - //---------------------------------------------------------------------- cmCTestUpdateHandler::cmCTestUpdateHandler() { @@ -194,7 +155,7 @@ int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type) int cmCTestUpdateHandler::ProcessHandler() { // Make sure VCS tool messages are in English so we can parse them. - cmCTestUpdateHandlerLocale fixLocale; + cmCLocaleEnvironmentScope fixLocale; static_cast<void>(fixLocale); // Get source dir diff --git a/Source/cmCLocaleEnvironmentScope.cxx b/Source/cmCLocaleEnvironmentScope.cxx new file mode 100644 index 0000000..5792302 --- /dev/null +++ b/Source/cmCLocaleEnvironmentScope.cxx @@ -0,0 +1,67 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "cmCLocaleEnvironmentScope.h" + +#include "cmSystemTools.h" + +#include <sstream> + +cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope() +{ + this->SetEnv("LANGUAGE", ""); + this->SetEnv("LC_MESSAGES", "C"); + + std::string lcAll = this->GetEnv("LC_ALL"); + + if(!lcAll.empty()) + { + this->SetEnv("LC_ALL", ""); + this->SetEnv("LC_CTYPE", lcAll); + } +} + +std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key) +{ + const char* value = cmSystemTools::GetEnv(key); + return value ? value : std::string(); +} + +void cmCLocaleEnvironmentScope::SetEnv( + std::string const& key, std::string const& value) +{ + std::string oldValue = this->GetEnv(key); + + this->EnvironmentBackup.insert(std::make_pair(key, oldValue)); + + if(value.empty()) + { + cmSystemTools::UnsetEnv(key.c_str()); + } + else + { + std::stringstream tmp; + tmp << key << "=" << value; + cmSystemTools::PutEnv(tmp.str()); + } +} + +cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope() +{ + for(backup_map_t::const_iterator i = this->EnvironmentBackup.begin(); + i != this->EnvironmentBackup.end(); ++i) + { + std::stringstream tmp; + tmp << i->first << "=" << i->second; + cmSystemTools::PutEnv(tmp.str()); + } +} diff --git a/Source/cmCLocaleEnvironmentScope.h b/Source/cmCLocaleEnvironmentScope.h new file mode 100644 index 0000000..b011741 --- /dev/null +++ b/Source/cmCLocaleEnvironmentScope.h @@ -0,0 +1,32 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmCLocaleEnvironmentScope_h +#define cmCLocaleEnvironmentScope_h + +#include "cmStandardIncludes.h" + +class cmCLocaleEnvironmentScope +{ +public: + cmCLocaleEnvironmentScope(); + ~cmCLocaleEnvironmentScope(); + +private: + std::string GetEnv(std::string const& key); + void SetEnv(std::string const& key, std::string const& value); + + typedef std::map<std::string, std::string> backup_map_t; + backup_map_t EnvironmentBackup; +}; + +#endif |