diff options
author | Brad King <brad.king@kitware.com> | 2011-04-12 18:44:25 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2011-04-12 18:44:25 (GMT) |
commit | 8997dc935cc7a7fc750eb3aa0a9e1ce2353121a0 (patch) | |
tree | 7df99d6fe0aab9931073449ce86fdb3a2487c801 | |
parent | bf4349b23cefa27d8359ff6ea6c70be62759768e (diff) | |
parent | 234bae7a204cc23fa0d297d5ab90db7ecc54f6d4 (diff) | |
download | CMake-8997dc935cc7a7fc750eb3aa0a9e1ce2353121a0.zip CMake-8997dc935cc7a7fc750eb3aa0a9e1ce2353121a0.tar.gz CMake-8997dc935cc7a7fc750eb3aa0a9e1ce2353121a0.tar.bz2 |
Merge topic 'vs10-custom-working-directory-issue-11938'
234bae7 VS10: Fix exit code of custom commands with setlocal/endlocal (#11938)
b98fdd5 VS: Use setlocal/endlocal only in VS 10 custom commands
06fcbc4 VS10: Fix working directory of consecutive custom commands (#11938)
-rw-r--r-- | Source/cmLocalVisualStudio10Generator.cxx | 4 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio10Generator.h | 3 | ||||
-rw-r--r-- | Source/cmLocalVisualStudioGenerator.cxx | 56 | ||||
-rw-r--r-- | Source/cmLocalVisualStudioGenerator.h | 10 |
4 files changed, 58 insertions, 15 deletions
diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index de2a837..1850c16 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -119,7 +119,7 @@ void cmLocalVisualStudio10Generator } //---------------------------------------------------------------------------- -std::string cmLocalVisualStudio10Generator::CheckForErrorLine() +const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const { - return "if errorlevel 1 goto :VCEnd"; + return ":VCEnd"; } diff --git a/Source/cmLocalVisualStudio10Generator.h b/Source/cmLocalVisualStudio10Generator.h index 06b8b09..0fccdb0 100644 --- a/Source/cmLocalVisualStudio10Generator.h +++ b/Source/cmLocalVisualStudio10Generator.h @@ -38,7 +38,8 @@ public: const char* path); protected: - virtual std::string CheckForErrorLine(); + virtual const char* ReportErrorLabel() const; + virtual bool CustomCommandUseLocal() const { return true; } private: }; diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 39f9962..4390a08 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -154,15 +154,15 @@ void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements } //---------------------------------------------------------------------------- -std::string cmLocalVisualStudioGenerator::CheckForErrorLine() +const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const { - return "if errorlevel 1 goto :VCReportError"; + return ":VCReportError"; } //---------------------------------------------------------------------------- -std::string cmLocalVisualStudioGenerator::GetCheckForErrorLine() +const char* cmLocalVisualStudioGenerator::GetReportErrorLabel() const { - return this->CheckForErrorLine(); + return this->ReportErrorLabel(); } //---------------------------------------------------------------------------- @@ -172,6 +172,7 @@ cmLocalVisualStudioGenerator const char* configName, const char* newline_text) { + bool useLocal = this->CustomCommandUseLocal(); const cmCustomCommandLines& commandLines = cc.GetCommandLines(); const char* workingDirectory = cc.GetWorkingDirectory(); cmCustomCommandGenerator ccg(cc, configName, this->Makefile); @@ -180,8 +181,29 @@ cmLocalVisualStudioGenerator // Avoid leading or trailing newlines. const char* newline = ""; + // Line to check for error between commands. + std::string check_error = newline_text; + if(useLocal) + { + check_error += "if %errorlevel% neq 0 goto :cmEnd"; + } + else + { + check_error += "if errorlevel 1 goto "; + check_error += this->GetReportErrorLabel(); + } + // Store the script in a string. std::string script; + + // Open a local context. + if(useLocal) + { + script += newline; + newline = newline_text; + script += "setlocal"; + } + if(workingDirectory) { // Change the working directory. @@ -189,6 +211,7 @@ cmLocalVisualStudioGenerator newline = newline_text; script += "cd "; script += this->Convert(workingDirectory, FULL, SHELL); + script += check_error; // Change the working drive. if(workingDirectory[0] && workingDirectory[1] == ':') @@ -197,8 +220,10 @@ cmLocalVisualStudioGenerator newline = newline_text; script += workingDirectory[0]; script += workingDirectory[1]; + script += check_error; } } + // for visual studio IDE add extra stuff to the PATH // if CMAKE_MSVCIDE_RUN_PATH is set. if(this->Makefile->GetDefinition("MSVC_IDE")) @@ -214,6 +239,7 @@ cmLocalVisualStudioGenerator script += ";%PATH%"; } } + // Write each command on a single line. for(unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) { @@ -230,9 +256,25 @@ cmLocalVisualStudioGenerator // If there was an error, jump to the VCReportError label, // skipping the run of any subsequent commands in this // sequence. - // - script += newline_text; - script += this->GetCheckForErrorLine(); + script += check_error; + } + + // Close the local context. + if(useLocal) + { + script += newline; + script += ":cmEnd"; + script += newline; + script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone"; + script += newline; + script += ":cmErrorLevel"; + script += newline; + script += "exit /b %1"; + script += newline; + script += ":cmDone"; + script += newline; + script += "if %errorlevel% neq 0 goto "; + script += this->GetReportErrorLabel(); } return script; diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index 22112b3..a38bc30 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -37,13 +37,13 @@ public: const char* configName, const char* newline = "\n"); - /** Line of batch file text that skips to the end after - * a failed step in a sequence of custom commands. - */ - std::string GetCheckForErrorLine(); + /** Label to which to jump in a batch file after a failed step in a + sequence of custom commands. */ + const char* GetReportErrorLabel() const; protected: - virtual std::string CheckForErrorLine(); + virtual const char* ReportErrorLabel() const; + virtual bool CustomCommandUseLocal() const { return false; } /** Construct a custom command to make exe import lib dir. */ cmsys::auto_ptr<cmCustomCommand> |