diff options
Diffstat (limited to 'Source/CPack/cpack.cxx')
| -rw-r--r-- | Source/CPack/cpack.cxx | 187 |
1 files changed, 84 insertions, 103 deletions
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index f06946b..c228f07 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -5,10 +5,12 @@ #include <cstddef> #include <functional> #include <iostream> +#include <iterator> #include <map> #include <memory> #include <sstream> #include <string> +#include <type_traits> #include <utility> #include <vector> @@ -25,7 +27,6 @@ #include "cmConsoleBuf.h" #include "cmDocumentation.h" #include "cmDocumentationEntry.h" -#include "cmDocumentationFormatter.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" @@ -36,19 +37,14 @@ #include "cmake.h" namespace { -const char* cmDocumentationName[][2] = { - { nullptr, " cpack - Packaging driver provided by CMake." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + {}, + " cpack - Packaging driver provided by CMake." }; -const char* cmDocumentationUsage[][2] = { - // clang-format off - { nullptr, " cpack [options]" }, - { nullptr, nullptr } - // clang-format on -}; +const cmDocumentationEntry cmDocumentationUsage = { {}, " cpack [options]" }; -const char* cmDocumentationOptions[][2] = { +const cmDocumentationEntry cmDocumentationOptions[14] = { { "-G <generators>", "Override/define CPACK_GENERATOR" }, { "-C <Configuration>", "Specify the project configuration" }, { "-D <var>=<value>", "Set a CPack variable." }, @@ -62,14 +58,30 @@ const char* cmDocumentationOptions[][2] = { { "-B <packageDirectory>", "Override/define CPACK_PACKAGE_DIRECTORY" }, { "--vendor <vendorName>", "Override/define CPACK_PACKAGE_VENDOR" }, { "--preset", "Read arguments from a package preset" }, - { "--list-presets", "List available package presets" }, - { nullptr, nullptr } + { "--list-presets", "List available package presets" } }; void cpackProgressCallback(const std::string& message, float /*unused*/) { - std::cout << "-- " << message << std::endl; + std::cout << "-- " << message << '\n'; } + +std::vector<cmDocumentationEntry> makeGeneratorDocs( + const cmCPackGeneratorFactory& gf) +{ + const auto& generators = gf.GetGeneratorsList(); + + std::vector<cmDocumentationEntry> docs; + docs.reserve(generators.size()); + + std::transform( + generators.cbegin(), generators.cend(), std::back_inserter(docs), + [](const std::decay<decltype(generators)>::type::value_type& gen) { + return cmDocumentationEntry{ gen.first, gen.second }; + }); + return docs; +} + } // namespace // this is CPack. @@ -101,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; } @@ -129,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; }; @@ -194,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); @@ -262,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; } @@ -276,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; } @@ -284,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; } @@ -294,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; } @@ -302,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; } @@ -320,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; } @@ -329,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; } @@ -339,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; } @@ -395,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()) { @@ -423,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; } @@ -431,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; } @@ -444,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; } @@ -503,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 && @@ -522,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) { @@ -539,19 +543,12 @@ 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; - std::vector<cmDocumentationEntry> v; - for (auto const& g : generators.GetGeneratorsList()) { - cmDocumentationEntry e; - e.Name = g.first; - e.Brief = g.second; - v.push_back(std::move(e)); - } - generatorDocs.SetSection("Generators", v); - std::cerr << "\n"; + generatorDocs.SetSection("Generators", + makeGeneratorDocs(generators)); + std::cerr << '\n'; generatorDocs.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr); parsed = false; @@ -559,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; } @@ -573,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) { @@ -594,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()); } @@ -603,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; } } @@ -618,27 +613,13 @@ int main(int argc, char const* const* argv) */ if (help) { // Construct and print requested documentation. - doc.SetName("cpack"); doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); doc.PrependSection("Options", cmDocumentationOptions); - - std::vector<cmDocumentationEntry> v; - for (auto const& g : generators.GetGeneratorsList()) { - cmDocumentationEntry e; - e.Name = g.first; - e.Brief = g.second; - v.push_back(std::move(e)); - } - doc.SetSection("Generators", v); - - return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; - } - - if (cmSystemTools::GetErrorOccurredFlag()) { - return 1; + doc.SetSection("Generators", makeGeneratorDocs(generators)); + return !doc.PrintRequestedDocumentation(std::cout); } - return 0; + return int(cmSystemTools::GetErrorOccurredFlag()); } |
