| 401 | } |
| 402 | |
| 403 | void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( |
| 404 | std::ostream& fout, cmCustomCommandGenerator const& ccg) |
| 405 | { |
| 406 | std::vector<std::string> cmdLines; |
| 407 | |
| 408 | // if the command specified a working directory use it. |
| 409 | std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory(); |
| 410 | std::string workingDir = ccg.GetWorkingDirectory(); |
| 411 | if (!workingDir.empty()) { |
| 412 | dir = workingDir; |
| 413 | } |
| 414 | |
| 415 | // Line to check for error between commands. |
| 416 | #ifdef _WIN32 |
| 417 | std::string check_error = "if %errorlevel% neq 0 exit /b %errorlevel%"; |
| 418 | #else |
| 419 | std::string check_error = "if [ $? -ne 0 ]; then exit 1; fi"; |
| 420 | #endif |
| 421 | |
| 422 | #ifdef _WIN32 |
| 423 | cmdLines.push_back("@echo off"); |
| 424 | #endif |
| 425 | // Echo the custom command's comment text. |
| 426 | if (cm::optional<std::string> comment = ccg.GetComment()) { |
| 427 | std::string escapedComment = this->LocalGenerator->EscapeForShell( |
| 428 | *comment, ccg.GetCC().GetEscapeAllowMakeVars()); |
| 429 | std::string echocmd = cmStrCat("echo ", escapedComment); |
| 430 | cmdLines.push_back(std::move(echocmd)); |
| 431 | } |
| 432 | |
| 433 | // Switch to working directory |
| 434 | std::string cdCmd; |
| 435 | #ifdef _WIN32 |
| 436 | std::string cdStr = "cd /D "; |
| 437 | #else |
| 438 | std::string cdStr = "cd "; |
| 439 | #endif |
| 440 | cdCmd = cdStr + |
| 441 | this->LocalGenerator->ConvertToOutputFormat(dir, cmOutputConverter::SHELL); |
| 442 | cmdLines.push_back(std::move(cdCmd)); |
| 443 | |
| 444 | for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) { |
| 445 | // Build the command line in a single string. |
| 446 | std::string cmd = ccg.GetCommand(c); |
| 447 | if (!cmd.empty()) { |
| 448 | // Use "call " before any invocations of .bat or .cmd files |
| 449 | // invoked as custom commands in the WindowsShell. |
| 450 | // |
| 451 | bool useCall = false; |
| 452 | |
| 453 | #ifdef _WIN32 |
| 454 | std::string suffix; |
| 455 | if (cmd.size() > 4) { |
| 456 | suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4)); |
| 457 | if (suffix == ".bat" || suffix == ".cmd") { |
| 458 | useCall = true; |
| 459 | } |
| 460 | } |
no test coverage detected