2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-05-04 19:34:59 +04:00
|
|
|
#include "cmBuildNameCommand.h"
|
|
|
|
|
2003-06-23 22:10:12 +04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2001-05-04 19:34:59 +04:00
|
|
|
// cmBuildNameCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-05-04 19:34:59 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Disallowed(
|
|
|
|
cmPolicies::CMP0036,
|
|
|
|
"The build_name command should not be called; see CMP0036.")) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty()) {
|
2001-05-04 19:34:59 +04:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
const char* cacheValue = this->Makefile->GetDefinition(args[0]);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cacheValue) {
|
2012-08-13 21:42:58 +04:00
|
|
|
// do we need to correct the value?
|
2003-06-23 22:10:12 +04:00
|
|
|
cmsys::RegularExpression reg("[()/]");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (reg.find(cacheValue)) {
|
2001-07-10 17:23:34 +04:00
|
|
|
std::string cv = cacheValue;
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(cv.begin(), cv.end(), '/', '_');
|
|
|
|
std::replace(cv.begin(), cv.end(), '(', '_');
|
|
|
|
std::replace(cv.begin(), cv.end(), ')', '_');
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(args[0], cv.c_str(), "Name of build.",
|
|
|
|
cmState::STRING);
|
2001-05-04 19:34:59 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-05-16 23:15:21 +04:00
|
|
|
std::string buildname = "WinNT";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->GetDefinition("UNIX")) {
|
2001-05-04 19:34:59 +04:00
|
|
|
buildname = "";
|
2015-04-20 22:36:57 +03:00
|
|
|
cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!buildname.empty()) {
|
2001-05-05 00:44:24 +04:00
|
|
|
std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::RegularExpression reg(RegExp.c_str());
|
|
|
|
if (reg.find(buildname.c_str())) {
|
2002-10-24 02:03:27 +04:00
|
|
|
buildname = reg.match(1) + "-" + reg.match(2);
|
2001-05-05 00:44:24 +04:00
|
|
|
}
|
2001-05-04 19:34:59 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-04-26 17:55:32 +04:00
|
|
|
std::string compiler = "${CMAKE_CXX_COMPILER}";
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->ExpandVariablesInString(compiler);
|
2002-04-26 17:55:32 +04:00
|
|
|
buildname += "-";
|
2001-07-03 00:30:40 +04:00
|
|
|
buildname += cmSystemTools::GetFilenameName(compiler);
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(buildname.begin(), buildname.end(), '/', '_');
|
|
|
|
std::replace(buildname.begin(), buildname.end(), '(', '_');
|
|
|
|
std::replace(buildname.begin(), buildname.end(), ')', '_');
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(args[0], buildname.c_str(),
|
|
|
|
"Name of build.", cmState::STRING);
|
2001-05-04 19:34:59 +04:00
|
|
|
return true;
|
|
|
|
}
|