mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
cmInstallScriptHandler: Refactor to store config and path for each command
This commit is contained in:
@@ -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<std::vector<std::string>> cmInstallScriptHandler::GetCommands()
|
||||
const
|
||||
std::vector<InstallScript> 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<InstallScript> scripts;
|
||||
scripts.reserve(this->commands.size());
|
||||
std::vector<InstallScriptRunner> runners;
|
||||
runners.reserve(this->scripts.size());
|
||||
|
||||
std::vector<std::string> 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<void()> 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<std::string> 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<void()> callback)
|
||||
void InstallScriptRunner::start(cm::uv_loop_ptr& loop,
|
||||
std::function<void()> 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) {
|
||||
|
@@ -22,11 +22,17 @@ public:
|
||||
std::vector<std::string>&);
|
||||
bool IsParallel();
|
||||
int Install(unsigned int j, cmInstrumentation& instrumentation);
|
||||
std::vector<std::vector<std::string>> GetCommands() const;
|
||||
class InstallScript
|
||||
struct InstallScript
|
||||
{
|
||||
std::string path;
|
||||
std::string config;
|
||||
std::vector<std::string> command;
|
||||
};
|
||||
std::vector<InstallScript> GetScripts() const;
|
||||
class InstallScriptRunner
|
||||
{
|
||||
public:
|
||||
InstallScript(std::vector<std::string> const&);
|
||||
InstallScriptRunner(InstallScript const&);
|
||||
void start(cm::uv_loop_ptr&, std::function<void()>);
|
||||
void printResult(std::size_t n, std::size_t total);
|
||||
|
||||
@@ -40,9 +46,9 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<std::vector<std::string>> commands;
|
||||
std::vector<std::string> directories;
|
||||
std::vector<InstallScript> scripts;
|
||||
std::vector<std::string> configs;
|
||||
std::vector<std::string> directories;
|
||||
std::string binaryDir;
|
||||
std::string component;
|
||||
bool parallel;
|
||||
|
@@ -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<std::string> cmd = script.command;
|
||||
cmake cm(cmake::RoleScript, cmState::Script);
|
||||
cmSystemTools::SetMessageCallback(
|
||||
[&cm](std::string const& msg, cmMessageMetadata const& md) {
|
||||
|
Reference in New Issue
Block a user