diff --git a/Source/cmInstallScriptHandler.cxx b/Source/cmInstallScriptHandler.cxx index 7ae56a252f..5bcca67adc 100644 --- a/Source/cmInstallScriptHandler.cxx +++ b/Source/cmInstallScriptHandler.cxx @@ -31,6 +31,7 @@ #include "cmUVStream.h" using InstallScript = cmInstallScriptHandler::InstallScript; +using InstallScriptRunner = cmInstallScriptHandler::InstallScriptRunner; cmInstallScriptHandler::cmInstallScriptHandler(std::string _binaryDir, std::string _component, @@ -45,13 +46,13 @@ cmInstallScriptHandler::cmInstallScriptHandler(std::string _binaryDir, auto addScript = [this, &args](std::string script, std::string config) -> void { - this->commands.push_back(args); + this->scripts.push_back({ script, config, args }); if (!config.empty()) { - this->commands.back().insert( - this->commands.back().end() - 1, + this->scripts.back().command.insert( + this->scripts.back().command.end() - 1, cmStrCat("-DCMAKE_INSTALL_CONFIG_NAME=", config)); } - this->commands.back().emplace_back(script); + this->scripts.back().command.emplace_back(script); this->directories.push_back(cmSystemTools::GetFilenamePath(script)); }; @@ -97,10 +98,9 @@ bool cmInstallScriptHandler::IsParallel() return this->parallel; } -std::vector> cmInstallScriptHandler::GetCommands() - const +std::vector cmInstallScriptHandler::GetScripts() const { - return this->commands; + return this->scripts; } int cmInstallScriptHandler::Install(unsigned int j, @@ -108,8 +108,8 @@ int cmInstallScriptHandler::Install(unsigned int j, { cm::uv_loop_ptr loop; loop.init(); - std::vector scripts; - scripts.reserve(this->commands.size()); + std::vector runners; + runners.reserve(this->scripts.size()); std::vector instrument_arg; if (instrumentation.HasQuery()) { @@ -122,23 +122,24 @@ int cmInstallScriptHandler::Install(unsigned int j, "--" }; } - for (auto& cmd : this->commands) { - cmd.insert(cmd.begin(), instrument_arg.begin(), instrument_arg.end()); - scripts.emplace_back(cmd); + for (auto& script : this->scripts) { + script.command.insert(script.command.begin(), instrument_arg.begin(), + instrument_arg.end()); + runners.emplace_back(script); } std::size_t working = 0; std::size_t installed = 0; std::size_t i = 0; std::function queueScripts; - queueScripts = [&scripts, &working, &installed, &i, &loop, j, + queueScripts = [&runners, &working, &installed, &i, &loop, j, &queueScripts]() { - for (auto queue = std::min(j - working, scripts.size() - i); queue > 0; + for (auto queue = std::min(j - working, runners.size() - i); queue > 0; --queue) { ++working; - scripts[i].start(loop, - [&scripts, &working, &installed, i, &queueScripts]() { - scripts[i].printResult(++installed, scripts.size()); + runners[i].start(loop, + [&runners, &working, &installed, i, &queueScripts]() { + runners[i].printResult(++installed, runners.size()); --working; queueScripts(); }); @@ -180,15 +181,15 @@ int cmInstallScriptHandler::Install(unsigned int j, return 0; } -InstallScript::InstallScript(std::vector const& cmd) +InstallScriptRunner::InstallScriptRunner(InstallScript const& script) { this->name = cmSystemTools::RelativePath( - cmSystemTools::GetLogicalWorkingDirectory(), cmd.back()); - this->command = cmd; + cmSystemTools::GetLogicalWorkingDirectory(), script.path); + this->command = script.command; } -void InstallScript::start(cm::uv_loop_ptr& loop, - std::function callback) +void InstallScriptRunner::start(cm::uv_loop_ptr& loop, + std::function callback) { cmUVProcessChainBuilder builder; builder.AddCommand(this->command) @@ -208,7 +209,7 @@ void InstallScript::start(cm::uv_loop_ptr& loop, std::move(callback)); } -void InstallScript::printResult(std::size_t n, std::size_t total) +void InstallScriptRunner::printResult(std::size_t n, std::size_t total) { cmSystemTools::Stdout(cmStrCat('[', n, '/', total, "] ", this->name, '\n')); for (auto const& line : this->output) { diff --git a/Source/cmInstallScriptHandler.h b/Source/cmInstallScriptHandler.h index 4323c6a00e..f35adb022e 100644 --- a/Source/cmInstallScriptHandler.h +++ b/Source/cmInstallScriptHandler.h @@ -22,11 +22,17 @@ public: std::vector&); bool IsParallel(); int Install(unsigned int j, cmInstrumentation& instrumentation); - std::vector> GetCommands() const; - class InstallScript + struct InstallScript + { + std::string path; + std::string config; + std::vector command; + }; + std::vector GetScripts() const; + class InstallScriptRunner { public: - InstallScript(std::vector const&); + InstallScriptRunner(InstallScript const&); void start(cm::uv_loop_ptr&, std::function); void printResult(std::size_t n, std::size_t total); @@ -40,9 +46,9 @@ public: }; private: - std::vector> commands; - std::vector directories; + std::vector scripts; std::vector configs; + std::vector directories; std::string binaryDir; std::string component; bool parallel; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 90eedcdf1f..d8a753fd09 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -965,7 +965,8 @@ int do_install(int ac, char const* const* av) if (handler.IsParallel()) { ret_ = handler.Install(jobs, instrumentation); } else { - for (auto const& cmd : handler.GetCommands()) { + for (auto const& script : handler.GetScripts()) { + std::vector cmd = script.command; cmake cm(cmake::RoleScript, cmState::Script); cmSystemTools::SetMessageCallback( [&cm](std::string const& msg, cmMessageMetadata const& md) {