cpack.cxx: Optimize calls to std::osteam::operator<<

This commit is contained in:
Alex Turbov
2022-10-26 13:32:57 +04:00
parent f6180485bb
commit df2047c2ac

View File

@@ -63,7 +63,7 @@ const cmDocumentationEntry cmDocumentationOptions[14] = {
void cpackProgressCallback(const std::string& message, float /*unused*/)
{
std::cout << "-- " << message << std::endl;
std::cout << "-- " << message << '\n';
}
std::vector<cmDocumentationEntry> makeGeneratorDocs(
@@ -113,8 +113,7 @@ int main(int argc, char const* const* argv)
if (cmSystemTools::GetCurrentWorkingDirectory().empty()) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Current working directory cannot be established."
<< std::endl);
"Current working directory cannot be established.\n");
return 1;
}
@@ -141,14 +140,14 @@ int main(int argc, char const* const* argv)
auto const verboseLambda = [&log](const std::string&, cmake*,
cmMakefile*) -> bool {
log.SetVerbose(true);
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl);
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose\n");
return true;
};
auto const debugLambda = [&log](const std::string&, cmake*,
cmMakefile*) -> bool {
log.SetDebug(true);
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl);
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug\n");
return true;
};
@@ -206,26 +205,25 @@ int main(int argc, char const* const* argv)
CommandArgument::setToValue(preset) },
CommandArgument{ "--list-presets", CommandArgument::Values::Zero,
CommandArgument::setToTrue(listPresets) },
CommandArgument{
"-D", CommandArgument::Values::One,
[&log, &definitions](const std::string& arg, cmake*,
cmMakefile*) -> bool {
std::string value = arg;
size_t pos = value.find_first_of('=');
if (pos == std::string::npos) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Please specify CPack definitions as: KEY=VALUE"
<< std::endl);
return false;
}
std::string key = value.substr(0, pos);
value.erase(0, pos + 1);
definitions[key] = value;
cmCPack_Log(&log, cmCPackLog::LOG_DEBUG,
"Set CPack variable: " << key << " to \"" << value << "\""
<< std::endl);
return true;
} },
CommandArgument{ "-D", CommandArgument::Values::One,
[&log, &definitions](const std::string& arg, cmake*,
cmMakefile*) -> bool {
std::string value = arg;
size_t pos = value.find_first_of('=');
if (pos == std::string::npos) {
cmCPack_Log(
&log, cmCPackLog::LOG_ERROR,
"Please specify CPack definitions as: KEY=VALUE\n");
return false;
}
std::string key = value.substr(0, pos);
value.erase(0, pos + 1);
definitions[key] = value;
cmCPack_Log(&log, cmCPackLog::LOG_DEBUG,
"Set CPack variable: " << key << " to \""
<< value << "\"\n");
return true;
} },
};
cmake cminst(cmake::RoleScript, cmState::CPack);
@@ -274,8 +272,7 @@ int main(int argc, char const* const* argv)
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Could not read presets from "
<< workingDirectory << ": "
<< cmCMakePresetsGraph::ResultToString(result)
<< std::endl);
<< cmCMakePresetsGraph::ResultToString(result) << '\n');
return 1;
}
@@ -288,7 +285,7 @@ int main(int argc, char const* const* argv)
if (presetPair == presetsGraph.PackagePresets.end()) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"No such package preset in " << workingDirectory << ": \""
<< preset << '"' << std::endl);
<< preset << "\"\n");
presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
return 1;
}
@@ -296,8 +293,7 @@ int main(int argc, char const* const* argv)
if (presetPair->second.Unexpanded.Hidden) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot use hidden package preset in "
<< workingDirectory << ": \"" << preset << '"'
<< std::endl);
<< workingDirectory << ": \"" << preset << "\"\n");
presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
return 1;
}
@@ -306,7 +302,7 @@ int main(int argc, char const* const* argv)
if (!expandedPreset) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Could not evaluate package preset \""
<< preset << "\": Invalid macro expansion" << std::endl);
<< preset << "\": Invalid macro expansion\n");
presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
return 1;
}
@@ -314,8 +310,7 @@ int main(int argc, char const* const* argv)
if (!expandedPreset->ConditionResult) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot use disabled package preset in "
<< workingDirectory << ": \"" << preset << '"'
<< std::endl);
<< workingDirectory << ": \"" << preset << "\"\n");
presetsGraph.PrintPackagePresetList(presetGeneratorsPresent);
return 1;
}
@@ -332,7 +327,7 @@ int main(int argc, char const* const* argv)
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"No such configure preset in "
<< workingDirectory << ": \""
<< expandedPreset->ConfigurePreset << '"' << std::endl);
<< expandedPreset->ConfigurePreset << "\"\n");
presetsGraph.PrintConfigurePresetList();
return 1;
}
@@ -341,7 +336,7 @@ int main(int argc, char const* const* argv)
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot use hidden configure preset in "
<< workingDirectory << ": \""
<< expandedPreset->ConfigurePreset << '"' << std::endl);
<< expandedPreset->ConfigurePreset << "\"\n");
presetsGraph.PrintConfigurePresetList();
return 1;
}
@@ -351,7 +346,7 @@ int main(int argc, char const* const* argv)
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Could not evaluate configure preset \""
<< expandedPreset->ConfigurePreset
<< "\": Invalid macro expansion" << std::endl);
<< "\": Invalid macro expansion\n");
return 1;
}
@@ -407,7 +402,7 @@ int main(int argc, char const* const* argv)
}
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Read CPack config file: " << cpackConfigFile << std::endl);
"Read CPack config file: " << cpackConfigFile << '\n');
bool cpackConfigFileSpecified = true;
if (cpackConfigFile.empty()) {
@@ -435,7 +430,7 @@ int main(int argc, char const* const* argv)
globalMF.GetModulesFile("CMakeDetermineSystem.cmake");
if (!globalMF.ReadListFile(systemFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error reading CMakeDetermineSystem.cmake" << std::endl);
"Error reading CMakeDetermineSystem.cmake\n");
return 1;
}
@@ -443,8 +438,7 @@ int main(int argc, char const* const* argv)
globalMF.GetModulesFile("CMakeSystemSpecificInformation.cmake");
if (!globalMF.ReadListFile(systemFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error reading CMakeSystemSpecificInformation.cmake"
<< std::endl);
"Error reading CMakeSystemSpecificInformation.cmake\n");
return 1;
}
@@ -456,17 +450,17 @@ int main(int argc, char const* const* argv)
cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile);
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Read CPack configuration file: " << cpackConfigFile
<< std::endl);
<< '\n');
if (!globalMF.ReadListFile(cpackConfigFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Problem reading CPack config file: \""
<< cpackConfigFile << "\"" << std::endl);
"Problem reading CPack config file: \"" << cpackConfigFile
<< "\"\n");
return 1;
}
} else if (cpackConfigFileSpecified) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot find CPack config file: \"" << cpackConfigFile
<< "\"" << std::endl);
<< "\"\n");
return 1;
}
@@ -515,17 +509,17 @@ int main(int argc, char const* const* argv)
cmValue genList = globalMF.GetDefinition("CPACK_GENERATOR");
if (!genList) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack generator not specified" << std::endl);
"CPack generator not specified\n");
} else {
std::vector<std::string> generatorsVector = cmExpandedList(*genList);
for (std::string const& gen : generatorsVector) {
cmMakefile::ScopePushPop raii(&globalMF);
cmMakefile* mf = &globalMF;
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Specified generator: " << gen << std::endl);
"Specified generator: " << gen << '\n');
if (!mf->GetDefinition("CPACK_PACKAGE_NAME")) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack project name not specified" << std::endl);
"CPack project name not specified" << '\n');
parsed = false;
}
if (parsed &&
@@ -534,13 +528,11 @@ int main(int argc, char const* const* argv)
mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")))) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack project version not specified"
<< std::endl
<< "Specify CPACK_PACKAGE_VERSION, or "
"CPACK_PACKAGE_VERSION_MAJOR, "
"CPACK_PACKAGE_VERSION_MINOR, and "
"CPACK_PACKAGE_VERSION_PATCH."
<< std::endl);
"CPack project version not specified\n"
"Specify CPACK_PACKAGE_VERSION, or "
"CPACK_PACKAGE_VERSION_MAJOR, "
"CPACK_PACKAGE_VERSION_MINOR, and "
"CPACK_PACKAGE_VERSION_PATCH.\n");
parsed = false;
}
if (parsed) {
@@ -551,8 +543,7 @@ int main(int argc, char const* const* argv)
cpackGenerator->SetTraceExpand(cminst.GetTraceExpand());
} else {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Could not create CPack generator: " << gen
<< std::endl);
"Could not create CPack generator: " << gen << '\n');
// Print out all the valid generators
cmDocumentation generatorDocs;
generatorDocs.SetSection("Generators",
@@ -565,8 +556,7 @@ int main(int argc, char const* const* argv)
if (parsed && !cpackGenerator->Initialize(gen, mf)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize the generator " << gen
<< std::endl);
"Cannot initialize the generator " << gen << '\n');
parsed = false;
}
@@ -579,17 +569,16 @@ int main(int argc, char const* const* argv)
"Please specify build tree of the project that uses CMake "
"using CPACK_INSTALL_CMAKE_PROJECTS, specify "
"CPACK_INSTALL_COMMANDS, CPACK_INSTALL_SCRIPT, or "
"CPACK_INSTALLED_DIRECTORIES."
<< std::endl);
"CPACK_INSTALLED_DIRECTORIES.\n");
parsed = false;
}
if (parsed) {
cmValue projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Use generator: " << cpackGenerator->GetNameOfClass()
<< std::endl);
<< '\n');
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"For project: " << *projName << std::endl);
"For project: " << *projName << '\n');
cmValue projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION");
if (!projVersion) {
@@ -600,7 +589,7 @@ int main(int argc, char const* const* argv)
cmValue projVersionPatch =
mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
std::ostringstream ostr;
ostr << *projVersionMajor << "." << *projVersionMinor << "."
ostr << *projVersionMajor << "." << *projVersionMinor << '.'
<< *projVersionPatch;
mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str());
}
@@ -609,7 +598,7 @@ int main(int argc, char const* const* argv)
if (!res) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error when generating package: " << *projName
<< std::endl);
<< '\n');
return 1;
}
}