| 503 | } |
| 504 | |
| 505 | bool BuildManager::execCommand(const BuildCommandInfo &info) |
| 506 | { |
| 507 | outBuildState(BuildState::kBuilding); |
| 508 | bool ret = false; |
| 509 | QString executeResult = tr("Execute command failed!\n"); |
| 510 | |
| 511 | d->cmdProcess.setWorkingDirectory(info.workingDir); |
| 512 | |
| 513 | QString startMsg = tr("Start execute command: \"%1\" \"%2\" in workspace \"%3\".\n") |
| 514 | .arg(info.program, info.arguments.join(" "), info.workingDir); |
| 515 | outputLog(startMsg, OutputPane::OutputFormat::NormalMessage); |
| 516 | |
| 517 | connect(&d->cmdProcess, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), |
| 518 | [&](int exitcode, QProcess::ExitStatus exitStatus) { |
| 519 | if (0 == exitcode && exitStatus == QProcess::ExitStatus::NormalExit) { |
| 520 | ret = true; |
| 521 | executeResult = tr("The process \"%1\" exited normally.\n").arg(d->cmdProcess.program()); |
| 522 | } else if (exitStatus == QProcess::NormalExit) { |
| 523 | ret = false; |
| 524 | executeResult = tr("The process \"%1\" exited with code %2.\n") |
| 525 | .arg(d->cmdProcess.program(), QString::number(exitcode)); |
| 526 | } else { |
| 527 | ret = false; |
| 528 | executeResult = tr("The process \"%1\" crashed.\n") |
| 529 | .arg(d->cmdProcess.program()); |
| 530 | } |
| 531 | }); |
| 532 | |
| 533 | connect(&d->cmdProcess, &QProcess::readyReadStandardOutput, [&]() { |
| 534 | d->cmdProcess.setReadChannel(QProcess::StandardOutput); |
| 535 | while (d->cmdProcess.canReadLine()) { |
| 536 | QString line = QString::fromUtf8(d->cmdProcess.readLine()); |
| 537 | outputLog(line, OutputPane::OutputFormat::StdOut); |
| 538 | } |
| 539 | }); |
| 540 | |
| 541 | connect(&d->cmdProcess, &QProcess::readyReadStandardError, [&]() { |
| 542 | d->cmdProcess.setReadChannel(QProcess::StandardError); |
| 543 | while (d->cmdProcess.canReadLine()) { |
| 544 | QString line = QString::fromUtf8(d->cmdProcess.readLine()); |
| 545 | outputLog(line, OutputPane::OutputFormat::StdErr); |
| 546 | outputError(line); |
| 547 | } |
| 548 | }); |
| 549 | |
| 550 | d->cmdProcess.start(info.program, info.arguments); |
| 551 | d->cmdProcess.waitForFinished(-1); |
| 552 | |
| 553 | disconnectSignals(); |
| 554 | outputLog(executeResult, ret ? OutputPane::OutputFormat::NormalMessage : OutputPane::OutputFormat::StdErr); |
| 555 | |
| 556 | QString endMsg = tr("Execute command finished.\n"); |
| 557 | outputLog(endMsg, OutputPane::OutputFormat::NormalMessage); |
| 558 | |
| 559 | BuildState buildState = ret ? BuildState::kNoBuild : BuildState::kBuildFailed; |
| 560 | outBuildState(buildState); |
| 561 | |
| 562 | outputNotify(buildState, info); |
nothing calls this directly
no test coverage detected