CTest: Fix locale used for VCS updates

6a661f0603 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.
This commit is contained in:
Nils Gladitz 2015-04-09 20:56:43 +02:00 committed by Brad King
parent 48040c19d5
commit a198839a7b
4 changed files with 103 additions and 41 deletions

View File

@ -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

View File

@ -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

View File

@ -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());
}
}

View File

@ -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