MCPcopy Create free account
hub / github.com/Kitware/CMake / WriteCustomCommandsHelper

Method WriteCustomCommandsHelper

Source/cmGhsMultiTargetGenerator.cxx:403–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

401}
402
403void 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 }

Callers 2

WriteSourcesMethod · 0.95

Calls 15

moveFunction · 0.85
push_backMethod · 0.80
EscapeForShellMethod · 0.80
GetNumberOfCommandsMethod · 0.80
AppendArgumentsMethod · 0.80
cmStrCatFunction · 0.70
GetWorkingDirectoryMethod · 0.45
emptyMethod · 0.45
GetCommentMethod · 0.45
ConvertToOutputFormatMethod · 0.45

Tested by

no test coverage detected