mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-13 17:47:49 +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;
|
||||
}
|
||||
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0].c_str())) {
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(args[0])) {
|
||||
std::ostringstream ostr;
|
||||
ostr << "problem removing the binary directory: " << args[0];
|
||||
this->SetError(ostr.str());
|
||||
|
@@ -37,8 +37,8 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args,
|
||||
++i;
|
||||
} else {
|
||||
int ret;
|
||||
cmCTestScriptHandler::RunScript(this->CTest, this->Makefile,
|
||||
args[i].c_str(), !np, &ret);
|
||||
cmCTestScriptHandler::RunScript(this->CTest, this->Makefile, args[i],
|
||||
!np, &ret);
|
||||
this->Makefile->AddDefinition(returnVariable, std::to_string(ret));
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <ratio>
|
||||
#include <sstream>
|
||||
@@ -91,7 +90,7 @@ void cmCTestScriptHandler::Initialize()
|
||||
cmCTestScriptHandler::~cmCTestScriptHandler() = default;
|
||||
|
||||
// just adds an argument to the vector
|
||||
void cmCTestScriptHandler::AddConfigurationScript(const char* script,
|
||||
void cmCTestScriptHandler::AddConfigurationScript(const std::string& script,
|
||||
bool pscope)
|
||||
{
|
||||
this->ConfigurationScripts.emplace_back(script);
|
||||
@@ -676,7 +675,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
||||
|
||||
// clear the binary directory?
|
||||
if (this->EmptyBinDir) {
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir.c_str())) {
|
||||
if (!cmCTestScriptHandler::EmptyBinaryDirectory(this->BinaryDir)) {
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
||||
"Problem removing the binary directory" << std::endl);
|
||||
}
|
||||
@@ -724,8 +723,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
||||
|
||||
// put the initial cache into the bin dir
|
||||
if (!this->InitialCache.empty()) {
|
||||
if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir.c_str(),
|
||||
this->InitialCache.c_str())) {
|
||||
if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir,
|
||||
this->InitialCache)) {
|
||||
this->RestoreBackupDirectories();
|
||||
return 9;
|
||||
}
|
||||
@@ -812,8 +811,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
|
||||
const char* text)
|
||||
bool cmCTestScriptHandler::WriteInitialCache(const std::string& directory,
|
||||
const std::string& text)
|
||||
{
|
||||
std::string cacheFile = cmStrCat(directory, "/CMakeCache.txt");
|
||||
cmGeneratedFileStream fout(cacheFile);
|
||||
@@ -821,9 +820,7 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (text != nullptr) {
|
||||
fout.write(text, strlen(text));
|
||||
}
|
||||
fout.write(text.data(), text.size());
|
||||
|
||||
// Make sure the operating system has finished writing the file
|
||||
// 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,
|
||||
const char* sname, bool InProcess,
|
||||
const std::string& sname, bool InProcess,
|
||||
int* returnValue)
|
||||
{
|
||||
auto sh = cm::make_unique<cmCTestScriptHandler>();
|
||||
@@ -866,10 +863,10 @@ bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestScriptHandler::EmptyBinaryDirectory(const char* sname)
|
||||
bool cmCTestScriptHandler::EmptyBinaryDirectory(const std::string& sname)
|
||||
{
|
||||
// try to avoid deleting root
|
||||
if (!sname || strlen(sname) < 2) {
|
||||
if (sname.size() < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public:
|
||||
/**
|
||||
* 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
|
||||
@@ -72,19 +72,21 @@ public:
|
||||
/*
|
||||
* Run a script
|
||||
*/
|
||||
static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script,
|
||||
bool InProcess, int* returnValue);
|
||||
static bool RunScript(cmCTest* ctest, cmMakefile* mf,
|
||||
const std::string& script, bool InProcess,
|
||||
int* returnValue);
|
||||
int RunCurrentScript();
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
|
@@ -1705,18 +1705,16 @@ bool cmCTestTestHandler::ParseResourceGroupsProperty(
|
||||
bool cmCTestTestHandler::GetListOfTests()
|
||||
{
|
||||
if (!this->IncludeLabelRegExp.empty()) {
|
||||
this->IncludeLabelRegularExpression.compile(
|
||||
this->IncludeLabelRegExp.c_str());
|
||||
this->IncludeLabelRegularExpression.compile(this->IncludeLabelRegExp);
|
||||
}
|
||||
if (!this->ExcludeLabelRegExp.empty()) {
|
||||
this->ExcludeLabelRegularExpression.compile(
|
||||
this->ExcludeLabelRegExp.c_str());
|
||||
this->ExcludeLabelRegularExpression.compile(this->ExcludeLabelRegExp);
|
||||
}
|
||||
if (!this->IncludeRegExp.empty()) {
|
||||
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
|
||||
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp);
|
||||
}
|
||||
if (!this->ExcludeRegExp.empty()) {
|
||||
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
|
||||
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp);
|
||||
}
|
||||
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"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();
|
||||
// -SR is an internal argument, -SP should be ignored when it is passed
|
||||
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;
|
||||
i++;
|
||||
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) {
|
||||
@@ -2240,7 +2240,7 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
|
||||
cmCTestScriptHandler* ch = this->GetScriptHandler();
|
||||
// -SR is an internal argument, -S should be ignored when it is passed
|
||||
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 += "$";
|
||||
entry.Regex.compile(regex.c_str());
|
||||
entry.Regex.compile(regex);
|
||||
this->Names.push_back(std::move(entry));
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
bool GetIndexArg(char const* arg, int* idx, cmMakefile& mf)
|
||||
bool GetIndexArg(const std::string& arg, int* idx, cmMakefile& mf)
|
||||
{
|
||||
long value;
|
||||
if (!cmStrToLong(arg, &value)) {
|
||||
@@ -189,7 +189,7 @@ bool HandleGetCommand(std::vector<std::string> const& args,
|
||||
size_t nitem = varArgsExpanded.size();
|
||||
for (cc = 2; cc < args.size() - 1; cc++) {
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
@@ -401,7 +401,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
|
||||
|
||||
// expand the variable
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
@@ -1326,11 +1326,11 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
|
||||
|
||||
int start;
|
||||
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"));
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
@@ -1389,7 +1389,7 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args,
|
||||
size_t nitem = varArgsExpanded.size();
|
||||
for (cc = 2; cc < args.size(); ++cc) {
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
|
@@ -359,7 +359,7 @@ void cmOrderDirectories::SetLinkExtensionInfo(
|
||||
std::string const& removeExtRegex)
|
||||
{
|
||||
this->LinkExtensions = linkExtensions;
|
||||
this->RemoveLibraryExtension.compile(removeExtRegex.c_str());
|
||||
this->RemoveLibraryExtension.compile(removeExtRegex);
|
||||
}
|
||||
|
||||
void cmOrderDirectories::CollectOriginalDirectories()
|
||||
|
@@ -241,7 +241,7 @@ bool RegexMatch(std::vector<std::string> const& args,
|
||||
status.GetMakefile().ClearMatches();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if (!re.compile(regex.c_str())) {
|
||||
if (!re.compile(regex)) {
|
||||
std::string e =
|
||||
"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();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if (!re.compile(regex.c_str())) {
|
||||
if (!re.compile(regex)) {
|
||||
std::string e =
|
||||
"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);
|
||||
|
||||
namespace {
|
||||
void CMakeCommandUsage(const char* program)
|
||||
void CMakeCommandUsage(std::string const& program)
|
||||
{
|
||||
std::ostringstream errorStream;
|
||||
|
||||
@@ -704,7 +704,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
} else if (args[2] == "--ignore-eol") {
|
||||
filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]);
|
||||
} else {
|
||||
CMakeCommandUsage(args[0].c_str());
|
||||
CMakeCommandUsage(args[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -1085,7 +1085,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
std::string const& directory = args[2];
|
||||
if (!cmSystemTools::FileExists(directory)) {
|
||||
cmSystemTools::Error("Directory does not exist for chdir command: " +
|
||||
args[2]);
|
||||
directory);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1152,7 +1152,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
<< "\n";
|
||||
return 1;
|
||||
}
|
||||
if (!cmSystemTools::CreateSymlink(args[2], args[3])) {
|
||||
if (!cmSystemTools::CreateSymlink(args[2], destinationFileName)) {
|
||||
return 1;
|
||||
}
|
||||
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
|
||||
// supporting them.
|
||||
if (args[1] == "create_hardlink" && args.size() == 4) {
|
||||
const char* SouceFileName = args[2].c_str();
|
||||
const char* destinationFileName = args[3].c_str();
|
||||
std::string const& sourceFileName = args[2];
|
||||
std::string const& destinationFileName = args[3];
|
||||
|
||||
if (!cmSystemTools::FileExists(SouceFileName)) {
|
||||
if (!cmSystemTools::FileExists(sourceFileName)) {
|
||||
std::cerr << "failed to create hard link because source path '"
|
||||
<< SouceFileName << "' does not exist \n";
|
||||
<< sourceFileName << "' does not exist \n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1180,7 +1180,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!cmSystemTools::CreateLink(args[2], args[3])) {
|
||||
if (!cmSystemTools::CreateLink(sourceFileName, destinationFileName)) {
|
||||
return 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user