cmake: Progress functions use std::string param

This commit is contained in:
Vitaly Stakhovsky 2019-02-11 10:30:00 -05:00
parent 8a1d25afdf
commit 950c099d83
22 changed files with 58 additions and 50 deletions

View File

@ -43,7 +43,8 @@ cmCPackGenerator::~cmCPackGenerator()
this->MakefileMap = nullptr;
}
void cmCPackGenerator::DisplayVerboseOutput(const char* msg, float progress)
void cmCPackGenerator::DisplayVerboseOutput(const std::string& msg,
float progress)
{
(void)progress;
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
@ -689,7 +690,7 @@ int cmCPackGenerator::InstallCMakeProject(
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cm.AddCMakePaths();
cm.SetProgressCallback([this](const char* msg, float prog) {
cm.SetProgressCallback([this](const std::string& msg, float prog) {
this->DisplayVerboseOutput(msg, prog);
});
cm.SetTrace(this->Trace);

View File

@ -96,7 +96,7 @@ public:
void SetLogger(cmCPackLog* log) { this->Logger = log; }
//! Display verbose information via logger
void DisplayVerboseOutput(const char* msg, float progress);
void DisplayVerboseOutput(const std::string& msg, float progress);
bool ReadListFile(const char* moduleName);

View File

@ -90,7 +90,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
return 1;
}
static void cpackProgressCallback(const char* message, float /*unused*/)
static void cpackProgressCallback(const std::string& message, float /*unused*/)
{
std::cout << "-- " << message << std::endl;
}

View File

@ -126,10 +126,11 @@ public:
cmSystemTools::SetStdoutCallback([&s](std::string const& m) { s += m; });
cmSystemTools::SetStderrCallback([&s](std::string const& m) { s += m; });
this->CM.SetProgressCallback([&s](const char* msg, float /*unused*/) {
s += msg;
s += "\n";
});
this->CM.SetProgressCallback(
[&s](const std::string& msg, float /*unused*/) {
s += msg;
s += "\n";
});
}
~cmCTestBuildAndTestCaptureRAII()

View File

@ -288,11 +288,12 @@ void cmCTestScriptHandler::CreateCMake()
this->ParentMakefile->GetRecursionDepth());
}
this->CMake->SetProgressCallback([this](const char* m, float /*unused*/) {
if (m && *m) {
cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl);
}
});
this->CMake->SetProgressCallback(
[this](const std::string& m, float /*unused*/) {
if (!m.empty()) {
cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl);
}
});
this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);

View File

@ -501,14 +501,14 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
pos_form_cursor(this->Form);
}
void cmCursesMainForm::UpdateProgress(const char* msg, float prog)
void cmCursesMainForm::UpdateProgress(const std::string& msg, float prog)
{
char tmp[1024];
const char* cmsg = tmp;
if (prog >= 0) {
sprintf(tmp, "%s %i%%", msg, static_cast<int>(100 * prog));
sprintf(tmp, "%s %i%%", msg.c_str(), static_cast<int>(100 * prog));
} else {
cmsg = msg;
cmsg = msg.c_str();
}
this->UpdateStatusBar(cmsg);
this->PrintKeys(1);
@ -528,7 +528,9 @@ int cmCursesMainForm::Configure(int noconfigure)
touchwin(stdscr);
refresh();
this->CMakeInstance->SetProgressCallback(
[this](const char* msg, float prog) { this->UpdateProgress(msg, prog); });
[this](const std::string& msg, float prog) {
this->UpdateProgress(msg, prog);
});
// always save the current gui values to disk
this->FillCacheManagerFromUI();
@ -598,7 +600,9 @@ int cmCursesMainForm::Generate()
touchwin(stdscr);
refresh();
this->CMakeInstance->SetProgressCallback(
[this](const char* msg, float prog) { this->UpdateProgress(msg, prog); });
[this](const std::string& msg, float prog) {
this->UpdateProgress(msg, prog);
});
// Get rid of previous errors
this->Errors = std::vector<std::string>();

View File

@ -102,7 +102,7 @@ public:
/**
* Progress callback
*/
void UpdateProgress(const char* msg, float prog);
void UpdateProgress(const std::string& msg, float prog);
protected:
// Copy the cache values from the user interface to the actual

View File

@ -37,7 +37,7 @@ QCMake::QCMake(QObject* p)
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeGUICommand());
this->CMakeInstance->SetProgressCallback(
[this](const char* msg, float percent) {
[this](const std::string& msg, float percent) {
this->progressCallback(msg, percent);
});
@ -346,12 +346,12 @@ bool QCMake::interruptCallback()
#endif
}
void QCMake::progressCallback(const char* msg, float percent)
void QCMake::progressCallback(const std::string& msg, float percent)
{
if (percent >= 0) {
emit this->progressChanged(QString::fromLocal8Bit(msg), percent);
emit this->progressChanged(QString::fromStdString(msg), percent);
} else {
emit this->outputMessage(QString::fromLocal8Bit(msg));
emit this->outputMessage(QString::fromStdString(msg));
}
QCoreApplication::processEvents();
}

View File

@ -168,7 +168,7 @@ protected:
cmake* CMakeInstance;
bool interruptCallback();
void progressCallback(const char* msg, float percent);
void progressCallback(std::string const& msg, float percent);
void messageCallback(std::string const& msg, const char* title);
void stdoutCallback(std::string const& msg);
void stderrCallback(std::string const& msg);

View File

@ -1834,7 +1834,7 @@ protected:
if (!this->MessageNever && (copy || !this->MessageLazy)) {
std::string message = (copy ? "Installing: " : "Up-to-date: ");
message += toFile;
this->Makefile->DisplayStatus(message.c_str(), -1);
this->Makefile->DisplayStatus(message, -1);
}
if (type != TypeDir) {
// Add the file to the manifest.
@ -2214,7 +2214,7 @@ bool cmFileCommand::HandleRPathChangeCommand(
message += "\" to \"";
message += newRPath;
message += "\"";
this->Makefile->DisplayStatus(message.c_str(), -1);
this->Makefile->DisplayStatus(message, -1);
}
if (have_ft) {
cmSystemTools::FileTimeSet(file, ft);
@ -2278,7 +2278,7 @@ bool cmFileCommand::HandleRPathRemoveCommand(
std::string message = "Removed runtime path from \"";
message += file;
message += "\"";
this->Makefile->DisplayStatus(message.c_str(), -1);
this->Makefile->DisplayStatus(message, -1);
}
if (have_ft) {
cmSystemTools::FileTimeSet(file, ft);
@ -2647,7 +2647,7 @@ int cmFileDownloadProgressCallback(void* clientp, double dltotal, double dlnow,
if (helper->UpdatePercentage(dlnow, dltotal, status)) {
cmFileCommand* fc = helper->GetFileCommand();
cmMakefile* mf = fc->GetMakefile();
mf->DisplayStatus(status.c_str(), -1);
mf->DisplayStatus(status, -1);
}
return 0;
@ -2665,7 +2665,7 @@ int cmFileUploadProgressCallback(void* clientp, double dltotal, double dlnow,
if (helper->UpdatePercentage(ulnow, ultotal, status)) {
cmFileCommand* fc = helper->GetFileCommand();
cmMakefile* mf = fc->GetMakefile();
mf->DisplayStatus(status.c_str(), -1);
mf->DisplayStatus(status, -1);
}
return 0;

View File

@ -911,7 +911,7 @@ bool cmFindPackageCommand::HandlePackageMode()
std::ostringstream aw;
aw << "Could NOT find " << this->Name << " (missing: " << this->Name
<< "_DIR)";
this->Makefile->DisplayStatus(aw.str().c_str(), -1);
this->Makefile->DisplayStatus(aw.str(), -1);
}
}

View File

@ -1225,7 +1225,7 @@ void cmGlobalGenerator::Configure()
} else {
msg << "Configuring done";
}
this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
this->CMakeInstance->UpdateProgress(msg.str(), -1);
}
}

View File

@ -1006,7 +1006,7 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
winSDK_7_1)) {
std::ostringstream m;
m << "Found Windows SDK v7.1: " << winSDK_7_1;
mf->DisplayStatus(m.str().c_str(), -1);
mf->DisplayStatus(m.str(), -1);
this->DefaultPlatformToolset = "Windows7.1SDK";
return true;
} else {

View File

@ -171,7 +171,7 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf,
std::ostringstream e;
e << "Selecting Windows SDK version " << this->WindowsTargetPlatformVersion
<< " to target Windows " << this->SystemVersion << ".";
mf->DisplayStatus(e.str().c_str(), -1);
mf->DisplayStatus(e.str(), -1);
}
mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION",
this->WindowsTargetPlatformVersion.c_str());

View File

@ -3547,7 +3547,7 @@ cmState* cmMakefile::GetState() const
return this->GetCMakeInstance()->GetState();
}
void cmMakefile::DisplayStatus(const char* message, float s) const
void cmMakefile::DisplayStatus(const std::string& message, float s) const
{
cmake* cm = this->GetCMakeInstance();
if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) {

View File

@ -639,7 +639,7 @@ public:
#endif
///! Display progress or status message.
void DisplayStatus(const char*, float) const;
void DisplayStatus(const std::string&, float) const;
/**
* Expand the given list file arguments into the full set after

View File

@ -68,7 +68,7 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args,
m->DisplayMessage(type, message, this->Makefile->GetBacktrace());
} else {
if (status) {
this->Makefile->DisplayStatus(message.c_str(), -1);
this->Makefile->DisplayStatus(message, -1);
} else {
cmSystemTools::Message(message);
}

View File

@ -103,7 +103,7 @@ void cmServer::ProcessRequest(cmConnection* connection,
if (this->Protocol) {
this->Protocol->CMakeInstance()->SetProgressCallback(
[&request](const char* msg, float prog) {
[&request](const std::string& msg, float prog) {
reportProgress(msg, prog, request);
});
this->WriteResponse(connection, this->Protocol->Process(request),
@ -155,7 +155,7 @@ void cmServer::PrintHello(cmConnection* connection) const
this->WriteJsonObject(connection, hello, nullptr);
}
void cmServer::reportProgress(const char* msg, float progress,
void cmServer::reportProgress(const std::string& msg, float progress,
const cmServerRequest& request)
{
if (progress < 0.0f || progress > 1.0f) {

View File

@ -119,7 +119,7 @@ public:
void OnConnected(cmConnection* connection) override;
private:
static void reportProgress(const char* msg, float progress,
static void reportProgress(const std::string& msg, float progress,
const cmServerRequest& request);
static void reportMessage(const std::string& msg, const char* title,
const cmServerRequest& request);

View File

@ -1705,7 +1705,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
ret = this->Generate();
std::string message = "Build files have been written to: ";
message += this->GetHomeOutputDirectory();
this->UpdateProgress(message.c_str(), -1);
this->UpdateProgress(message, -1);
return ret;
}
@ -1925,7 +1925,7 @@ void cmake::SetProgressCallback(ProgressCallbackType f)
this->ProgressCallback = std::move(f);
}
void cmake::UpdateProgress(const char* msg, float prog)
void cmake::UpdateProgress(const std::string& msg, float prog)
{
if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
this->ProgressCallback(msg, prog);
@ -2640,7 +2640,7 @@ int cmake::Build(int jobs, const std::string& dir, const std::string& target,
}
std::string message = "Build files have been written to: ";
message += this->GetHomeOutputDirectory();
this->UpdateProgress(message.c_str(), -1);
this->UpdateProgress(message, -1);
// Restore the previously set directories to their original value.
this->SetHomeDirectory(homeOrig);

View File

@ -273,7 +273,7 @@ public:
///! Parse command line arguments that might set cache values
bool SetCacheArgs(const std::vector<std::string>&);
using ProgressCallbackType = std::function<void(const char*, float)>;
using ProgressCallbackType = std::function<void(const std::string&, float)>;
/**
* Set the function used by GUIs to receive progress updates
* Function gets passed: message as a const char*, a progress
@ -284,7 +284,7 @@ public:
void SetProgressCallback(ProgressCallbackType f);
///! this is called by generators to update the progress
void UpdateProgress(const char* msg, float prog);
void UpdateProgress(const std::string& msg, float prog);
#if defined(CMAKE_BUILD_WITH_CMAKE)
///! Get the variable watch object

View File

@ -148,14 +148,15 @@ static void cmakemainMessageCallback(const std::string& m,
std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush;
}
static void cmakemainProgressCallback(const char* m, float prog, cmake* cm)
static void cmakemainProgressCallback(const std::string& m, float prog,
cmake* cm)
{
cmMakefile* mf = cmakemainGetMakefile(cm);
std::string dir;
if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) {
if (mf && cmHasLiteralPrefix(m, "Configuring") && (prog < 0)) {
dir = " ";
dir += mf->GetCurrentSourceDirectory();
} else if ((mf) && (strstr(m, "Generating") == m)) {
} else if (mf && cmHasLiteralPrefix(m, "Generating")) {
dir = " ";
dir += mf->GetCurrentBinaryDirectory();
}
@ -323,7 +324,7 @@ int do_cmake(int ac, char const* const* av)
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
cm.SetWorkingMode(workingMode);
@ -504,7 +505,7 @@ static int do_build(int ac, char const* const* av)
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
return cm.Build(jobs, dir, target, config, nativeOptions, clean, verbose);
@ -547,7 +548,7 @@ static int do_open(int ac, char const* const* av)
[&cm](const std::string& msg, const char* title) {
cmakemainMessageCallback(msg, title, &cm);
});
cm.SetProgressCallback([&cm](const char* msg, float prog) {
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
return cm.Open(dir, false) ? 0 : 1;