Browse Source

Merge topic 'cleanup-endls-2'

1e4b5c7d09 Refactor: Avoid `std::endl` where it's not necessary (part 2)

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4514
Brad King 5 years ago
parent
commit
6a0c1726e0

+ 12 - 19
Source/cmDepends.cxx

@@ -2,7 +2,6 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmDepends.h"
 
-#include <sstream>
 #include <utility>
 
 #include "cmsys/FStream.hxx"
@@ -81,16 +80,14 @@ void cmDepends::Clear(const std::string& file)
 {
   // Print verbose output.
   if (this->Verbose) {
-    std::ostringstream msg;
-    msg << "Clearing dependencies in \"" << file << "\"." << std::endl;
-    cmSystemTools::Stdout(msg.str());
+    cmSystemTools::Stdout(
+      cmStrCat("Clearing dependencies in \"", file, "\".\n"));
   }
 
   // Write an empty dependency file.
   cmGeneratedFileStream depFileStream(file);
   depFileStream << "# Empty dependencies file\n"
-                << "# This may be replaced when dependencies are built."
-                << std::endl;
+                   "# This may be replaced when dependencies are built.\n";
 }
 
 bool cmDepends::WriteDependencies(const std::set<std::string>& /*unused*/,
@@ -172,10 +169,9 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends,
 
       // Print verbose output.
       if (this->Verbose) {
-        std::ostringstream msg;
-        msg << "Dependee \"" << dependee << "\" does not exist for depender \""
-            << depender << "\"." << std::endl;
-        cmSystemTools::Stdout(msg.str());
+        cmSystemTools::Stdout(cmStrCat("Dependee \"", dependee,
+                                       "\" does not exist for depender \"",
+                                       depender, "\".\n"));
       }
     } else if (dependerExists) {
       // The dependee and depender both exist.  Compare file times.
@@ -185,10 +181,9 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends,
 
         // Print verbose output.
         if (this->Verbose) {
-          std::ostringstream msg;
-          msg << "Dependee \"" << dependee << "\" is newer than depender \""
-              << depender << "\"." << std::endl;
-          cmSystemTools::Stdout(msg.str());
+          cmSystemTools::Stdout(cmStrCat("Dependee \"", dependee,
+                                         "\" is newer than depender \"",
+                                         depender, "\".\n"));
         }
       }
     } else {
@@ -200,11 +195,9 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends,
 
         // Print verbose output.
         if (this->Verbose) {
-          std::ostringstream msg;
-          msg << "Dependee \"" << dependee
-              << "\" is newer than depends file \"" << internalDependsFileName
-              << "\"." << std::endl;
-          cmSystemTools::Stdout(msg.str());
+          cmSystemTools::Stdout(cmStrCat("Dependee \"", dependee,
+                                         "\" is newer than depends file \"",
+                                         internalDependsFileName, "\".\n"));
         }
       }
     }

+ 9 - 9
Source/cmDependsC.cxx

@@ -212,17 +212,17 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
   // convert the dependencies to paths relative to the home output
   // directory.  We must do the same here.
   std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i);
-  internalDepends << obj_i << std::endl;
+  internalDepends << obj_i << '\n';
 
   for (std::string const& dep : dependencies) {
     makeDepends << obj_m << ": "
                 << cmSystemTools::ConvertToOutputPath(
                      this->LocalGenerator->MaybeConvertToRelativePath(binDir,
                                                                       dep))
-                << std::endl;
-    internalDepends << " " << dep << std::endl;
+                << '\n';
+    internalDepends << ' ' << dep << '\n';
   }
-  makeDepends << std::endl;
+  makeDepends << '\n';
 
   return true;
 }
@@ -312,17 +312,17 @@ void cmDependsC::WriteCacheFile() const
 
   for (auto const& fileIt : this->FileCache) {
     if (fileIt.second.Used) {
-      cacheOut << fileIt.first << std::endl;
+      cacheOut << fileIt.first << '\n';
 
       for (UnscannedEntry const& inc : fileIt.second.UnscannedEntries) {
-        cacheOut << inc.FileName << std::endl;
+        cacheOut << inc.FileName << '\n';
         if (inc.QuotedLocation.empty()) {
-          cacheOut << "-" << std::endl;
+          cacheOut << '-' << '\n';
         } else {
-          cacheOut << inc.QuotedLocation << std::endl;
+          cacheOut << inc.QuotedLocation << '\n';
         }
       }
-      cacheOut << std::endl;
+      cacheOut << '\n';
     }
   }
 }

+ 18 - 19
Source/cmDependsFortran.cxx

@@ -185,7 +185,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
   fiStream << "provides\n";
   std::set<std::string> const& provides = this->Internal->TargetProvides;
   for (std::string const& i : provides) {
-    fiStream << " " << i << "\n";
+    fiStream << ' ' << i << '\n';
   }
 
   // Create a script to clean the modules.
@@ -202,14 +202,14 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
       std::string mod_lower = cmStrCat(mod_dir, '/');
       cmFortranModuleAppendUpperLower(i, mod_upper, mod_lower);
       std::string stamp = cmStrCat(stamp_dir, '/', i, ".stamp");
-      fcStream << "\n";
-      fcStream << "  \""
+      fcStream << "\n"
+                  "  \""
                << this->MaybeConvertToRelativePath(currentBinDir, mod_lower)
-               << "\"\n";
-      fcStream << "  \""
+               << "\"\n"
+                  "  \""
                << this->MaybeConvertToRelativePath(currentBinDir, mod_upper)
-               << "\"\n";
-      fcStream << "  \""
+               << "\"\n"
+                  "  \""
                << this->MaybeConvertToRelativePath(currentBinDir, stamp)
                << "\"\n";
     }
@@ -326,16 +326,15 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
   std::string binDir = this->LocalGenerator->GetBinaryDirectory();
   std::string obj_i = this->MaybeConvertToRelativePath(binDir, obj);
   std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i);
-  internalDepends << obj_i << std::endl;
-  internalDepends << " " << src << std::endl;
+  internalDepends << obj_i << "\n " << src << '\n';
   for (std::string const& i : info.Includes) {
     makeDepends << obj_m << ": "
                 << cmSystemTools::ConvertToOutputPath(
                      this->MaybeConvertToRelativePath(binDir, i))
-                << std::endl;
-    internalDepends << " " << i << std::endl;
+                << '\n';
+    internalDepends << ' ' << i << '\n';
   }
-  makeDepends << std::endl;
+  makeDepends << '\n';
 
   // Write module requirements to the output stream.
   for (std::string const& i : info.Requires) {
@@ -354,7 +353,7 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
       // This module is known.  Depend on its timestamp file.
       std::string stampFile = cmSystemTools::ConvertToOutputPath(
         this->MaybeConvertToRelativePath(binDir, required->second));
-      makeDepends << obj_m << ": " << stampFile << "\n";
+      makeDepends << obj_m << ": " << stampFile << '\n';
     } else {
       // This module is not known to CMake.  Try to locate it where
       // the compiler will and depend on that.
@@ -362,7 +361,7 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
       if (this->FindModule(i, module)) {
         module = cmSystemTools::ConvertToOutputPath(
           this->MaybeConvertToRelativePath(binDir, module));
-        makeDepends << obj_m << ": " << module << "\n";
+        makeDepends << obj_m << ": " << module << '\n';
       }
     }
   }
@@ -391,7 +390,7 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
         cmSystemTools::ConvertToOutputPath(stampFile);
 
       makeDepends << obj_m << ".provides.build"
-                  << ": " << stampFileForMake << "\n";
+                  << ": " << stampFileForMake << '\n';
       // Note that when cmake_copy_f90_mod finds that a module file
       // and the corresponding stamp file have no differences, the stamp
       // file is not updated. In such case the stamp file will be always
@@ -399,15 +398,15 @@ bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
       // on each new build. This is expected behavior for incremental
       // builds and can not be changed without preforming recursive make
       // calls that would considerably slow down the building process.
-      makeDepends << stampFileForMake << ": " << obj_m << "\n";
+      makeDepends << stampFileForMake << ": " << obj_m << '\n';
       makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
-                  << " " << stampFileForShell;
+                  << ' ' << stampFileForShell;
       cmMakefile* mf = this->LocalGenerator->GetMakefile();
       const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
       if (cid && *cid) {
-        makeDepends << " " << cid;
+        makeDepends << ' ' << cid;
       }
-      makeDepends << "\n";
+      makeDepends << '\n';
     }
     makeDepends << obj_m << ".provides.build:\n";
     // After copying the modules update the timestamp file.

+ 2 - 2
Source/cmExtraEclipseCDT4Generator.cxx

@@ -187,10 +187,10 @@ void cmExtraEclipseCDT4Generator::CreateSettingsResourcePrefsFile()
     return;
   }
 
-  fout << "eclipse.preferences.version=1" << std::endl;
+  fout << "eclipse.preferences.version=1\n";
   const char* encoding = mf->GetDefinition("CMAKE_ECLIPSE_RESOURCE_ENCODING");
   if (encoding) {
-    fout << "encoding/<project>=" << encoding << std::endl;
+    fout << "encoding/<project>=" << encoding << '\n';
   }
 }
 

+ 27 - 26
Source/cmLocalGenerator.cxx

@@ -288,21 +288,23 @@ void cmLocalGenerator::GenerateTestFiles()
   cmGeneratedFileStream fout(file);
   fout.SetCopyIfDifferent(true);
 
-  fout << "# CMake generated Testfile for " << std::endl
-       << "# Source directory: "
-       << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
-       << "# Build directory: "
-       << this->StateSnapshot.GetDirectory().GetCurrentBinary() << std::endl
-       << "# " << std::endl
-       << "# This file includes the relevant testing commands "
-       << "required for " << std::endl
-       << "# testing this directory and lists subdirectories to "
-       << "be tested as well." << std::endl;
+  fout << "# CMake generated Testfile for \n"
+          "# Source directory: "
+       << this->StateSnapshot.GetDirectory().GetCurrentSource()
+       << "\n"
+          "# Build directory: "
+       << this->StateSnapshot.GetDirectory().GetCurrentBinary()
+       << "\n"
+          "# \n"
+          "# This file includes the relevant testing commands "
+          "required for \n"
+          "# testing this directory and lists subdirectories to "
+          "be tested as well.\n";
 
   const char* testIncludeFile =
     this->Makefile->GetProperty("TEST_INCLUDE_FILE");
   if (testIncludeFile) {
-    fout << "include(\"" << testIncludeFile << "\")" << std::endl;
+    fout << "include(\"" << testIncludeFile << "\")\n";
   }
 
   const char* testIncludeFiles =
@@ -310,7 +312,7 @@ void cmLocalGenerator::GenerateTestFiles()
   if (testIncludeFiles) {
     std::vector<std::string> includesList = cmExpandedList(testIncludeFiles);
     for (std::string const& i : includesList) {
-      fout << "include(\"" << i << "\")" << std::endl;
+      fout << "include(\"" << i << "\")\n";
     }
   }
 
@@ -327,7 +329,7 @@ void cmLocalGenerator::GenerateTestFiles()
     std::string outP = i.GetDirectory().GetCurrentBinary();
     outP = this->MaybeConvertToRelativePath(parentBinDir, outP);
     outP = cmOutputConverter::EscapeForCMake(outP);
-    fout << "subdirs(" << outP << ")" << std::endl;
+    fout << "subdirs(" << outP << ")\n";
   }
 
   // Add directory labels property
@@ -346,7 +348,7 @@ void cmLocalGenerator::GenerateTestFiles()
     if (directoryLabels) {
       fout << cmOutputConverter::EscapeForCMake(directoryLabels);
     }
-    fout << ")" << std::endl;
+    fout << ")\n";
   }
 }
 
@@ -467,16 +469,17 @@ void cmLocalGenerator::GenerateInstallRules()
   fout.SetCopyIfDifferent(true);
 
   // Write the header.
+  /* clang-format off */
   fout << "# Install script for directory: "
-       << this->StateSnapshot.GetDirectory().GetCurrentSource() << std::endl
-       << std::endl;
-  fout << "# Set the install prefix" << std::endl
-       << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
-       << "  set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
-       << "endif()" << std::endl
+       << this->StateSnapshot.GetDirectory().GetCurrentSource()
+       << "\n\n"
+          "# Set the install prefix\n"
+          "if(NOT DEFINED CMAKE_INSTALL_PREFIX)\n"
+          "  set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")\n"
+          "endif()\n"
        << R"(string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX )"
-       << "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
-       << std::endl;
+       << "\"${CMAKE_INSTALL_PREFIX}\")\n\n";
+  /* clang-format on */
 
   // Write support code for generating per-configuration install rules.
   /* clang-format off */
@@ -591,8 +594,7 @@ void cmLocalGenerator::GenerateInstallRules()
           if (!c.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
             std::string odir = c.GetDirectory().GetCurrentBinary();
             cmSystemTools::ConvertToUnixSlashes(odir);
-            fout << "  include(\"" << odir << "/cmake_install.cmake\")"
-                 << std::endl;
+            fout << "  include(\"" << odir << "/cmake_install.cmake\")\n";
           }
         }
         fout << "\n";
@@ -949,8 +951,7 @@ void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags,
         << "\".  "
            "This is not permitted. The COMPILE_FEATURES may not both depend "
            "on "
-           "and be depended on by the link implementation."
-        << std::endl;
+           "and be depended on by the link implementation.\n";
       this->IssueMessage(MessageType::FATAL_ERROR, e.str());
       return;
     }

+ 11 - 12
Source/cmQtAutoMocUic.cxx

@@ -700,27 +700,27 @@ bool cmQtAutoMocUicT::ParseCacheT::WriteToFile(std::string const& fileName)
   if (!ofs) {
     return false;
   }
-  ofs << "# Generated by CMake. Changes will be overwritten." << std::endl;
+  ofs << "# Generated by CMake. Changes will be overwritten.\n";
   for (auto const& pair : Map_) {
-    ofs << pair.first << std::endl;
+    ofs << pair.first << '\n';
     FileT const& file = *pair.second;
     if (!file.Moc.Macro.empty()) {
-      ofs << " mmc:" << file.Moc.Macro << std::endl;
+      ofs << " mmc:" << file.Moc.Macro << '\n';
     }
     for (IncludeKeyT const& item : file.Moc.Include.Underscore) {
-      ofs << " miu:" << item.Key << std::endl;
+      ofs << " miu:" << item.Key << '\n';
     }
     for (IncludeKeyT const& item : file.Moc.Include.Dot) {
-      ofs << " mid:" << item.Key << std::endl;
+      ofs << " mid:" << item.Key << '\n';
     }
     for (std::string const& item : file.Moc.Depends) {
-      ofs << " mdp:" << item << std::endl;
+      ofs << " mdp:" << item << '\n';
     }
     for (IncludeKeyT const& item : file.Uic.Include) {
-      ofs << " uic:" << item.Key << std::endl;
+      ofs << " uic:" << item.Key << '\n';
     }
     for (std::string const& item : file.Uic.Depends) {
-      ofs << " udp:" << item << std::endl;
+      ofs << " udp:" << item << '\n';
     }
   }
   return ofs.Close();
@@ -2211,9 +2211,9 @@ void cmQtAutoMocUicT::JobDepFilesMergeT::Process()
                       " for writing."));
     return;
   }
-  ofs << BaseConst().DepFileRuleName << ": \\" << std::endl;
+  ofs << BaseConst().DepFileRuleName << ": \\\n";
   for (const std::string& file : dependencies) {
-    ofs << '\t' << escapeDependencyPath(file) << " \\" << std::endl;
+    ofs << '\t' << escapeDependencyPath(file) << " \\\n";
     if (!ofs.good()) {
       LogError(GenT::GEN,
                cmStrCat("Writing depfile", MessagePath(BaseConst().DepFile),
@@ -2224,8 +2224,7 @@ void cmQtAutoMocUicT::JobDepFilesMergeT::Process()
 
   // Add the CMake executable to re-new cache data if necessary.
   // Also, this is the last entry, so don't add a backslash.
-  ofs << '\t' << escapeDependencyPath(BaseConst().CMakeExecutable)
-      << std::endl;
+  ofs << '\t' << escapeDependencyPath(BaseConst().CMakeExecutable) << '\n';
 }
 
 void cmQtAutoMocUicT::JobFinishT::Process()

+ 1 - 1
Source/cmTarget.cxx

@@ -888,7 +888,7 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
       cmListFileContext lfc = cmd.second;
       lfc.FilePath = cmDir.ConvertToRelPathIfNotContained(
         impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
-      s << " * " << lfc << std::endl;
+      s << " * " << lfc << '\n';
     }
   }
 }

+ 5 - 5
Source/cmTestGenerator.cxx

@@ -134,7 +134,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
             ge.Parse(i.second)->Evaluate(this->LG, config));
   }
   this->GenerateInternalProperties(os);
-  os << ")" << std::endl;
+  os << ")\n";
 }
 
 void cmTestGenerator::GenerateScriptNoConfig(std::ostream& os, Indent indent)
@@ -176,9 +176,9 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent)
       }
       fout << c;
     }
-    fout << "\"";
+    fout << '"';
   }
-  fout << ")" << std::endl;
+  fout << ")\n";
 
   // Output properties for the test.
   fout << indent << "set_tests_properties(" << this->Test->GetName()
@@ -188,7 +188,7 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent)
          << cmOutputConverter::EscapeForCMake(i.second);
   }
   this->GenerateInternalProperties(fout);
-  fout << ")" << std::endl;
+  fout << ")\n";
 }
 
 void cmTestGenerator::GenerateInternalProperties(std::ostream& os)
@@ -213,7 +213,7 @@ void cmTestGenerator::GenerateInternalProperties(std::ostream& os)
     prependTripleSeparator = true;
   }
 
-  os << "\"";
+  os << '"';
 }
 
 std::vector<std::string> cmTestGenerator::EvaluateCommandLineArguments(