Source: change parameters to std::string
This commit is contained in:
parent
7024fe33b8
commit
273257222e
@ -82,11 +82,11 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
|
||||
bool result = true;
|
||||
if (args.size() - count == 2) {
|
||||
cmSystemTools::MakeDirectory(args[1]);
|
||||
result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal,
|
||||
result = cmExecProgramCommand::RunCommand(command, output, retVal,
|
||||
args[1].c_str(), verbose);
|
||||
} else {
|
||||
result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal,
|
||||
nullptr, verbose);
|
||||
result = cmExecProgramCommand::RunCommand(command, output, retVal, nullptr,
|
||||
verbose);
|
||||
}
|
||||
if (!result) {
|
||||
retVal = -1;
|
||||
@ -115,7 +115,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
bool cmExecProgramCommand::RunCommand(std::string command, std::string& output,
|
||||
int& retVal, const char* dir,
|
||||
bool verbose, Encoding encoding)
|
||||
{
|
||||
@ -128,12 +128,11 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
// try to find the program, and if the program can not be
|
||||
// found use system to run the command as it must be a built in
|
||||
// shell command like echo or dir
|
||||
int count = 0;
|
||||
std::string shortCmd;
|
||||
if (command[0] == '\"') {
|
||||
if (!command.empty() && command[0] == '\"') {
|
||||
// count the number of quotes
|
||||
for (const char* s = command; *s != 0; ++s) {
|
||||
if (*s == '\"') {
|
||||
int count = 0;
|
||||
for (char c : command) {
|
||||
if (c == '\"') {
|
||||
count++;
|
||||
if (count > 2) {
|
||||
break;
|
||||
@ -147,20 +146,21 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
if (count > 2) {
|
||||
cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)");
|
||||
if (quoted.find(command)) {
|
||||
std::string shortCmd;
|
||||
std::string cmd = quoted.match(1);
|
||||
std::string args = quoted.match(2);
|
||||
if (!cmSystemTools::FileExists(cmd)) {
|
||||
shortCmd = cmd;
|
||||
} else if (!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd)) {
|
||||
} else if (!cmSystemTools::GetShortPath(cmd, shortCmd)) {
|
||||
cmSystemTools::Error("GetShortPath failed for " + cmd);
|
||||
return false;
|
||||
}
|
||||
shortCmd += " ";
|
||||
shortCmd += args;
|
||||
|
||||
command = shortCmd.c_str();
|
||||
command = shortCmd;
|
||||
} else {
|
||||
cmSystemTools::Error("Could not parse command line with quotes ",
|
||||
cmSystemTools::Error("Could not parse command line with quotes " +
|
||||
command);
|
||||
}
|
||||
}
|
||||
@ -182,7 +182,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
||||
}
|
||||
cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
|
||||
const char* cmd[] = { command, 0 };
|
||||
const char* cmd[] = { command.c_str(), nullptr };
|
||||
cmsysProcess_SetCommand(cp, cmd);
|
||||
#else
|
||||
std::string commandInDir;
|
||||
@ -197,7 +197,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
# ifndef __VMS
|
||||
commandInDir += " 2>&1";
|
||||
# endif
|
||||
command = commandInDir.c_str();
|
||||
command = commandInDir;
|
||||
if (verbose) {
|
||||
cmSystemTools::Stdout("running ");
|
||||
cmSystemTools::Stdout(command);
|
||||
@ -205,7 +205,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
|
||||
}
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
const char* cmd[] = { "/bin/sh", "-c", command, nullptr };
|
||||
const char* cmd[] = { "/bin/sh", "-c", command.c_str(), nullptr };
|
||||
cmsysProcess_SetCommand(cp, cmd);
|
||||
#endif
|
||||
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
private:
|
||||
static bool RunCommand(const char* command, std::string& output, int& retVal,
|
||||
static bool RunCommand(std::string command, std::string& output, int& retVal,
|
||||
const char* directory = nullptr, bool verbose = true,
|
||||
Encoding encoding = cmProcessOutput::Auto);
|
||||
};
|
||||
|
@ -558,8 +558,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
|
||||
std::string binaryFileName = this->Makefile->GetCurrentBinaryDirectory();
|
||||
binaryFileName += "/CMakeFiles";
|
||||
binaryFileName += "/FileCommandStringsBinaryFile";
|
||||
if (cmHexFileConverter::TryConvert(fileName.c_str(),
|
||||
binaryFileName.c_str())) {
|
||||
if (cmHexFileConverter::TryConvert(fileName, binaryFileName)) {
|
||||
fileName = binaryFileName;
|
||||
}
|
||||
}
|
||||
|
@ -170,8 +170,9 @@ cmGraphVizWriter::cmGraphVizWriter(const cmGlobalGenerator* globalGenerator)
|
||||
{
|
||||
}
|
||||
|
||||
void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
|
||||
const char* fallbackSettingsFileName)
|
||||
void cmGraphVizWriter::ReadSettings(
|
||||
const std::string& settingsFileName,
|
||||
const std::string& fallbackSettingsFileName)
|
||||
{
|
||||
cmake cm(cmake::RoleScript, cmState::Unknown);
|
||||
cm.SetHomeDirectory("");
|
||||
@ -181,8 +182,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
|
||||
cmMakefile mf(&ggi, cm.GetCurrentSnapshot());
|
||||
std::unique_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator(&mf));
|
||||
|
||||
const char* inFileName = settingsFileName;
|
||||
|
||||
std::string inFileName = settingsFileName;
|
||||
if (!cmSystemTools::FileExists(inFileName)) {
|
||||
inFileName = fallbackSettingsFileName;
|
||||
if (!cmSystemTools::FileExists(inFileName)) {
|
||||
@ -191,7 +191,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
|
||||
}
|
||||
|
||||
if (!mf.ReadListFile(inFileName)) {
|
||||
cmSystemTools::Error("Problem opening GraphViz options file: ",
|
||||
cmSystemTools::Error("Problem opening GraphViz options file: " +
|
||||
inFileName);
|
||||
return;
|
||||
}
|
||||
@ -249,7 +249,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
|
||||
|
||||
// Iterate over all targets and write for each one a graph which shows
|
||||
// which other targets depend on it.
|
||||
void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
|
||||
void cmGraphVizWriter::WriteTargetDependersFiles(const std::string& fileName)
|
||||
{
|
||||
if (!this->GenerateDependers) {
|
||||
return;
|
||||
@ -291,7 +291,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
|
||||
|
||||
// Iterate over all targets and write for each one a graph which shows
|
||||
// on which targets it depends.
|
||||
void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
|
||||
void cmGraphVizWriter::WritePerTargetFiles(const std::string& fileName)
|
||||
{
|
||||
if (!this->GeneratePerTarget) {
|
||||
return;
|
||||
@ -327,7 +327,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
|
||||
}
|
||||
}
|
||||
|
||||
void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
|
||||
void cmGraphVizWriter::WriteGlobalFile(const std::string& fileName)
|
||||
{
|
||||
this->CollectTargetsAndLibs();
|
||||
|
||||
@ -392,7 +392,7 @@ void cmGraphVizWriter::WriteConnections(
|
||||
GlobalGenerator);
|
||||
|
||||
for (auto const& llit : ll) {
|
||||
const char* libName = llit.first.c_str();
|
||||
const std::string& libName = llit.first;
|
||||
std::map<std::string, std::string>::const_iterator libNameIt =
|
||||
this->TargetNamesNodes.find(libName);
|
||||
|
||||
@ -519,7 +519,7 @@ int cmGraphVizWriter::CollectAllTargets()
|
||||
for (cmLocalGenerator* lg : this->LocalGenerators) {
|
||||
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
|
||||
for (cmGeneratorTarget* target : targets) {
|
||||
const char* realTargetName = target->GetName().c_str();
|
||||
const std::string& realTargetName = target->GetName();
|
||||
if (this->IgnoreThisTarget(realTargetName)) {
|
||||
// Skip ignored targets
|
||||
continue;
|
||||
@ -541,7 +541,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
|
||||
for (cmLocalGenerator* lg : this->LocalGenerators) {
|
||||
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
|
||||
for (cmGeneratorTarget* target : targets) {
|
||||
const char* realTargetName = target->GetName().c_str();
|
||||
const std::string& realTargetName = target->GetName();
|
||||
if (this->IgnoreThisTarget(realTargetName)) {
|
||||
// Skip ignored targets
|
||||
continue;
|
||||
@ -549,7 +549,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
|
||||
const cmTarget::LinkLibraryVectorType* ll =
|
||||
&(target->Target->GetOriginalLinkLibraries());
|
||||
for (auto const& llit : *ll) {
|
||||
const char* libName = llit.first.c_str();
|
||||
std::string libName = llit.first;
|
||||
if (this->IgnoreThisTarget(libName)) {
|
||||
// Skip ignored targets
|
||||
continue;
|
||||
@ -558,7 +558,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
|
||||
if (GlobalGenerator->IsAlias(libName)) {
|
||||
const auto tgt = GlobalGenerator->FindTarget(libName);
|
||||
if (tgt) {
|
||||
libName = tgt->GetName().c_str();
|
||||
libName = tgt->GetName();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,13 +25,13 @@ class cmGraphVizWriter
|
||||
public:
|
||||
cmGraphVizWriter(const cmGlobalGenerator* globalGenerator);
|
||||
|
||||
void ReadSettings(const char* settingsFileName,
|
||||
const char* fallbackSettingsFileName);
|
||||
void ReadSettings(const std::string& settingsFileName,
|
||||
const std::string& fallbackSettingsFileName);
|
||||
|
||||
void WritePerTargetFiles(const char* fileName);
|
||||
void WriteTargetDependersFiles(const char* fileName);
|
||||
void WritePerTargetFiles(const std::string& fileName);
|
||||
void WriteTargetDependersFiles(const std::string& fileName);
|
||||
|
||||
void WriteGlobalFile(const char* fileName);
|
||||
void WriteGlobalFile(const std::string& fileName);
|
||||
|
||||
protected:
|
||||
void CollectTargetsAndLibs();
|
||||
|
@ -128,7 +128,7 @@ static bool ConvertIntelHexLine(const char* buf, FILE* outFile)
|
||||
}
|
||||
|
||||
cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType(
|
||||
const char* inFileName)
|
||||
const std::string& inFileName)
|
||||
{
|
||||
char buf[1024];
|
||||
FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb");
|
||||
@ -170,8 +170,8 @@ cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType(
|
||||
return type;
|
||||
}
|
||||
|
||||
bool cmHexFileConverter::TryConvert(const char* inFileName,
|
||||
const char* outFileName)
|
||||
bool cmHexFileConverter::TryConvert(const std::string& inFileName,
|
||||
const std::string& outFileName)
|
||||
{
|
||||
FileType type = DetermineFileType(inFileName);
|
||||
if (type == Binary) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#define cmHexFileConverter_h
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
#include <string>
|
||||
|
||||
/** \class cmHexFileConverter
|
||||
* \brief Can detects Intel Hex and Motorola S-record files and convert them
|
||||
@ -19,8 +20,9 @@ public:
|
||||
IntelHex,
|
||||
MotorolaSrec
|
||||
};
|
||||
static FileType DetermineFileType(const char* inFileName);
|
||||
static bool TryConvert(const char* inFileName, const char* outFileName);
|
||||
static FileType DetermineFileType(const std::string& inFileName);
|
||||
static bool TryConvert(const std::string& inFileName,
|
||||
const std::string& outFileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -30,7 +30,7 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
|
||||
this->SetError(e);
|
||||
return false;
|
||||
}
|
||||
const char* destDir = args[1].c_str();
|
||||
const std::string& destDir = args[1];
|
||||
std::vector<std::string> files;
|
||||
cmSystemTools::Glob(inputDir, "\\.h$", files);
|
||||
if (files.empty()) {
|
||||
@ -42,14 +42,14 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
|
||||
std::string path = inputDir;
|
||||
path += "/";
|
||||
path += f;
|
||||
this->CopyAndFullPathMesaHeader(path.c_str(), destDir);
|
||||
this->CopyAndFullPathMesaHeader(path, destDir);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
|
||||
const char* outdir)
|
||||
void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(
|
||||
const std::string& source, const std::string& outdir)
|
||||
{
|
||||
std::string dir, file;
|
||||
cmSystemTools::SplitProgramPath(source, dir, file);
|
||||
@ -65,9 +65,9 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
|
||||
cmSystemTools::ReportLastSystemError("");
|
||||
return;
|
||||
}
|
||||
cmsys::ifstream fin(source);
|
||||
cmsys::ifstream fin(source.c_str());
|
||||
if (!fin) {
|
||||
cmSystemTools::Error("Could not open file for read in copy operation",
|
||||
cmSystemTools::Error("Could not open file for read in copy operation" +
|
||||
source);
|
||||
return;
|
||||
}
|
||||
|
@ -20,7 +20,8 @@ public:
|
||||
cmExecutionStatus& status) override;
|
||||
|
||||
protected:
|
||||
void CopyAndFullPathMesaHeader(const char* source, const char* outdir);
|
||||
void CopyAndFullPathMesaHeader(const std::string& source,
|
||||
const std::string& outdir);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -812,7 +812,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
|
||||
}
|
||||
// no option assume it is the path to the source or an existing build
|
||||
else {
|
||||
this->SetDirectoriesFromFile(arg.c_str());
|
||||
this->SetDirectoriesFromFile(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -855,7 +855,7 @@ cmake::LogLevel cmake::StringToLogLevel(const std::string& levelStr)
|
||||
return (it != levels.cend()) ? it->second : LogLevel::LOG_UNDEFINED;
|
||||
}
|
||||
|
||||
void cmake::SetDirectoriesFromFile(const char* arg)
|
||||
void cmake::SetDirectoriesFromFile(const std::string& arg)
|
||||
{
|
||||
// Check if the argument refers to a CMakeCache.txt or
|
||||
// CMakeLists.txt file.
|
||||
@ -1755,7 +1755,7 @@ int cmake::Generate()
|
||||
this->GlobalGenerator->Generate();
|
||||
if (!this->GraphVizFile.empty()) {
|
||||
std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
|
||||
this->GenerateGraphViz(this->GraphVizFile.c_str());
|
||||
this->GenerateGraphViz(this->GraphVizFile);
|
||||
}
|
||||
if (this->WarnUnusedCli) {
|
||||
this->RunCheckForUnusedVariables();
|
||||
@ -2263,7 +2263,7 @@ void cmake::MarkCliAsUsed(const std::string& variable)
|
||||
this->UsedCliVariables[variable] = true;
|
||||
}
|
||||
|
||||
void cmake::GenerateGraphViz(const char* fileName) const
|
||||
void cmake::GenerateGraphViz(const std::string& fileName) const
|
||||
{
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
cmGraphVizWriter gvWriter(this->GetGlobalGenerator());
|
||||
@ -2273,8 +2273,7 @@ void cmake::GenerateGraphViz(const char* fileName) const
|
||||
std::string fallbackSettingsFile = this->GetHomeDirectory();
|
||||
fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
|
||||
|
||||
gvWriter.ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
|
||||
|
||||
gvWriter.ReadSettings(settingsFile, fallbackSettingsFile);
|
||||
gvWriter.WritePerTargetFiles(fileName);
|
||||
gvWriter.WriteTargetDependersFiles(fileName);
|
||||
gvWriter.WriteGlobalFile(fileName);
|
||||
@ -2652,7 +2651,7 @@ int cmake::Build(int jobs, const std::string& dir,
|
||||
// directories, which is required for running the generation step.
|
||||
std::string homeOrig = this->GetHomeDirectory();
|
||||
std::string homeOutputOrig = this->GetHomeOutputDirectory();
|
||||
this->SetDirectoriesFromFile(cachePath.c_str());
|
||||
this->SetDirectoriesFromFile(cachePath);
|
||||
|
||||
this->AddProjectCommands();
|
||||
|
||||
|
@ -495,13 +495,13 @@ protected:
|
||||
*/
|
||||
int CheckBuildSystem();
|
||||
|
||||
void SetDirectoriesFromFile(const char* arg);
|
||||
void SetDirectoriesFromFile(const std::string& arg);
|
||||
|
||||
//! Make sure all commands are what they say they are and there is no
|
||||
/// macros.
|
||||
void CleanupCommandsAndMacros();
|
||||
|
||||
void GenerateGraphViz(const char* fileName) const;
|
||||
void GenerateGraphViz(const std::string& fileName) const;
|
||||
|
||||
private:
|
||||
ProgressCallbackType ProgressCallback;
|
||||
|
Loading…
Reference in New Issue
Block a user