Browse Source

cmake: Remove force from IssueMessage API

The force parameter is ugly and makes the method harder to reason about
(issues the message ... but maybe it doesn't ... but then again you can
force it).  It is a violation of

 https://en.wikipedia.org/wiki/Interface_segregation_principle

and is the kind of thing described in a recent blog here:

 http://code.joejag.com/2016/anti-if-the-missing-patterns.html

 "Any time you see this you actually have two methods bundled into one.
  That boolean represents an opportunity to name a concept in your code."
Stephen Kelly 9 years ago
parent
commit
23f87e8157
5 changed files with 16 additions and 19 deletions
  1. 3 3
      Source/cmMakefile.cxx
  2. 1 2
      Source/cmMakefile.h
  3. 3 2
      Source/cmMessageCommand.cxx
  4. 8 10
      Source/cmake.cxx
  5. 1 2
      Source/cmake.h

+ 3 - 3
Source/cmMakefile.cxx

@@ -105,8 +105,8 @@ cmMakefile::~cmMakefile()
   cmDeleteAll(this->EvaluationFiles);
 }
 
-void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text,
-                              bool force) const
+void cmMakefile::IssueMessage(cmake::MessageType t,
+                              std::string const& text) const
 {
   // Collect context information.
   if (!this->ExecutionStatusStack.empty()) {
@@ -114,7 +114,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text,
       this->ExecutionStatusStack.back()->SetNestedError(true);
     }
   }
-  this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace(), force);
+  this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
 }
 
 cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const

+ 1 - 2
Source/cmMakefile.h

@@ -715,8 +715,7 @@ public:
     cmMakefile* Makefile;
   };
 
-  void IssueMessage(cmake::MessageType t, std::string const& text,
-                    bool force = false) const;
+  void IssueMessage(cmake::MessageType t, std::string const& text) const;
 
   /** Set whether or not to report a CMP0000 violation.  */
   void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }

+ 3 - 2
Source/cmMessageCommand.cxx

@@ -63,8 +63,9 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args,
   std::string message = cmJoin(cmMakeRange(i, args.end()), std::string());
 
   if (type != cmake::MESSAGE) {
-    // we've overriden the message type, above, so force IssueMessage to use it
-    this->Makefile->IssueMessage(type, message, true);
+    // we've overriden the message type, above, so display it directly
+    cmake* cm = this->Makefile->GetCMakeInstance();
+    cm->DisplayMessage(type, message, this->Makefile->GetBacktrace());
   } else {
     if (status) {
       this->Makefile->DisplayStatus(message.c_str(), -1);

+ 8 - 10
Source/cmake.cxx

@@ -2294,16 +2294,14 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
 }
 
 void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
-                         cmListFileBacktrace const& backtrace,
-                         bool force) const
-{
-  if (!force) {
-    // override the message type, if needed, for warnings and errors
-    cmake::MessageType override = this->ConvertMessageType(t);
-    if (override != t) {
-      t = override;
-      force = true;
-    }
+                         cmListFileBacktrace const& backtrace) const
+{
+  bool force = false;
+  // override the message type, if needed, for warnings and errors
+  cmake::MessageType override = this->ConvertMessageType(t);
+  if (override != t) {
+    t = override;
+    force = true;
   }
 
   if (!force && !this->IsMessageTypeVisible(t)) {

+ 1 - 2
Source/cmake.h

@@ -381,8 +381,7 @@ public:
   /** Display a message to the user.  */
   void IssueMessage(
     cmake::MessageType t, std::string const& text,
-    cmListFileBacktrace const& backtrace = cmListFileBacktrace(),
-    bool force = false) const;
+    cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
 
   void DisplayMessage(cmake::MessageType t, std::string const& text,
                       cmListFileBacktrace const& backtrace) const;