mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Source: Reduce c_str() usage
This commit is contained in:

committed by
Vitaly Stakhovsky

parent
982f7bb506
commit
12624ebd7e
@@ -16,7 +16,7 @@ bool cmCTestEmptyBinaryDirectoryCommand::InitialPass(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0].c_str())) {
|
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0])) {
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "problem removing the binary directory: " << args[0];
|
ostr << "problem removing the binary directory: " << args[0];
|
||||||
this->SetError(ostr.str());
|
this->SetError(ostr.str());
|
||||||
|
@@ -37,8 +37,8 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
int ret;
|
int ret;
|
||||||
cmCTestScriptHandler::RunScript(this->CTest, this->Makefile,
|
cmCTestScriptHandler::RunScript(this->CTest, this->Makefile, args[i],
|
||||||
args[i].c_str(), !np, &ret);
|
!np, &ret);
|
||||||
this->Makefile->AddDefinition(returnVariable, std::to_string(ret));
|
this->Makefile->AddDefinition(returnVariable, std::to_string(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -91,7 +90,7 @@ void cmCTestScriptHandler::Initialize()
|
|||||||
cmCTestScriptHandler::~cmCTestScriptHandler() = default;
|
cmCTestScriptHandler::~cmCTestScriptHandler() = default;
|
||||||
|
|
||||||
// just adds an argument to the vector
|
// just adds an argument to the vector
|
||||||
void cmCTestScriptHandler::AddConfigurationScript(const char* script,
|
void cmCTestScriptHandler::AddConfigurationScript(const std::string& script,
|
||||||
bool pscope)
|
bool pscope)
|
||||||
{
|
{
|
||||||
this->ConfigurationScripts.emplace_back(script);
|
this->ConfigurationScripts.emplace_back(script);
|
||||||
@@ -676,7 +675,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
|||||||
|
|
||||||
// clear the binary directory?
|
// clear the binary directory?
|
||||||
if (this->EmptyBinDir) {
|
if (this->EmptyBinDir) {
|
||||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir.c_str())) {
|
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir)) {
|
||||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||||
"Problem removing the binary directory" << std::endl);
|
"Problem removing the binary directory" << std::endl);
|
||||||
}
|
}
|
||||||
@@ -724,8 +723,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
|||||||
|
|
||||||
// put the initial cache into the bin dir
|
// put the initial cache into the bin dir
|
||||||
if (!this->InitialCache.empty()) {
|
if (!this->InitialCache.empty()) {
|
||||||
if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir.c_str(),
|
if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir,
|
||||||
this->InitialCache.c_str())) {
|
this->InitialCache)) {
|
||||||
this->RestoreBackupDirectories();
|
this->RestoreBackupDirectories();
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
@@ -812,8 +811,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
|
bool cmCTestScriptHandler::WriteInitialCache(const std::string& directory,
|
||||||
const char* text)
|
const std::string& text)
|
||||||
{
|
{
|
||||||
std::string cacheFile = cmStrCat(directory, "/CMakeCache.txt");
|
std::string cacheFile = cmStrCat(directory, "/CMakeCache.txt");
|
||||||
cmGeneratedFileStream fout(cacheFile);
|
cmGeneratedFileStream fout(cacheFile);
|
||||||
@@ -821,9 +820,7 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text != nullptr) {
|
fout.write(text.data(), text.size());
|
||||||
fout.write(text, strlen(text));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the operating system has finished writing the file
|
// Make sure the operating system has finished writing the file
|
||||||
// before closing it. This will ensure the file is finished before
|
// before closing it. This will ensure the file is finished before
|
||||||
@@ -852,7 +849,7 @@ void cmCTestScriptHandler::RestoreBackupDirectories()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||||
const char* sname, bool InProcess,
|
const std::string& sname, bool InProcess,
|
||||||
int* returnValue)
|
int* returnValue)
|
||||||
{
|
{
|
||||||
auto sh = cm::make_unique<cmCTestScriptHandler>();
|
auto sh = cm::make_unique<cmCTestScriptHandler>();
|
||||||
@@ -866,10 +863,10 @@ bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmCTestScriptHandler::EmptyBinaryDirectory(const char* sname)
|
bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname)
|
||||||
{
|
{
|
||||||
// try to avoid deleting root
|
// try to avoid deleting root
|
||||||
if (!sname || strlen(sname) < 2) {
|
if (sname.size() < 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Add a script to run, and if is should run in the current process
|
* Add a script to run, and if is should run in the current process
|
||||||
*/
|
*/
|
||||||
void AddConfigurationScript(const char*, bool pscope);
|
void AddConfigurationScript(const std::string&, bool pscope);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a dashboard using a specified confiuration script
|
* Run a dashboard using a specified confiuration script
|
||||||
@@ -72,19 +72,21 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Run a script
|
* Run a script
|
||||||
*/
|
*/
|
||||||
static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script,
|
static bool RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||||
bool InProcess, int* returnValue);
|
const std::string& script, bool InProcess,
|
||||||
|
int* returnValue);
|
||||||
int RunCurrentScript();
|
int RunCurrentScript();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empty Binary Directory
|
* Empty Binary Directory
|
||||||
*/
|
*/
|
||||||
static bool EmptyBinaryDirectory(const char* dir);
|
static bool EmptyBinaryDirectory(const std::string& dir);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write an initial CMakeCache.txt from the given contents.
|
* Write an initial CMakeCache.txt from the given contents.
|
||||||
*/
|
*/
|
||||||
static bool WriteInitialCache(const char* directory, const char* text);
|
static bool WriteInitialCache(const std::string& directory,
|
||||||
|
const std::string& text);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some elapsed time handling functions
|
* Some elapsed time handling functions
|
||||||
|
@@ -1705,18 +1705,16 @@ bool cmCTestTestHandler::ParseResourceGroupsProperty(
|
|||||||
bool cmCTestTestHandler::GetListOfTests()
|
bool cmCTestTestHandler::GetListOfTests()
|
||||||
{
|
{
|
||||||
if (!this->IncludeLabelRegExp.empty()) {
|
if (!this->IncludeLabelRegExp.empty()) {
|
||||||
this->IncludeLabelRegularExpression.compile(
|
this->IncludeLabelRegularExpression.compile(this->IncludeLabelRegExp);
|
||||||
this->IncludeLabelRegExp.c_str());
|
|
||||||
}
|
}
|
||||||
if (!this->ExcludeLabelRegExp.empty()) {
|
if (!this->ExcludeLabelRegExp.empty()) {
|
||||||
this->ExcludeLabelRegularExpression.compile(
|
this->ExcludeLabelRegularExpression.compile(this->ExcludeLabelRegExp);
|
||||||
this->ExcludeLabelRegExp.c_str());
|
|
||||||
}
|
}
|
||||||
if (!this->IncludeRegExp.empty()) {
|
if (!this->IncludeRegExp.empty()) {
|
||||||
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
|
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp);
|
||||||
}
|
}
|
||||||
if (!this->ExcludeRegExp.empty()) {
|
if (!this->ExcludeRegExp.empty()) {
|
||||||
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
|
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp);
|
||||||
}
|
}
|
||||||
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||||
"Constructing a list of tests" << std::endl, this->Quiet);
|
"Constructing a list of tests" << std::endl, this->Quiet);
|
||||||
|
@@ -2221,7 +2221,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
|
|||||||
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
||||||
// -SR is an internal argument, -SP should be ignored when it is passed
|
// -SR is an internal argument, -SP should be ignored when it is passed
|
||||||
if (!SRArgumentSpecified) {
|
if (!SRArgumentSpecified) {
|
||||||
ch->AddConfigurationScript(args[i].c_str(), false);
|
ch->AddConfigurationScript(args[i], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2231,7 +2231,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
|
|||||||
this->Impl->RunConfigurationScript = true;
|
this->Impl->RunConfigurationScript = true;
|
||||||
i++;
|
i++;
|
||||||
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
||||||
ch->AddConfigurationScript(args[i].c_str(), true);
|
ch->AddConfigurationScript(args[i], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->CheckArgument(arg, "-S"_s, "--script") && i < args.size() - 1) {
|
if (this->CheckArgument(arg, "-S"_s, "--script") && i < args.size() - 1) {
|
||||||
@@ -2240,7 +2240,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
|
|||||||
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
||||||
// -SR is an internal argument, -S should be ignored when it is passed
|
// -SR is an internal argument, -S should be ignored when it is passed
|
||||||
if (!SRArgumentSpecified) {
|
if (!SRArgumentSpecified) {
|
||||||
ch->AddConfigurationScript(args[i].c_str(), true);
|
ch->AddConfigurationScript(args[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -374,7 +374,7 @@ void cmFindLibraryHelper::AddName(std::string const& name)
|
|||||||
regex += "(\\.[0-9]+\\.[0-9]+)?";
|
regex += "(\\.[0-9]+\\.[0-9]+)?";
|
||||||
}
|
}
|
||||||
regex += "$";
|
regex += "$";
|
||||||
entry.Regex.compile(regex.c_str());
|
entry.Regex.compile(regex);
|
||||||
this->Names.push_back(std::move(entry));
|
this->Names.push_back(std::move(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool GetIndexArg(char const* arg, int* idx, cmMakefile& mf)
|
bool GetIndexArg(const std::string& arg, int* idx, cmMakefile& mf)
|
||||||
{
|
{
|
||||||
long value;
|
long value;
|
||||||
if (!cmStrToLong(arg, &value)) {
|
if (!cmStrToLong(arg, &value)) {
|
||||||
@@ -189,7 +189,7 @@ bool HandleGetCommand(std::vector<std::string> const& args,
|
|||||||
size_t nitem = varArgsExpanded.size();
|
size_t nitem = varArgsExpanded.size();
|
||||||
for (cc = 2; cc < args.size() - 1; cc++) {
|
for (cc = 2; cc < args.size() - 1; cc++) {
|
||||||
int item;
|
int item;
|
||||||
if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
|
if (!GetIndexArg(args[cc], &item, status.GetMakefile())) {
|
||||||
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
|
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -401,7 +401,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
// expand the variable
|
// expand the variable
|
||||||
int item;
|
int item;
|
||||||
if (!GetIndexArg(args[2].c_str(), &item, status.GetMakefile())) {
|
if (!GetIndexArg(args[2], &item, status.GetMakefile())) {
|
||||||
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
|
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1326,11 +1326,11 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
|
|||||||
|
|
||||||
int start;
|
int start;
|
||||||
int length;
|
int length;
|
||||||
if (!GetIndexArg(args[2].c_str(), &start, status.GetMakefile())) {
|
if (!GetIndexArg(args[2], &start, status.GetMakefile())) {
|
||||||
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
|
status.SetError(cmStrCat("index: ", args[2], " is not a valid index"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!GetIndexArg(args[3].c_str(), &length, status.GetMakefile())) {
|
if (!GetIndexArg(args[3], &length, status.GetMakefile())) {
|
||||||
status.SetError(cmStrCat("index: ", args[3], " is not a valid index"));
|
status.SetError(cmStrCat("index: ", args[3], " is not a valid index"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1389,7 +1389,7 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args,
|
|||||||
size_t nitem = varArgsExpanded.size();
|
size_t nitem = varArgsExpanded.size();
|
||||||
for (cc = 2; cc < args.size(); ++cc) {
|
for (cc = 2; cc < args.size(); ++cc) {
|
||||||
int item;
|
int item;
|
||||||
if (!GetIndexArg(args[cc].c_str(), &item, status.GetMakefile())) {
|
if (!GetIndexArg(args[cc], &item, status.GetMakefile())) {
|
||||||
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
|
status.SetError(cmStrCat("index: ", args[cc], " is not a valid index"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -359,7 +359,7 @@ void cmOrderDirectories::SetLinkExtensionInfo(
|
|||||||
std::string const& removeExtRegex)
|
std::string const& removeExtRegex)
|
||||||
{
|
{
|
||||||
this->LinkExtensions = linkExtensions;
|
this->LinkExtensions = linkExtensions;
|
||||||
this->RemoveLibraryExtension.compile(removeExtRegex.c_str());
|
this->RemoveLibraryExtension.compile(removeExtRegex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmOrderDirectories::CollectOriginalDirectories()
|
void cmOrderDirectories::CollectOriginalDirectories()
|
||||||
|
@@ -241,7 +241,7 @@ bool RegexMatch(std::vector<std::string> const& args,
|
|||||||
status.GetMakefile().ClearMatches();
|
status.GetMakefile().ClearMatches();
|
||||||
// Compile the regular expression.
|
// Compile the regular expression.
|
||||||
cmsys::RegularExpression re;
|
cmsys::RegularExpression re;
|
||||||
if (!re.compile(regex.c_str())) {
|
if (!re.compile(regex)) {
|
||||||
std::string e =
|
std::string e =
|
||||||
"sub-command REGEX, mode MATCH failed to compile regex \"" + regex +
|
"sub-command REGEX, mode MATCH failed to compile regex \"" + regex +
|
||||||
"\".";
|
"\".";
|
||||||
@@ -283,7 +283,7 @@ bool RegexMatchAll(std::vector<std::string> const& args,
|
|||||||
status.GetMakefile().ClearMatches();
|
status.GetMakefile().ClearMatches();
|
||||||
// Compile the regular expression.
|
// Compile the regular expression.
|
||||||
cmsys::RegularExpression re;
|
cmsys::RegularExpression re;
|
||||||
if (!re.compile(regex.c_str())) {
|
if (!re.compile(regex)) {
|
||||||
std::string e =
|
std::string e =
|
||||||
"sub-command REGEX, mode MATCHALL failed to compile regex \"" + regex +
|
"sub-command REGEX, mode MATCHALL failed to compile regex \"" + regex +
|
||||||
"\".";
|
"\".";
|
||||||
|
@@ -74,7 +74,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
|
|||||||
std::vector<std::string>::const_iterator argEnd);
|
std::vector<std::string>::const_iterator argEnd);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void CMakeCommandUsage(const char* program)
|
void CMakeCommandUsage(std::string const& program)
|
||||||
{
|
{
|
||||||
std::ostringstream errorStream;
|
std::ostringstream errorStream;
|
||||||
|
|
||||||
@@ -704,7 +704,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
} else if (args[2] == "--ignore-eol") {
|
} else if (args[2] == "--ignore-eol") {
|
||||||
filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]);
|
filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]);
|
||||||
} else {
|
} else {
|
||||||
CMakeCommandUsage(args[0].c_str());
|
CMakeCommandUsage(args[0]);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,7 +1085,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
std::string const& directory = args[2];
|
std::string const& directory = args[2];
|
||||||
if (!cmSystemTools::FileExists(directory)) {
|
if (!cmSystemTools::FileExists(directory)) {
|
||||||
cmSystemTools::Error("Directory does not exist for chdir command: " +
|
cmSystemTools::Error("Directory does not exist for chdir command: " +
|
||||||
args[2]);
|
directory);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1152,7 +1152,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
<< "\n";
|
<< "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!cmSystemTools::CreateSymlink(args[2], args[3])) {
|
if (!cmSystemTools::CreateSymlink(args[2], destinationFileName)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1161,12 +1161,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
// Command to create a hard link. Fails on platforms not
|
// Command to create a hard link. Fails on platforms not
|
||||||
// supporting them.
|
// supporting them.
|
||||||
if (args[1] == "create_hardlink" && args.size() == 4) {
|
if (args[1] == "create_hardlink" && args.size() == 4) {
|
||||||
const char* SouceFileName = args[2].c_str();
|
std::string const& sourceFileName = args[2];
|
||||||
const char* destinationFileName = args[3].c_str();
|
std::string const& destinationFileName = args[3];
|
||||||
|
|
||||||
if (!cmSystemTools::FileExists(SouceFileName)) {
|
if (!cmSystemTools::FileExists(sourceFileName)) {
|
||||||
std::cerr << "failed to create hard link because source path '"
|
std::cerr << "failed to create hard link because source path '"
|
||||||
<< SouceFileName << "' does not exist \n";
|
<< sourceFileName << "' does not exist \n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1180,7 +1180,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cmSystemTools::CreateLink(args[2], args[3])) {
|
if (!cmSystemTools::CreateLink(sourceFileName, destinationFileName)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1560,7 +1560,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeCommandUsage(args[0].c_str());
|
CMakeCommandUsage(args[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user