VS10: Fix exit code of custom commands with setlocal/endlocal (#11938)

Use the pattern

  setlocal
  ...
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd

in custom commands to preserve the %errorlevel% from inside the
setlocal/endlocal block.
This commit is contained in:
Brad King 2011-04-11 11:48:08 -04:00
parent b98fdd5284
commit 234bae7a20
1 changed files with 8 additions and 4 deletions

View File

@ -201,8 +201,6 @@ cmLocalVisualStudioGenerator
{ {
script += newline; script += newline;
newline = newline_text; newline = newline_text;
script += "set errlev=";
script += newline;
script += "setlocal"; script += "setlocal";
} }
@ -267,9 +265,15 @@ cmLocalVisualStudioGenerator
script += newline; script += newline;
script += ":cmEnd"; script += ":cmEnd";
script += newline; script += newline;
script += "endlocal & set errlev=%errorlevel%"; script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone";
script += newline; script += newline;
script += "if %errlev% neq 0 goto "; script += ":cmErrorLevel";
script += newline;
script += "exit /b %1";
script += newline;
script += ":cmDone";
script += newline;
script += "if %errorlevel% neq 0 goto ";
script += this->GetReportErrorLabel(); script += this->GetReportErrorLabel();
} }