BUG: Fix issue #7088 - do not emit error messages when attempts to run Visual Studio macros fail. You can still get the error output as messages if you want using --debug-output from the cmake command line.

This commit is contained in:
David Cole 2008-07-30 15:26:34 -04:00
parent beeebcdc40
commit 17452105cd
4 changed files with 39 additions and 19 deletions

View File

@ -24,6 +24,11 @@
#endif
// Just for this file:
//
static bool LogErrorsAsMessages;
#if defined(HAVE_COMDEF_H)
@ -31,17 +36,20 @@
//----------------------------------------------------------------------------
///! Use ReportHRESULT to make a cmSystemTools::Error after calling
///! Use ReportHRESULT to make a cmSystemTools::Message after calling
///! a COM method that may have failed.
#define ReportHRESULT(hr, context) \
if (FAILED(hr)) \
{ \
std::ostringstream oss; \
oss.flags(std::ios::hex); \
oss << context << " failed HRESULT, hr = 0x" << hr << std::endl; \
oss.flags(std::ios::dec); \
oss << __FILE__ << "(" << __LINE__ << ")"; \
cmSystemTools::Error(oss.str().c_str()); \
if (LogErrorsAsMessages) \
{ \
std::ostringstream oss; \
oss.flags(std::ios::hex); \
oss << context << " failed HRESULT, hr = 0x" << hr << std::endl; \
oss.flags(std::ios::dec); \
oss << __FILE__ << "(" << __LINE__ << ")"; \
cmSystemTools::Message(oss.str().c_str()); \
} \
}
@ -404,6 +412,8 @@ int cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
{
int count = 0;
LogErrorsAsMessages = false;
#if defined(HAVE_COMDEF_H)
HRESULT hr = CoInitialize(0);
ReportHRESULT(hr, "CoInitialize");
@ -438,10 +448,13 @@ int cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
int cmCallVisualStudioMacro::CallMacro(
const std::string& slnFile,
const std::string& macro,
const std::string& args)
const std::string& args,
const bool logErrorsAsMessages)
{
int err = 1; // no comdef.h
LogErrorsAsMessages = logErrorsAsMessages;
#if defined(HAVE_COMDEF_H)
err = 2; // error initializing
@ -489,16 +502,19 @@ int cmCallVisualStudioMacro::CallMacro(
(void)slnFile;
(void)macro;
(void)args;
cmSystemTools::Error("cmCallVisualStudioMacro::CallMacro is not "
"supported on this platform");
if (LogErrorsAsMessages)
{
cmSystemTools::Message("cmCallVisualStudioMacro::CallMacro is not "
"supported on this platform");
}
#endif
if (err)
if (err && LogErrorsAsMessages)
{
std::ostringstream oss;
oss << "cmCallVisualStudioMacro::CallMacro failed, err = " << err;
cmSystemTools::Error(oss.str().c_str());
cmSystemTools::Message(oss.str().c_str());
}
return err;
return 0;
}

View File

@ -33,7 +33,8 @@ public:
///! macro in each Visual Studio instance.
static int CallMacro(const std::string& slnFile,
const std::string& macro,
const std::string& args);
const std::string& args,
const bool logErrorsAsMessages);
///! Count the number of running instances of Visual Studio with the
///! given solution file open. Pass "ALL" for slnFile to count all

View File

@ -178,14 +178,16 @@ cmGlobalVisualStudioGenerator
projects += ";";
projects += *it;
}
cmCallVisualStudioMacro::CallMacro
(topLevelSlnName, CMAKE_VSMACROS_RELOAD_MACRONAME, projects);
cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
this->GetCMakeInstance()->GetDebugOutput());
}
}
else if(m == MacroStop)
{
cmCallVisualStudioMacro::CallMacro(topLevelSlnName,
CMAKE_VSMACROS_STOP_MACRONAME, "");
CMAKE_VSMACROS_STOP_MACRONAME, "",
this->GetCMakeInstance()->GetDebugOutput());
}
}
}

View File

@ -1181,7 +1181,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
<< " s. (clock)"
<< "\n";
return 0;
}
}
// Command to calculate the md5sum of a file
else if (args[1] == "md5sum" && args.size() >= 3)
@ -1422,7 +1422,8 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
}
}
return cmCallVisualStudioMacro::CallMacro(args[2], args[3], macroArgs);
return cmCallVisualStudioMacro::CallMacro(args[2], args[3],
macroArgs, true);
}
#endif