Commit b6802cd5 authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

cmGeneratedFileStream: clang-tidy applied to remove redundant ``c_str`` calls

After changing the ``cmGeneratedFileStream`` methods to accept
``std::string const&`` instead of ``const char*`` we don't
need to call ``std::string::c_str`` anymore when passing
a ``std::string`` to a ``cmGeneratedFileStream`` method.

This patch removes all redundant ``std::string::c_str``
calls when passing a string to a ``cmGeneratedFileStream`` method.

It was generated by building CMake with clang-tidy enabled using
the following options:

-DCMAKE_CXX_CLANG_TIDY=/usr/bin/clang-tidy-4.0;-checks=-*,readability-redundant-string-cstr;-fix;-fix-errors
parent a688defc
......@@ -90,7 +90,7 @@ int cmCPackIFWGenerator::PackageFiles()
ifwCmd.c_str(), &output, &output, &retVal, nullptr,
this->GeneratorVerbose, cmDuration::zero());
if (!res || retVal) {
cmGeneratedFileStream ofs(ifwTmpFile.c_str());
cmGeneratedFileStream ofs(ifwTmpFile);
ofs << "# Run command: " << ifwCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......@@ -203,7 +203,7 @@ int cmCPackIFWGenerator::PackageFiles()
ifwCmd.c_str(), &output, &output, &retVal, nullptr,
this->GeneratorVerbose, cmDuration::zero());
if (!res || retVal) {
cmGeneratedFileStream ofs(ifwTmpFile.c_str());
cmGeneratedFileStream ofs(ifwTmpFile);
ofs << "# Run command: " << ifwCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......
......@@ -306,7 +306,7 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
}
// Output stream
cmGeneratedFileStream fout((this->Directory + "/config/config.xml").data());
cmGeneratedFileStream fout(this->Directory + "/config/config.xml");
cmXMLWriter xout(fout);
xout.StartDocument();
......
......@@ -528,7 +528,7 @@ void cmCPackIFWPackage::GeneratePackageFile()
}
// Output stream
cmGeneratedFileStream fout((this->Directory + "/meta/package.xml").data());
cmGeneratedFileStream fout(this->Directory + "/meta/package.xml");
cmXMLWriter xout(fout);
xout.StartDocument();
......
......@@ -183,7 +183,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml()
this->Directory + "/repository/UpdatesPatch.xml";
// Output stream
cmGeneratedFileStream fout(updatesPatchXml.data());
cmGeneratedFileStream fout(updatesPatchXml);
cmXMLWriter xout(fout);
xout.StartDocument();
......
......@@ -103,7 +103,7 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(
*/
#define DECLARE_AND_OPEN_ARCHIVE(filename, archive) \
cmGeneratedFileStream gf; \
gf.Open((filename).c_str(), false, true); \
gf.Open((filename), false, true); \
if (!GenerateHeader(&gf)) { \
cmCPackLogger(cmCPackLog::LOG_ERROR, \
"Problem to generate Header for archive <" \
......
......@@ -238,7 +238,7 @@ int cmCPackDebGenerator::createDeb()
const std::string strGenWDIR(this->GetOption("GEN_WDIR"));
const std::string dbfilename = strGenWDIR + "/debian-binary";
{ // the scope is needed for cmGeneratedFileStream
cmGeneratedFileStream out(dbfilename.c_str());
cmGeneratedFileStream out(dbfilename);
out << "2.0";
out << std::endl; // required for valid debian package
}
......@@ -287,7 +287,7 @@ int cmCPackDebGenerator::createDeb()
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE");
{ // the scope is needed for cmGeneratedFileStream
cmGeneratedFileStream out(ctlfilename.c_str());
cmGeneratedFileStream out(ctlfilename);
out << "Package: " << debian_pkg_name << "\n";
out << "Version: " << debian_pkg_version << "\n";
out << "Section: " << debian_pkg_section << "\n";
......@@ -347,7 +347,7 @@ int cmCPackDebGenerator::createDeb()
const bool gen_shibs = this->IsOn("CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS") &&
debian_pkg_shlibs && *debian_pkg_shlibs;
if (gen_shibs) {
cmGeneratedFileStream out(shlibsfilename.c_str());
cmGeneratedFileStream out(shlibsfilename);
out << debian_pkg_shlibs;
out << std::endl;
}
......@@ -355,7 +355,7 @@ int cmCPackDebGenerator::createDeb()
const std::string postinst = strGenWDIR + "/postinst";
const std::string postrm = strGenWDIR + "/postrm";
if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) {
cmGeneratedFileStream out(postinst.c_str());
cmGeneratedFileStream out(postinst);
out << "#!/bin/sh\n\n"
"set -e\n\n"
"if [ \"$1\" = \"configure\" ]; then\n"
......@@ -363,7 +363,7 @@ int cmCPackDebGenerator::createDeb()
"fi\n";
}
if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) {
cmGeneratedFileStream out(postrm.c_str());
cmGeneratedFileStream out(postrm);
out << "#!/bin/sh\n\n"
"set -e\n\n"
"if [ \"$1\" = \"remove\" ]; then\n"
......@@ -412,7 +412,7 @@ int cmCPackDebGenerator::createDeb()
// atomic file generation for data.tar
{
cmGeneratedFileStream fileStream_data_tar;
fileStream_data_tar.Open(filename_data_tar.c_str(), false, true);
fileStream_data_tar.Open(filename_data_tar, false, true);
if (!fileStream_data_tar) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error opening the file \""
......@@ -493,7 +493,7 @@ int cmCPackDebGenerator::createDeb()
std::string md5filename = strGenWDIR + "/md5sums";
{
// the scope is needed for cmGeneratedFileStream
cmGeneratedFileStream out(md5filename.c_str());
cmGeneratedFileStream out(md5filename);
std::string topLevelWithTrailingSlash =
this->GetOption("CPACK_TEMPORARY_DIRECTORY");
......@@ -528,7 +528,7 @@ int cmCPackDebGenerator::createDeb()
// atomic file generation for control.tar
{
cmGeneratedFileStream fileStream_control_tar;
fileStream_control_tar.Open(filename_control_tar.c_str(), false, true);
fileStream_control_tar.Open(filename_control_tar, false, true);
if (!fileStream_control_tar) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error opening the file \"" << filename_control_tar
......@@ -662,7 +662,7 @@ int cmCPackDebGenerator::createDeb()
std::string const outputPath = outputDir + "/" + outputName;
std::string const tlDir = strGenWDIR + "/";
cmGeneratedFileStream debStream;
debStream.Open(outputPath.c_str(), false, true);
debStream.Open(outputPath, false, true);
cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd");
// uid/gid should be the one of the root user, and this root user has
......
......@@ -288,7 +288,7 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
if (!resB || retVal) {
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/InstallOutput.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << ic << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......@@ -660,7 +660,7 @@ int cmCPackGenerator::RunPreinstallTarget(
if (!resB || retVal) {
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/PreinstallOutput.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << buildCommand << std::endl
<< "# Directory: " << installDirectory << std::endl
<< "# Output:" << std::endl
......
......@@ -305,7 +305,7 @@ int cmCPackNSISGenerator::PackageFiles()
nsisCmd.c_str(), &output, &output, &retVal, nullptr,
this->GeneratorVerbose, cmDuration::zero());
if (!res || retVal) {
cmGeneratedFileStream ofs(tmpFile.c_str());
cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << nsisCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......@@ -416,7 +416,7 @@ int cmCPackNSISGenerator::InitializeInternal()
const char* topDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
std::string tmpFile = topDir ? topDir : ".";
tmpFile += "/NSISOutput.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << nsisCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......@@ -726,7 +726,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
cmSystemTools::IsOn(this->GetOption("CPACK_ZIP_NEED_QUOTES"));
unsigned long totalSize = 0;
{ // the scope is needed for cmGeneratedFileStream
cmGeneratedFileStream out(zipListFileName.c_str());
cmGeneratedFileStream out(zipListFileName);
for (std::string const& file : component->Files) {
if (needQuotesInFile) {
out << "\"";
......@@ -754,7 +754,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
if (!res || retVal) {
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/CompressZip.log";
cmGeneratedFileStream ofs(tmpFile.c_str());
cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << cmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
......
......@@ -742,7 +742,7 @@ void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
// Give some testing configuration information to the launcher.
std::string fname = this->Handler->CTestLaunchDir;
fname += "/CTestLaunchConfig.cmake";
cmGeneratedFileStream fout(fname.c_str());
cmGeneratedFileStream fout(fname);
std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
}
......@@ -757,7 +757,7 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers(
fname += "/Custom";
fname += purpose;
fname += ".txt";
cmGeneratedFileStream fout(fname.c_str());
cmGeneratedFileStream fout(fname);
for (std::string const& m : matchers) {
fout << m << "\n";
}
......
......@@ -345,7 +345,7 @@ void cmCTestLaunch::WriteXML()
logXML += ".xml";
// Use cmGeneratedFileStream to atomically create the report file.
cmGeneratedFileStream fxml(logXML.c_str());
cmGeneratedFileStream fxml(logXML);
cmXMLWriter xml(fxml, 2);
cmXMLElement e2(xml, "Failure");
e2.Attribute("type", this->IsError() ? "Error" : "Warning");
......
......@@ -792,7 +792,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Write CMake output to file: " << cmakeOutputFile
<< std::endl);
cmGeneratedFileStream fout(cmakeOutputFile.c_str());
cmGeneratedFileStream fout(cmakeOutputFile);
if (fout) {
fout << output.c_str();
} else {
......@@ -856,7 +856,7 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
{
std::string cacheFile = directory;
cacheFile += "/CMakeCache.txt";
cmGeneratedFileStream fout(cacheFile.c_str());
cmGeneratedFileStream fout(cacheFile);
if (!fout) {
return false;
}
......
......@@ -121,7 +121,7 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
// Log startup actions.
std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
cmGeneratedFileStream ofs(startLogFile.c_str());
cmGeneratedFileStream ofs(startLogFile);
if (!ofs) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create log file: LastStart.log" << std::endl);
......
......@@ -818,7 +818,7 @@ bool cmCTest::OpenOutputFile(const std::string& path, const std::string& name,
}
}
std::string filename = testingDir + "/" + name;
stream.Open(filename.c_str());
stream.Open(filename);
if (!stream) {
cmCTestLog(this, ERROR_MESSAGE,
"Problem opening file: " << filename << std::endl);
......
......@@ -234,7 +234,7 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger)
{
std::string cacheFile = path;
cacheFile += "/CMakeCache.txt";
cmGeneratedFileStream fout(cacheFile.c_str());
cmGeneratedFileStream fout(cacheFile);
fout.SetCopyIfDifferent(true);
if (!fout) {
cmSystemTools::Error("Unable to open cache file for save. ",
......
......@@ -178,7 +178,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
// Store the list of modules provided by this target.
std::string fiName = this->TargetDirectory;
fiName += "/fortran.internal";
cmGeneratedFileStream fiStream(fiName.c_str());
cmGeneratedFileStream fiStream(fiName);
fiStream << "# The fortran modules provided by this target.\n";
fiStream << "provides\n";
std::set<std::string> const& provides = this->Internal->TargetProvides;
......@@ -190,7 +190,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
if (!provides.empty()) {
std::string fcName = this->TargetDirectory;
fcName += "/cmake_clean_Fortran.cmake";
cmGeneratedFileStream fcStream(fcName.c_str());
cmGeneratedFileStream fcStream(fcName);
fcStream << "# Remove fortran modules provided by this target.\n";
fcStream << "FILE(REMOVE";
std::string currentBinDir =
......
......@@ -339,7 +339,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
fname += "/";
fname += hash;
if (!cmSystemTools::FileExists(fname)) {
cmGeneratedFileStream entry(fname.c_str(), true);
cmGeneratedFileStream entry(fname, true);
if (entry) {
entry << content << "\n";
} else {
......
......@@ -75,7 +75,7 @@ bool cmExportFileGenerator::GenerateImportFile()
} else {
// Generate atomically and with copy-if-different.
std::unique_ptr<cmGeneratedFileStream> ap(
new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
new cmGeneratedFileStream(this->MainImportFile, true));
ap->SetCopyIfDifferent(true);
foutPtr = std::move(ap);
}
......
......@@ -288,7 +288,7 @@ bool cmExportInstallFileGenerator::GenerateImportFileConfig(
fileName += this->FileExt;
// Open the output file to generate it.
cmGeneratedFileStream exportFileStream(fileName.c_str(), true);
cmGeneratedFileStream exportFileStream(fileName, true);
if (!exportFileStream) {
std::string se = cmSystemTools::GetLastSystemError();
std::ostringstream e;
......
......@@ -54,7 +54,7 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), std::ios::app);
} else {
std::unique_ptr<cmGeneratedFileStream> ap(
new cmGeneratedFileStream(this->Filename.c_str(), true));
new cmGeneratedFileStream(this->Filename, true));
ap->SetCopyIfDifferent(true);
foutPtr = std::move(ap);
}
......
......@@ -199,7 +199,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
{
const cmMakefile* mf = lgs[0]->GetMakefile();
cmGeneratedFileStream fout(filename.c_str());
cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
......@@ -476,7 +476,7 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
filename += "/";
filename += target->GetName();
filename += ".objlib";
cmGeneratedFileStream fout(filename.c_str());
cmGeneratedFileStream fout(filename);
if (fout) {
/* clang-format off */
fout << "# This is a dummy file for the OBJECT library "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment