diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 18:08:52 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 18:59:57 -0700 |
| commit | 1e9471a1489156720362ef12e1ec6849ea9b45b6 (patch) | |
| tree | 46f0f35093ecd18034c9f9463d6f8b7aa590ade0 /toolsrc/src | |
| parent | 75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f (diff) | |
| download | vcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.tar.gz vcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.zip | |
Run clang-format over the cpp files
Diffstat (limited to 'toolsrc/src')
55 files changed, 1328 insertions, 1178 deletions
diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index 99d7d230b..d545eee2a 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -1,13 +1,13 @@ #include "pch.h" + #include "BinaryParagraph.h" -#include "vcpkglib_helpers.h" #include "vcpkg_Checks.h" +#include "vcpkglib_helpers.h" using namespace vcpkg::details; namespace vcpkg { - // namespace BinaryParagraphRequiredField { static const std::string PACKAGE = "Package"; @@ -28,7 +28,8 @@ namespace vcpkg BinaryParagraph::BinaryParagraph(std::unordered_map<std::string, std::string> fields) { const std::string name = details::remove_required_field(&fields, BinaryParagraphRequiredField::PACKAGE); - const std::string architecture = details::remove_required_field(&fields, BinaryParagraphRequiredField::ARCHITECTURE); + const std::string architecture = + details::remove_required_field(&fields, BinaryParagraphRequiredField::ARCHITECTURE); const Triplet triplet = Triplet::from_canonical_name(architecture); this->spec = PackageSpec::from_name_and_triplet(name, triplet).value_or_exit(VCPKG_LINE_INFO); @@ -53,15 +54,9 @@ namespace vcpkg this->depends = filter_dependencies(spgh.depends, triplet); } - std::string BinaryParagraph::displayname() const - { - return this->spec.to_string(); - } + std::string BinaryParagraph::displayname() const { return this->spec.to_string(); } - std::string BinaryParagraph::dir() const - { - return this->spec.dir(); - } + std::string BinaryParagraph::dir() const { return this->spec.dir(); } std::string BinaryParagraph::fullstem() const { @@ -82,9 +77,7 @@ namespace vcpkg out_str.append("Architecture: ").append(pgh.spec.triplet().to_string()).push_back('\n'); out_str.append("Multi-Arch: same\n"); - if (!pgh.maintainer.empty()) - out_str.append("Maintainer: ").append(pgh.maintainer).push_back('\n'); - if (!pgh.description.empty()) - out_str.append("Description: ").append(pgh.description).push_back('\n'); + if (!pgh.maintainer.empty()) out_str.append("Maintainer: ").append(pgh.maintainer).push_back('\n'); + if (!pgh.description.empty()) out_str.append("Description: ").append(pgh.description).push_back('\n'); } } diff --git a/toolsrc/src/LineInfo.cpp b/toolsrc/src/LineInfo.cpp index e32d237f4..d1bf9a4b1 100644 --- a/toolsrc/src/LineInfo.cpp +++ b/toolsrc/src/LineInfo.cpp @@ -1,11 +1,9 @@ #include "pch.h" + #include "LineInfo.h" #include "vcpkg_Strings.h" namespace vcpkg { - std::string LineInfo::to_string() const - { - return Strings::format("%s(%d)", this->file_name, this->line_number); - } + std::string LineInfo::to_string() const { return Strings::format("%s(%d)", this->file_name, this->line_number); } } diff --git a/toolsrc/src/MachineType.cpp b/toolsrc/src/MachineType.cpp index 97d0a0280..f288855e6 100644 --- a/toolsrc/src/MachineType.cpp +++ b/toolsrc/src/MachineType.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "MachineType.h" #include "vcpkg_Checks.h" @@ -33,10 +34,8 @@ namespace vcpkg case MachineType::SH4: case MachineType::SH5: case MachineType::THUMB: - case MachineType::WCEMIPSV2: - return t; - default: - Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown machine type code 0x%x", value); + case MachineType::WCEMIPSV2: return t; + default: Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown machine type code 0x%x", value); } } } diff --git a/toolsrc/src/OptBool.cpp b/toolsrc/src/OptBool.cpp index 976321d97..78069df6a 100644 --- a/toolsrc/src/OptBool.cpp +++ b/toolsrc/src/OptBool.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "OptBool.h" #include "vcpkg_Checks.h" diff --git a/toolsrc/src/PackageSpec.cpp b/toolsrc/src/PackageSpec.cpp index a77ac45eb..af70dd615 100644 --- a/toolsrc/src/PackageSpec.cpp +++ b/toolsrc/src/PackageSpec.cpp @@ -1,13 +1,11 @@ #include "pch.h" + #include "PackageSpec.h" #include "vcpkg_Util.h" namespace vcpkg { - static bool is_valid_package_spec_char(char c) - { - return (c == '-') || isdigit(c) || (isalpha(c) && islower(c)); - } + static bool is_valid_package_spec_char(char c) { return (c == '-') || isdigit(c) || (isalpha(c) && islower(c)); } Expected<PackageSpec> PackageSpec::from_string(const std::string& spec_as_string, const Triplet& default_triplet) { @@ -41,33 +39,18 @@ namespace vcpkg return p; } - const std::string& PackageSpec::name() const - { - return this->m_name; - } + const std::string& PackageSpec::name() const { return this->m_name; } - const Triplet& PackageSpec::triplet() const - { - return this->m_triplet; - } + const Triplet& PackageSpec::triplet() const { return this->m_triplet; } - std::string PackageSpec::dir() const - { - return Strings::format("%s_%s", this->m_name, this->m_triplet); - } + std::string PackageSpec::dir() const { return Strings::format("%s_%s", this->m_name, this->m_triplet); } - std::string PackageSpec::to_string() const - { - return Strings::format("%s:%s", this->name(), this->triplet()); - } + std::string PackageSpec::to_string() const { return Strings::format("%s:%s", this->name(), this->triplet()); } bool operator==(const PackageSpec& left, const PackageSpec& right) { return left.name() == right.name() && left.triplet() == right.triplet(); } - bool operator!=(const PackageSpec& left, const PackageSpec& right) - { - return !(left == right); - } + bool operator!=(const PackageSpec& left, const PackageSpec& right) { return !(left == right); } } diff --git a/toolsrc/src/PackageSpecParseResult.cpp b/toolsrc/src/PackageSpecParseResult.cpp index 3fb2def0b..487c3aa1d 100644 --- a/toolsrc/src/PackageSpecParseResult.cpp +++ b/toolsrc/src/PackageSpecParseResult.cpp @@ -1,26 +1,22 @@ #include "pch.h" -#include "vcpkg_Checks.h" + #include "PackageSpecParseResult.h" +#include "vcpkg_Checks.h" namespace vcpkg { - const char* PackageSpecParseResultCategoryImpl::name() const noexcept - { - return "PackageSpecParseResult"; - } + const char* PackageSpecParseResultCategoryImpl::name() const noexcept { return "PackageSpecParseResult"; } std::string PackageSpecParseResultCategoryImpl::message(int ev) const noexcept { switch (static_cast<PackageSpecParseResult>(ev)) { - case PackageSpecParseResult::SUCCESS: - return "OK"; - case PackageSpecParseResult::TOO_MANY_COLONS: - return "Too many colons"; + case PackageSpecParseResult::SUCCESS: return "OK"; + case PackageSpecParseResult::TOO_MANY_COLONS: return "Too many colons"; case PackageSpecParseResult::INVALID_CHARACTERS: - return "Contains invalid characters. Only alphanumeric lowercase ASCII characters and dashes are allowed"; - default: - Checks::unreachable(VCPKG_LINE_INFO); + return "Contains invalid characters. Only alphanumeric lowercase ASCII characters and dashes are " + "allowed"; + default: Checks::unreachable(VCPKG_LINE_INFO); } } @@ -35,10 +31,7 @@ namespace vcpkg return std::error_code(static_cast<int>(e), package_spec_parse_result_category()); } - PackageSpecParseResult to_package_spec_parse_result(int i) - { - return static_cast<PackageSpecParseResult>(i); - } + PackageSpecParseResult to_package_spec_parse_result(int i) { return static_cast<PackageSpecParseResult>(i); } PackageSpecParseResult to_package_spec_parse_result(std::error_code ec) { diff --git a/toolsrc/src/ParagraphParseResult.cpp b/toolsrc/src/ParagraphParseResult.cpp index c2da78d30..5c8c1d59d 100644 --- a/toolsrc/src/ParagraphParseResult.cpp +++ b/toolsrc/src/ParagraphParseResult.cpp @@ -1,24 +1,19 @@ #include "pch.h" -#include "vcpkg_Checks.h" + #include "ParagraphParseResult.h" +#include "vcpkg_Checks.h" namespace vcpkg { - const char* ParagraphParseResultCategoryImpl::name() const noexcept - { - return "ParagraphParseResult"; - } + const char* ParagraphParseResultCategoryImpl::name() const noexcept { return "ParagraphParseResult"; } std::string ParagraphParseResultCategoryImpl::message(int ev) const noexcept { switch (static_cast<ParagraphParseResult>(ev)) { - case ParagraphParseResult::SUCCESS: - return "OK"; - case ParagraphParseResult::EXPECTED_ONE_PARAGRAPH: - return "There should be exactly one paragraph"; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case ParagraphParseResult::SUCCESS: return "OK"; + case ParagraphParseResult::EXPECTED_ONE_PARAGRAPH: return "There should be exactly one paragraph"; + default: Checks::unreachable(VCPKG_LINE_INFO); } } @@ -33,13 +28,7 @@ namespace vcpkg return std::error_code(static_cast<int>(e), paragraph_parse_result_category()); } - ParagraphParseResult to_paragraph_parse_result(int i) - { - return static_cast<ParagraphParseResult>(i); - } + ParagraphParseResult to_paragraph_parse_result(int i) { return static_cast<ParagraphParseResult>(i); } - ParagraphParseResult to_paragraph_parse_result(std::error_code ec) - { - return to_paragraph_parse_result(ec.value()); - } + ParagraphParseResult to_paragraph_parse_result(std::error_code ec) { return to_paragraph_parse_result(ec.value()); } } diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index f14552169..36ef8b9ac 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -1,13 +1,14 @@ #include "pch.h" + +#include "ParagraphParseResult.h" #include "Paragraphs.h" #include "vcpkg_Files.h" -#include "ParagraphParseResult.h" namespace vcpkg::Paragraphs { struct Parser { - Parser(const char* c, const char* e) : cur(c), end(e) { } + Parser(const char* c, const char* e) : cur(c), end(e) {} private: const char* cur; @@ -36,10 +37,8 @@ namespace vcpkg::Paragraphs { while (ch != '\r' && ch != '\n' && ch != '\0') next(ch); - if (ch == '\r') - next(ch); - if (ch == '\n') - next(ch); + if (ch == '\r') next(ch); + if (ch == '\n') next(ch); } void skip_spaces(char& ch) @@ -50,20 +49,12 @@ namespace vcpkg::Paragraphs static bool is_alphanum(char ch) { - return (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z') - || (ch >= '0' && ch <= '9'); + return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9'); } - static bool is_comment(char ch) - { - return (ch == '#'); - } + static bool is_comment(char ch) { return (ch == '#'); } - static bool is_lineend(char ch) - { - return ch == '\r' || ch == '\n' || ch == 0; - } + static bool is_lineend(char ch) { return ch == '\r' || ch == '\n' || ch == 0; } void get_fieldvalue(char& ch, std::string& fieldvalue) { @@ -78,10 +69,8 @@ namespace vcpkg::Paragraphs fieldvalue.append(beginning_of_line, cur); - if (ch == '\r') - next(ch); - if (ch == '\n') - next(ch); + if (ch == '\r') next(ch); + if (ch == '\n') next(ch); if (is_alphanum(ch) || is_comment(ch)) { @@ -106,8 +95,7 @@ namespace vcpkg::Paragraphs // First nonspace is not a newline. This continues the current field value. // We forcibly convert all newlines into single '\n' for ease of text handling later on. fieldvalue.push_back('\n'); - } - while (true); + } while (true); } void get_fieldname(char& ch, std::string& fieldname) @@ -144,8 +132,7 @@ namespace vcpkg::Paragraphs get_fieldvalue(ch, fieldvalue); fields.emplace(fieldname, fieldvalue); - } - while (!is_lineend(ch)); + } while (!is_lineend(ch)); } public: @@ -172,7 +159,8 @@ namespace vcpkg::Paragraphs } }; - Expected<std::unordered_map<std::string, std::string>> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path) + Expected<std::unordered_map<std::string, std::string>> get_single_paragraph(const Files::Filesystem& fs, + const fs::path& control_path) { const Expected<std::string> contents = fs.read_contents(control_path); if (auto spgh = contents.get()) @@ -183,7 +171,8 @@ namespace vcpkg::Paragraphs return contents.error_code(); } - Expected<std::vector<std::unordered_map<std::string, std::string>>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path) + Expected<std::vector<std::unordered_map<std::string, std::string>>> get_paragraphs(const Files::Filesystem& fs, + const fs::path& control_path) { const Expected<std::string> contents = fs.read_contents(control_path); if (auto spgh = contents.get()) @@ -196,7 +185,8 @@ namespace vcpkg::Paragraphs Expected<std::unordered_map<std::string, std::string>> parse_single_paragraph(const std::string& str) { - const std::vector<std::unordered_map<std::string, std::string>> p = Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); + const std::vector<std::unordered_map<std::string, std::string>> p = + Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); if (p.size() == 1) { @@ -224,7 +214,8 @@ namespace vcpkg::Paragraphs Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec) { - Expected<std::unordered_map<std::string, std::string>> pghs = get_single_paragraph(paths.get_filesystem(), paths.package_dir(spec) / "CONTROL"); + Expected<std::unordered_map<std::string, std::string>> pghs = + get_single_paragraph(paths.get_filesystem(), paths.package_dir(spec) / "CONTROL"); if (auto p = pghs.get()) { @@ -249,7 +240,8 @@ namespace vcpkg::Paragraphs return output; } - std::map<std::string, VersionT> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs) + std::map<std::string, VersionT> + extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs) { std::map<std::string, VersionT> names_and_versions; for (const SourceParagraph& port : source_paragraphs) diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index f1e1dcd17..4d689b624 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -1,22 +1,20 @@ #include "pch.h" -#include "VcpkgPaths.h" + #include "PackageSpec.h" -#include "vcpkg_Files.h" -#include "vcpkg_Util.h" -#include "vcpkg_System.h" -#include "coff_file_reader.h" +#include "PostBuildLint.h" #include "PostBuildLint_BuildInfo.h" #include "PostBuildLint_BuildType.h" -#include "PostBuildLint.h" +#include "VcpkgPaths.h" +#include "coff_file_reader.h" +#include "vcpkg_Files.h" +#include "vcpkg_System.h" +#include "vcpkg_Util.h" namespace vcpkg::PostBuildLint { static auto has_extension_pred(const Files::Filesystem& fs, const std::string& ext) { - return [&fs, ext](const fs::path& path) - { - return !fs.is_directory(path) && path.extension() == ext; - }; + return [&fs, ext](const fs::path& path) { return !fs.is_directory(path) && path.extension() == ext; }; } enum class LintStatus @@ -31,32 +29,31 @@ namespace vcpkg::PostBuildLint std::regex regex; OutdatedDynamicCrt(const std::string& name, const std::string& regex_as_string) - : name(name) - , regex(std::regex(regex_as_string, std::regex_constants::icase)) {} + : name(name), regex(std::regex(regex_as_string, std::regex_constants::icase)) + { + } }; const std::vector<OutdatedDynamicCrt>& get_outdated_dynamic_crts() { - static const std::vector<OutdatedDynamicCrt> v = { - { "msvcp100.dll", R"(msvcp100\.dll)" }, - { "msvcp100d.dll", R"(msvcp100d\.dll)" }, - { "msvcp110.dll", R"(msvcp110\.dll)" }, - { "msvcp110_win.dll", R"(msvcp110_win\.dll)" }, - { "msvcp120.dll", R"(msvcp120\.dll)" }, - { "msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)" }, - { "msvcp60.dll", R"(msvcp60\.dll)" }, - { "msvcp60.dll", R"(msvcp60\.dll)" }, - - { "msvcr100.dll", R"(msvcr100\.dll)" }, - { "msvcr100d.dll", R"(msvcr100d\.dll)" }, - { "msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)" }, - { "msvcr110.dll", R"(msvcr110\.dll)" }, - { "msvcr120.dll", R"(msvcr120\.dll)" }, - { "msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)" }, - { "msvcrt.dll", R"(msvcrt\.dll)" }, - { "msvcrt20.dll", R"(msvcrt20\.dll)" }, - { "msvcrt40.dll", R"(msvcrt40\.dll)" } - }; + static const std::vector<OutdatedDynamicCrt> v = { { "msvcp100.dll", R"(msvcp100\.dll)" }, + { "msvcp100d.dll", R"(msvcp100d\.dll)" }, + { "msvcp110.dll", R"(msvcp110\.dll)" }, + { "msvcp110_win.dll", R"(msvcp110_win\.dll)" }, + { "msvcp120.dll", R"(msvcp120\.dll)" }, + { "msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)" }, + { "msvcp60.dll", R"(msvcp60\.dll)" }, + { "msvcp60.dll", R"(msvcp60\.dll)" }, + + { "msvcr100.dll", R"(msvcr100\.dll)" }, + { "msvcr100d.dll", R"(msvcr100d\.dll)" }, + { "msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)" }, + { "msvcr110.dll", R"(msvcr110\.dll)" }, + { "msvcr120.dll", R"(msvcr120\.dll)" }, + { "msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)" }, + { "msvcrt.dll", R"(msvcrt\.dll)" }, + { "msvcrt20.dll", R"(msvcrt20\.dll)" }, + { "msvcrt40.dll", R"(msvcrt40\.dll)" } }; return v; } @@ -73,7 +70,9 @@ namespace vcpkg::PostBuildLint return false; } - static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies, OptBool>& policies, const fs::path& package_dir) + static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, + const std::map<BuildPolicies, OptBool>& policies, + const fs::path& package_dir) { if (contains_and_enabled(policies, BuildPoliciesC::EMPTY_INCLUDE_FOLDER)) { @@ -83,29 +82,30 @@ namespace vcpkg::PostBuildLint const fs::path include_dir = package_dir / "include"; if (!fs.exists(include_dir) || fs.is_empty(include_dir)) { - System::println(System::Color::warning, "The folder /include is empty. This indicates the library was not correctly installed."); + System::println(System::Color::warning, + "The folder /include is empty. This indicates the library was not correctly installed."); return LintStatus::ERROR_DETECTED; } return LintStatus::SUCCESS; } - static LintStatus check_for_files_in_debug_include_directory(const Files::Filesystem& fs, const fs::path& package_dir) + static LintStatus check_for_files_in_debug_include_directory(const Files::Filesystem& fs, + const fs::path& package_dir) { const fs::path debug_include_dir = package_dir / "debug" / "include"; std::vector<fs::path> files_found = fs.get_files_recursive(debug_include_dir); - Util::unstable_keep_if(files_found, [&fs](const fs::path& path) - { - return !fs.is_directory(path) && path.extension() != ".ifc"; - }); + Util::unstable_keep_if( + files_found, [&fs](const fs::path& path) { return !fs.is_directory(path) && path.extension() != ".ifc"; }); if (!files_found.empty()) { - System::println(System::Color::warning, "Include files should not be duplicated into the /debug/include directory. If this cannot be disabled in the project cmake, use\n" - " file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)" - ); + System::println(System::Color::warning, + "Include files should not be duplicated into the /debug/include directory. If this cannot " + "be disabled in the project cmake, use\n" + " file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)"); return LintStatus::ERROR_DETECTED; } @@ -118,7 +118,8 @@ namespace vcpkg::PostBuildLint if (fs.exists(debug_share)) { - System::println(System::Color::warning, "/debug/share should not exist. Please reorganize any important files, then use\n" + System::println(System::Color::warning, + "/debug/share should not exist. Please reorganize any important files, then use\n" " file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)"); return LintStatus::ERROR_DETECTED; } @@ -126,22 +127,28 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static LintStatus check_folder_lib_cmake(const Files::Filesystem& fs, const fs::path& package_dir, const PackageSpec& spec) + static LintStatus check_folder_lib_cmake(const Files::Filesystem& fs, + const fs::path& package_dir, + const PackageSpec& spec) { const fs::path lib_cmake = package_dir / "lib" / "cmake"; if (fs.exists(lib_cmake)) { - System::println(System::Color::warning, "The /lib/cmake folder should be merged with /debug/lib/cmake and moved to /share/%s/cmake.", spec.name()); + System::println( + System::Color::warning, + "The /lib/cmake folder should be merged with /debug/lib/cmake and moved to /share/%s/cmake.", + spec.name()); return LintStatus::ERROR_DETECTED; } return LintStatus::SUCCESS; } - static LintStatus check_for_misplaced_cmake_files(const Files::Filesystem& fs, const fs::path& package_dir, const PackageSpec& spec) + static LintStatus check_for_misplaced_cmake_files(const Files::Filesystem& fs, + const fs::path& package_dir, + const PackageSpec& spec) { - std::vector<fs::path> dirs = - { + std::vector<fs::path> dirs = { package_dir / "cmake", package_dir / "debug" / "cmake", package_dir / "lib" / "cmake", @@ -161,7 +168,11 @@ namespace vcpkg::PostBuildLint if (!misplaced_cmake_files.empty()) { - System::println(System::Color::warning, "The following cmake files were found outside /share/%s. Please place cmake files in /share/%s.", spec.name(), spec.name()); + System::println( + System::Color::warning, + "The following cmake files were found outside /share/%s. Please place cmake files in /share/%s.", + spec.name(), + spec.name()); Files::print_paths(misplaced_cmake_files); return LintStatus::ERROR_DETECTED; } @@ -169,12 +180,16 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static LintStatus check_folder_debug_lib_cmake(const Files::Filesystem& fs, const fs::path& package_dir, const PackageSpec& spec) + static LintStatus check_folder_debug_lib_cmake(const Files::Filesystem& fs, + const fs::path& package_dir, + const PackageSpec& spec) { const fs::path lib_cmake_debug = package_dir / "debug" / "lib" / "cmake"; if (fs.exists(lib_cmake_debug)) { - System::println(System::Color::warning, "The /debug/lib/cmake folder should be merged with /lib/cmake into /share/%s", spec.name()); + System::println(System::Color::warning, + "The /debug/lib/cmake folder should be merged with /lib/cmake into /share/%s", + spec.name()); return LintStatus::ERROR_DETECTED; } @@ -188,7 +203,9 @@ namespace vcpkg::PostBuildLint if (!dlls.empty()) { - System::println(System::Color::warning, "\nThe following dlls were found in /lib or /debug/lib. Please move them to /bin or /debug/bin, respectively."); + System::println(System::Color::warning, + "\nThe following dlls were found in /lib or /debug/lib. Please move them to /bin or " + "/debug/bin, respectively."); Files::print_paths(dlls); return LintStatus::ERROR_DETECTED; } @@ -196,7 +213,9 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static LintStatus check_for_copyright_file(const Files::Filesystem& fs, const PackageSpec& spec, const VcpkgPaths& paths) + static LintStatus check_for_copyright_file(const Files::Filesystem& fs, + const PackageSpec& spec, + const VcpkgPaths& paths) { const fs::path packages_dir = paths.packages / spec.dir(); const fs::path copyright_file = packages_dir / "share" / spec.name() / "copyright"; @@ -212,8 +231,7 @@ namespace vcpkg::PostBuildLint auto src_dirs = fs.get_files_non_recursive(current_buildtrees_dir_src); for (auto&& src_dir : src_dirs) { - if (!fs.is_directory(src_dir)) - continue; + if (!fs.is_directory(src_dir)) continue; for (auto&& src_file : fs.get_files_non_recursive(src_dir)) { @@ -226,14 +244,23 @@ namespace vcpkg::PostBuildLint } } - System::println(System::Color::warning, "The software license must be available at ${CURRENT_PACKAGES_DIR}/share/%s/copyright", spec.name()); - if (potential_copyright_files.size() == 1) // if there is only one candidate, provide the cmake lines needed to place it in the proper location + System::println(System::Color::warning, + "The software license must be available at ${CURRENT_PACKAGES_DIR}/share/%s/copyright", + spec.name()); + if (potential_copyright_files.size() == + 1) // if there is only one candidate, provide the cmake lines needed to place it in the proper location { const fs::path found_file = potential_copyright_files[0]; - const fs::path relative_path = found_file.string().erase(0, current_buildtrees_dir.string().size() + 1); // The +1 is needed to remove the "/" - System::println("\n file(COPY ${CURRENT_BUILDTREES_DIR}/%s DESTINATION ${CURRENT_PACKAGES_DIR}/share/%s)\n" - " file(RENAME ${CURRENT_PACKAGES_DIR}/share/%s/%s ${CURRENT_PACKAGES_DIR}/share/%s/copyright)", - relative_path.generic_string(), spec.name(), spec.name(), found_file.filename().generic_string(), spec.name()); + const fs::path relative_path = found_file.string().erase( + 0, current_buildtrees_dir.string().size() + 1); // The +1 is needed to remove the "/" + System::println( + "\n file(COPY ${CURRENT_BUILDTREES_DIR}/%s DESTINATION ${CURRENT_PACKAGES_DIR}/share/%s)\n" + " file(RENAME ${CURRENT_PACKAGES_DIR}/share/%s/%s ${CURRENT_PACKAGES_DIR}/share/%s/copyright)", + relative_path.generic_string(), + spec.name(), + spec.name(), + found_file.filename().generic_string(), + spec.name()); } else if (potential_copyright_files.size() > 1) { @@ -250,7 +277,9 @@ namespace vcpkg::PostBuildLint if (!exes.empty()) { - System::println(System::Color::warning, "The following EXEs were found in /bin or /debug/bin. EXEs are not valid distribution targets."); + System::println( + System::Color::warning, + "The following EXEs were found in /bin or /debug/bin. EXEs are not valid distribution targets."); Files::print_paths(exes); return LintStatus::ERROR_DETECTED; } @@ -263,9 +292,13 @@ namespace vcpkg::PostBuildLint std::vector<fs::path> dlls_with_no_exports; for (const fs::path& dll : dlls) { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /exports "%s")", dumpbin_exe.native(), dll.native()); + const std::wstring cmd_line = + Strings::wformat(LR"("%s" /exports "%s")", dumpbin_exe.native(), dll.native()); System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + ec_data.exit_code == 0, + "Running command:\n %s\n failed", + Strings::utf16_to_utf8(cmd_line)); if (ec_data.output.find("ordinal hint RVA name") == std::string::npos) { @@ -284,7 +317,9 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static LintStatus check_uwp_bit_of_dlls(const std::string& expected_system_name, const std::vector<fs::path>& dlls, const fs::path dumpbin_exe) + static LintStatus check_uwp_bit_of_dlls(const std::string& expected_system_name, + const std::vector<fs::path>& dlls, + const fs::path dumpbin_exe) { if (expected_system_name != "uwp") { @@ -294,9 +329,13 @@ namespace vcpkg::PostBuildLint std::vector<fs::path> dlls_with_improper_uwp_bit; for (const fs::path& dll : dlls) { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /headers "%s")", dumpbin_exe.native(), dll.native()); + const std::wstring cmd_line = + Strings::wformat(LR"("%s" /headers "%s")", dumpbin_exe.native(), dll.native()); System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + ec_data.exit_code == 0, + "Running command:\n %s\n failed", + Strings::utf16_to_utf8(cmd_line)); if (ec_data.output.find("App Container") == std::string::npos) { @@ -326,19 +365,16 @@ namespace vcpkg::PostBuildLint switch (machine_type) { case MachineType::AMD64: - case MachineType::IA64: - return "x64"; - case MachineType::I386: - return "x86"; + case MachineType::IA64: return "x64"; + case MachineType::I386: return "x86"; case MachineType::ARM: - case MachineType::ARMNT: - return "arm"; - default: - return "Machine Type Code = " + std::to_string(static_cast<uint16_t>(machine_type)); + case MachineType::ARMNT: return "arm"; + default: return "Machine Type Code = " + std::to_string(static_cast<uint16_t>(machine_type)); } } - static void print_invalid_architecture_files(const std::string& expected_architecture, std::vector<FileAndArch> binaries_with_invalid_architecture) + static void print_invalid_architecture_files(const std::string& expected_architecture, + std::vector<FileAndArch> binaries_with_invalid_architecture) { System::println(System::Color::warning, "The following files were built for an incorrect architecture:"); System::println(""); @@ -350,13 +386,17 @@ namespace vcpkg::PostBuildLint } } - static LintStatus check_dll_architecture(const std::string& expected_architecture, const std::vector<fs::path>& files) + static LintStatus check_dll_architecture(const std::string& expected_architecture, + const std::vector<fs::path>& files) { std::vector<FileAndArch> binaries_with_invalid_architecture; for (const fs::path& file : files) { - Checks::check_exit(VCPKG_LINE_INFO, file.extension() == ".dll", "The file extension was not .dll: %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, + file.extension() == ".dll", + "The file extension was not .dll: %s", + file.generic_string()); COFFFileReader::DllInfo info = COFFFileReader::read_dll(file); const std::string actual_architecture = get_actual_architecture(info.machine_type); @@ -375,15 +415,22 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static LintStatus check_lib_architecture(const std::string& expected_architecture, const std::vector<fs::path>& files) + static LintStatus check_lib_architecture(const std::string& expected_architecture, + const std::vector<fs::path>& files) { std::vector<FileAndArch> binaries_with_invalid_architecture; for (const fs::path& file : files) { - Checks::check_exit(VCPKG_LINE_INFO, file.extension() == ".lib", "The file extension was not .lib: %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, + file.extension() == ".lib", + "The file extension was not .lib: %s", + file.generic_string()); COFFFileReader::LibInfo info = COFFFileReader::read_lib(file); - Checks::check_exit(VCPKG_LINE_INFO, info.machine_types.size() == 1, "Found more than 1 architecture in file %s", file.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, + info.machine_types.size() == 1, + "Found more than 1 architecture in file %s", + file.generic_string()); const std::string actual_architecture = get_actual_architecture(info.machine_types.at(0)); if (expected_architecture != actual_architecture) @@ -408,12 +455,14 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - System::println(System::Color::warning, "DLLs should not be present in a static build, but the following DLLs were found:"); + System::println(System::Color::warning, + "DLLs should not be present in a static build, but the following DLLs were found:"); Files::print_paths(dlls); return LintStatus::ERROR_DETECTED; } - static LintStatus check_matching_debug_and_release_binaries(const std::vector<fs::path>& debug_binaries, const std::vector<fs::path>& release_binaries) + static LintStatus check_matching_debug_and_release_binaries(const std::vector<fs::path>& debug_binaries, + const std::vector<fs::path>& release_binaries) { const size_t debug_count = debug_binaries.size(); const size_t release_count = release_binaries.size(); @@ -422,7 +471,10 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - System::println(System::Color::warning, "Mismatching number of debug and release binaries. Found %d for debug but %d for release.", debug_count, release_count); + System::println(System::Color::warning, + "Mismatching number of debug and release binaries. Found %d for debug but %d for release.", + debug_count, + release_count); System::println("Debug binaries"); Files::print_paths(debug_binaries); @@ -443,7 +495,11 @@ namespace vcpkg::PostBuildLint return LintStatus::ERROR_DETECTED; } - static LintStatus check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies, OptBool>& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) + static LintStatus + check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies, OptBool>& policies, + const size_t lib_count, + const size_t dll_count, + const fs::path& lib_dir) { auto it = policies.find(BuildPoliciesC::DLLS_WITHOUT_LIBS); if (it != policies.cend() && it->second == OptBoolC::ENABLED) @@ -456,14 +512,16 @@ namespace vcpkg::PostBuildLint System::println(System::Color::warning, "Import libs were not present in %s", lib_dir.u8string()); System::println(System::Color::warning, "If this is intended, add the following line in the portfile:\n" - " SET(%s enabled)", BuildPoliciesC::DLLS_WITHOUT_LIBS.cmake_variable()); + " SET(%s enabled)", + BuildPoliciesC::DLLS_WITHOUT_LIBS.cmake_variable()); return LintStatus::ERROR_DETECTED; } return LintStatus::SUCCESS; } - static LintStatus check_bin_folders_are_not_present_in_static_build(const Files::Filesystem& fs, const fs::path& package_dir) + static LintStatus check_bin_folders_are_not_present_in_static_build(const Files::Filesystem& fs, + const fs::path& package_dir) { const fs::path bin = package_dir / "bin"; const fs::path debug_bin = package_dir / "debug" / "bin"; @@ -475,21 +533,29 @@ namespace vcpkg::PostBuildLint if (fs.exists(bin)) { - System::println(System::Color::warning, R"(There should be no bin\ directory in a static build, but %s is present.)", bin.u8string()); + System::println(System::Color::warning, + R"(There should be no bin\ directory in a static build, but %s is present.)", + bin.u8string()); } if (fs.exists(debug_bin)) { - System::println(System::Color::warning, R"(There should be no debug\bin\ directory in a static build, but %s is present.)", debug_bin.u8string()); - } - - System::println(System::Color::warning, R"(If the creation of bin\ and/or debug\bin\ cannot be disabled, use this in the portfile to remove them)" "\n" - "\n" - R"###( if(VCPKG_LIBRARY_LINKAGE STREQUAL static))###""\n" - R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin))###""\n" - R"###( endif())###" - "\n" - ); + System::println(System::Color::warning, + R"(There should be no debug\bin\ directory in a static build, but %s is present.)", + debug_bin.u8string()); + } + + System::println( + System::Color::warning, + R"(If the creation of bin\ and/or debug\bin\ cannot be disabled, use this in the portfile to remove them)" + "\n" + "\n" + R"###( if(VCPKG_LIBRARY_LINKAGE STREQUAL static))###" + "\n" + R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin))###" + "\n" + R"###( endif())###" + "\n"); return LintStatus::ERROR_DETECTED; } @@ -498,21 +564,24 @@ namespace vcpkg::PostBuildLint { std::vector<fs::path> empty_directories = fs.get_files_recursive(dir); - Util::unstable_keep_if(empty_directories, [&fs](const fs::path& current) - { - return fs.is_directory(current) && fs.is_empty(current); - }); + Util::unstable_keep_if(empty_directories, [&fs](const fs::path& current) { + return fs.is_directory(current) && fs.is_empty(current); + }); if (!empty_directories.empty()) { System::println(System::Color::warning, "There should be no empty directories in %s", dir.generic_string()); System::println("The following empty directories were found: "); Files::print_paths(empty_directories); - System::println(System::Color::warning, "If a directory should be populated but is not, this might indicate an error in the portfile.\n" - "If the directories are not needed and their creation cannot be disabled, use something like this in the portfile to remove them:\n" - "\n" - R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/a/dir ${CURRENT_PACKAGES_DIR}/some/other/dir))###""\n" - "\n"); + System::println( + System::Color::warning, + "If a directory should be populated but is not, this might indicate an error in the portfile.\n" + "If the directories are not needed and their creation cannot be disabled, use something like this in " + "the portfile to remove them:\n" + "\n" + R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/a/dir ${CURRENT_PACKAGES_DIR}/some/other/dir))###" + "\n" + "\n"); return LintStatus::ERROR_DETECTED; } @@ -525,18 +594,25 @@ namespace vcpkg::PostBuildLint BuildType build_type; }; - static LintStatus check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector<fs::path>& libs, const fs::path dumpbin_exe) + static LintStatus check_crt_linkage_of_libs(const BuildType& expected_build_type, + const std::vector<fs::path>& libs, + const fs::path dumpbin_exe) { std::vector<BuildType> bad_build_types(BuildTypeC::VALUES.cbegin(), BuildTypeC::VALUES.cend()); - bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end()); + bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), + bad_build_types.end()); std::vector<BuildType_and_file> libs_with_invalid_crt; for (const fs::path& lib : libs) { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /directives "%s")", dumpbin_exe.native(), lib.native()); + const std::wstring cmd_line = + Strings::wformat(LR"("%s" /directives "%s")", dumpbin_exe.native(), lib.native()); System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + ec_data.exit_code == 0, + "Running command:\n %s\n failed", + Strings::utf16_to_utf8(cmd_line)); for (const BuildType& bad_build_type : bad_build_types) { @@ -550,7 +626,9 @@ namespace vcpkg::PostBuildLint if (!libs_with_invalid_crt.empty()) { - System::println(System::Color::warning, "Expected %s crt linkage, but the following libs had invalid crt linkage:", expected_build_type.to_string()); + System::println(System::Color::warning, + "Expected %s crt linkage, but the following libs had invalid crt linkage:", + expected_build_type.to_string()); System::println(""); for (const BuildType_and_file btf : libs_with_invalid_crt) { @@ -558,7 +636,8 @@ namespace vcpkg::PostBuildLint } System::println(""); - System::println(System::Color::warning, "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); + System::println(System::Color::warning, + "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); return LintStatus::ERROR_DETECTED; } @@ -581,9 +660,13 @@ namespace vcpkg::PostBuildLint for (const fs::path& dll : dlls) { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native()); + const std::wstring cmd_line = + Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native()); System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + ec_data.exit_code == 0, + "Running command:\n %s\n failed", + Strings::utf16_to_utf8(cmd_line)); for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) { @@ -605,7 +688,8 @@ namespace vcpkg::PostBuildLint } System::println(""); - System::println(System::Color::warning, "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll"); + System::println(System::Color::warning, + "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll"); return LintStatus::ERROR_DETECTED; } @@ -615,13 +699,12 @@ namespace vcpkg::PostBuildLint static LintStatus check_no_files_in_dir(const Files::Filesystem& fs, const fs::path& dir) { std::vector<fs::path> misplaced_files = fs.get_files_non_recursive(dir); - Util::unstable_keep_if(misplaced_files, [&fs](const fs::path& path) - { - const std::string filename = path.filename().generic_string(); - if (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0) - return false; - return !fs.is_directory(path); - }); + Util::unstable_keep_if(misplaced_files, [&fs](const fs::path& path) { + const std::string filename = path.filename().generic_string(); + if (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0) + return false; + return !fs.is_directory(path); + }); if (!misplaced_files.empty()) { @@ -634,10 +717,7 @@ namespace vcpkg::PostBuildLint return LintStatus::SUCCESS; } - static void operator +=(size_t& left, const LintStatus& right) - { - left += static_cast<size_t>(right); - } + static void operator+=(size_t& left, const LintStatus& right) { left += static_cast<size_t>(right); } static size_t perform_all_checks_and_return_error_count(const PackageSpec& spec, const VcpkgPaths& paths) { @@ -691,46 +771,53 @@ namespace vcpkg::PostBuildLint switch (build_info.library_linkage) { case LinkageType::BackingEnum::DYNAMIC: - { - std::vector<fs::path> debug_dlls = fs.get_files_recursive(debug_bin_dir); - Util::unstable_keep_if(debug_dlls, has_extension_pred(fs, ".dll")); - std::vector<fs::path> release_dlls = fs.get_files_recursive(release_bin_dir); - Util::unstable_keep_if(release_dlls, has_extension_pred(fs, ".dll")); + { + std::vector<fs::path> debug_dlls = fs.get_files_recursive(debug_bin_dir); + Util::unstable_keep_if(debug_dlls, has_extension_pred(fs, ".dll")); + std::vector<fs::path> release_dlls = fs.get_files_recursive(release_bin_dir); + Util::unstable_keep_if(release_dlls, has_extension_pred(fs, ".dll")); - error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); + error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); - error_count += check_lib_files_are_available_if_dlls_are_available(build_info.policies, debug_libs.size(), debug_dlls.size(), debug_lib_dir); - error_count += check_lib_files_are_available_if_dlls_are_available(build_info.policies, release_libs.size(), release_dlls.size(), release_lib_dir); + error_count += check_lib_files_are_available_if_dlls_are_available( + build_info.policies, debug_libs.size(), debug_dlls.size(), debug_lib_dir); + error_count += check_lib_files_are_available_if_dlls_are_available( + build_info.policies, release_libs.size(), release_dlls.size(), release_lib_dir); - std::vector<fs::path> dlls; - dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); - dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); + std::vector<fs::path> dlls; + dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); + dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); - error_count += check_exports_of_dlls(dlls, toolset.dumpbin); - error_count += check_uwp_bit_of_dlls(spec.triplet().system(), dlls, toolset.dumpbin); - error_count += check_dll_architecture(spec.triplet().architecture(), dlls); + error_count += check_exports_of_dlls(dlls, toolset.dumpbin); + error_count += check_uwp_bit_of_dlls(spec.triplet().system(), dlls, toolset.dumpbin); + error_count += check_dll_architecture(spec.triplet().architecture(), dlls); - error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin); - break; - } + error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin); + break; + } case LinkageType::BackingEnum::STATIC: - { - std::vector<fs::path> dlls = fs.get_files_recursive(package_dir); - Util::unstable_keep_if(dlls, has_extension_pred(fs, ".dll")); - error_count += check_no_dlls_present(dlls); + { + std::vector<fs::path> dlls = fs.get_files_recursive(package_dir); + Util::unstable_keep_if(dlls, has_extension_pred(fs, ".dll")); + error_count += check_no_dlls_present(dlls); - error_count += check_bin_folders_are_not_present_in_static_build(fs, package_dir); + error_count += check_bin_folders_are_not_present_in_static_build(fs, package_dir); - if (!contains_and_enabled(build_info.policies, BuildPoliciesC::ONLY_RELEASE_CRT)) - { - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationTypeC::DEBUG, build_info.crt_linkage), debug_libs, toolset.dumpbin); - } - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationTypeC::RELEASE, build_info.crt_linkage), release_libs, toolset.dumpbin); - break; + if (!contains_and_enabled(build_info.policies, BuildPoliciesC::ONLY_RELEASE_CRT)) + { + error_count += check_crt_linkage_of_libs( + BuildType::value_of(ConfigurationTypeC::DEBUG, build_info.crt_linkage), + debug_libs, + toolset.dumpbin); } + error_count += + check_crt_linkage_of_libs(BuildType::value_of(ConfigurationTypeC::RELEASE, build_info.crt_linkage), + release_libs, + toolset.dumpbin); + break; + } case LinkageType::BackingEnum::NULLVALUE: - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } error_count += check_no_empty_folders(fs, package_dir); @@ -748,7 +835,10 @@ namespace vcpkg::PostBuildLint if (error_count != 0) { const fs::path portfile = paths.ports / spec.name() / "portfile.cmake"; - System::println(System::Color::error, "Found %u error(s). Please correct the portfile:\n %s", error_count, portfile.string()); + System::println(System::Color::error, + "Found %u error(s). Please correct the portfile:\n %s", + error_count, + portfile.string()); } System::println("-- Performing post-build validation done"); diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index afba05aae..65072b8ed 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -1,13 +1,13 @@ #include "pch.h" -#include "PostBuildLint_BuildInfo.h" -#include "vcpkg_Checks.h" + #include "OptBool.h" -#include "vcpkglib_helpers.h" #include "Paragraphs.h" +#include "PostBuildLint_BuildInfo.h" +#include "vcpkg_Checks.h" +#include "vcpkglib_helpers.h" namespace vcpkg::PostBuildLint { - // namespace BuildInfoRequiredField { static const std::string CRT_LINKAGE = "CRTLinkage"; @@ -17,19 +17,28 @@ namespace vcpkg::PostBuildLint BuildInfo BuildInfo::create(std::unordered_map<std::string, std::string> pgh) { BuildInfo build_info; - const std::string crt_linkage_as_string = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); + const std::string crt_linkage_as_string = + details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); build_info.crt_linkage = LinkageType::value_of(crt_linkage_as_string); - Checks::check_exit(VCPKG_LINE_INFO, build_info.crt_linkage != LinkageTypeC::NULLVALUE, "Invalid crt linkage type: [%s]", crt_linkage_as_string); + Checks::check_exit(VCPKG_LINE_INFO, + build_info.crt_linkage != LinkageTypeC::NULLVALUE, + "Invalid crt linkage type: [%s]", + crt_linkage_as_string); - const std::string library_linkage_as_string = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); + const std::string library_linkage_as_string = + details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); build_info.library_linkage = LinkageType::value_of(library_linkage_as_string); - Checks::check_exit(VCPKG_LINE_INFO, build_info.library_linkage != LinkageTypeC::NULLVALUE, "Invalid library linkage type: [%s]", library_linkage_as_string); + Checks::check_exit(VCPKG_LINE_INFO, + build_info.library_linkage != LinkageTypeC::NULLVALUE, + "Invalid library linkage type: [%s]", + library_linkage_as_string); // The remaining entries are policies for (const std::unordered_map<std::string, std::string>::value_type& p : pgh) { const BuildPolicies policy = BuildPolicies::parse(p.first); - Checks::check_exit(VCPKG_LINE_INFO, policy != BuildPoliciesC::NULLVALUE, "Unknown policy found: %s", p.first); + Checks::check_exit( + VCPKG_LINE_INFO, policy != BuildPoliciesC::NULLVALUE, "Unknown policy found: %s", p.first); const OptBool status = OptBool::parse(p.second); build_info.policies.emplace(policy, status); } @@ -39,7 +48,8 @@ namespace vcpkg::PostBuildLint BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath) { - const Expected<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_single_paragraph(fs, filepath); + const Expected<std::unordered_map<std::string, std::string>> pghs = + Paragraphs::get_single_paragraph(fs, filepath); Checks::check_exit(VCPKG_LINE_INFO, pghs.get() != nullptr, "Invalid BUILD_INFO file for package"); return BuildInfo::create(*pghs.get()); } diff --git a/toolsrc/src/PostBuildLint_BuildPolicies.cpp b/toolsrc/src/PostBuildLint_BuildPolicies.cpp index c09a06627..001ba31e7 100644 --- a/toolsrc/src/PostBuildLint_BuildPolicies.cpp +++ b/toolsrc/src/PostBuildLint_BuildPolicies.cpp @@ -1,7 +1,8 @@ #include "pch.h" + #include "PostBuildLint_BuildPolicies.h" -#include "vcpkg_Enums.h" #include "vcpkg_Checks.h" +#include "vcpkg_Enums.h" namespace vcpkg::PostBuildLint { @@ -41,18 +42,12 @@ namespace vcpkg::PostBuildLint { switch (this->backing_enum) { - case BuildPoliciesC::EMPTY_PACKAGE: - return NAME_EMPTY_PACKAGE; - case BuildPoliciesC::DLLS_WITHOUT_LIBS: - return NAME_DLLS_WITHOUT_LIBS; - case BuildPoliciesC::ONLY_RELEASE_CRT: - return NAME_ONLY_RELEASE_CRT; - case BuildPoliciesC::EMPTY_INCLUDE_FOLDER: - return NAME_EMPTY_INCLUDE_FOLDER; - case BuildPoliciesC::NULLVALUE: - return NULLVALUE_STRING; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case BuildPoliciesC::EMPTY_PACKAGE: return NAME_EMPTY_PACKAGE; + case BuildPoliciesC::DLLS_WITHOUT_LIBS: return NAME_DLLS_WITHOUT_LIBS; + case BuildPoliciesC::ONLY_RELEASE_CRT: return NAME_ONLY_RELEASE_CRT; + case BuildPoliciesC::EMPTY_INCLUDE_FOLDER: return NAME_EMPTY_INCLUDE_FOLDER; + case BuildPoliciesC::NULLVALUE: return NULLVALUE_STRING; + default: Checks::unreachable(VCPKG_LINE_INFO); } } @@ -65,18 +60,12 @@ namespace vcpkg::PostBuildLint switch (this->backing_enum) { - case BuildPoliciesC::EMPTY_PACKAGE: - return CMAKE_VARIABLE_EMPTY_PACKAGE; - case BuildPoliciesC::DLLS_WITHOUT_LIBS: - return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; - case BuildPoliciesC::ONLY_RELEASE_CRT: - return CMAKE_VARIABLE_ONLY_RELEASE_CRT; - case BuildPoliciesC::EMPTY_INCLUDE_FOLDER: - return CMAKE_VARIABLE_EMPTY_INCLUDE_FOLDER; - case BuildPoliciesC::NULLVALUE: - Enums::nullvalue_used(VCPKG_LINE_INFO, BuildPoliciesC::ENUM_NAME); - default: - Checks::unreachable(VCPKG_LINE_INFO); + case BuildPoliciesC::EMPTY_PACKAGE: return CMAKE_VARIABLE_EMPTY_PACKAGE; + case BuildPoliciesC::DLLS_WITHOUT_LIBS: return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; + case BuildPoliciesC::ONLY_RELEASE_CRT: return CMAKE_VARIABLE_ONLY_RELEASE_CRT; + case BuildPoliciesC::EMPTY_INCLUDE_FOLDER: return CMAKE_VARIABLE_EMPTY_INCLUDE_FOLDER; + case BuildPoliciesC::NULLVALUE: Enums::nullvalue_used(VCPKG_LINE_INFO, BuildPoliciesC::ENUM_NAME); + default: Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/PostBuildLint_BuildType.cpp b/toolsrc/src/PostBuildLint_BuildType.cpp index 651e95836..e690036d2 100644 --- a/toolsrc/src/PostBuildLint_BuildType.cpp +++ b/toolsrc/src/PostBuildLint_BuildType.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "PostBuildLint_BuildType.h" #include "vcpkg_Checks.h" @@ -29,15 +30,9 @@ namespace vcpkg::PostBuildLint Checks::unreachable(VCPKG_LINE_INFO); } - const ConfigurationType& BuildType::config() const - { - return this->m_config; - } + const ConfigurationType& BuildType::config() const { return this->m_config; } - const LinkageType& BuildType::linkage() const - { - return this->m_linkage; - } + const LinkageType& BuildType::linkage() const { return this->m_linkage; } const std::regex& BuildType::crt_regex() const { @@ -48,16 +43,11 @@ namespace vcpkg::PostBuildLint switch (backing_enum) { - case BuildTypeC::DEBUG_STATIC: - return REGEX_DEBUG_STATIC; - case BuildTypeC::DEBUG_DYNAMIC: - return REGEX_DEBUG_DYNAMIC; - case BuildTypeC::RELEASE_STATIC: - return REGEX_RELEASE_STATIC; - case BuildTypeC::RELEASE_DYNAMIC: - return REGEX_RELEASE_DYNAMIC; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case BuildTypeC::DEBUG_STATIC: return REGEX_DEBUG_STATIC; + case BuildTypeC::DEBUG_DYNAMIC: return REGEX_DEBUG_DYNAMIC; + case BuildTypeC::RELEASE_STATIC: return REGEX_RELEASE_STATIC; + case BuildTypeC::RELEASE_DYNAMIC: return REGEX_RELEASE_DYNAMIC; + default: Checks::unreachable(VCPKG_LINE_INFO); } } @@ -70,16 +60,11 @@ namespace vcpkg::PostBuildLint switch (backing_enum) { - case BuildTypeC::DEBUG_STATIC: - return NAME_DEBUG_STATIC; - case BuildTypeC::DEBUG_DYNAMIC: - return NAME_DEBUG_DYNAMIC; - case BuildTypeC::RELEASE_STATIC: - return NAME_RELEASE_STATIC; - case BuildTypeC::RELEASE_DYNAMIC: - return NAME_RELEASE_DYNAMIC; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case BuildTypeC::DEBUG_STATIC: return NAME_DEBUG_STATIC; + case BuildTypeC::DEBUG_DYNAMIC: return NAME_DEBUG_DYNAMIC; + case BuildTypeC::RELEASE_STATIC: return NAME_RELEASE_STATIC; + case BuildTypeC::RELEASE_DYNAMIC: return NAME_RELEASE_DYNAMIC; + default: Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/PostBuildLint_ConfigurationType.cpp b/toolsrc/src/PostBuildLint_ConfigurationType.cpp index 1acfb3cf9..eeccb1804 100644 --- a/toolsrc/src/PostBuildLint_ConfigurationType.cpp +++ b/toolsrc/src/PostBuildLint_ConfigurationType.cpp @@ -1,7 +1,8 @@ #include "pch.h" + +#include "PackageSpec.h" #include "PostBuildLint_ConfigurationType.h" #include "vcpkg_Enums.h" -#include "PackageSpec.h" namespace vcpkg::PostBuildLint { @@ -14,14 +15,10 @@ namespace vcpkg::PostBuildLint { switch (this->backing_enum) { - case ConfigurationTypeC::DEBUG: - return NAME_DEBUG; - case ConfigurationTypeC::RELEASE: - return NAME_RELEASE; - case ConfigurationTypeC::NULLVALUE: - return NULLVALUE_STRING; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case ConfigurationTypeC::DEBUG: return NAME_DEBUG; + case ConfigurationTypeC::RELEASE: return NAME_RELEASE; + case ConfigurationTypeC::NULLVALUE: return NULLVALUE_STRING; + default: Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/PostBuildLint_LinkageType.cpp b/toolsrc/src/PostBuildLint_LinkageType.cpp index b3f045750..43bdbed7b 100644 --- a/toolsrc/src/PostBuildLint_LinkageType.cpp +++ b/toolsrc/src/PostBuildLint_LinkageType.cpp @@ -1,7 +1,8 @@ #include "pch.h" + #include "PostBuildLint_LinkageType.h" -#include "vcpkg_Enums.h" #include "vcpkg_Checks.h" +#include "vcpkg_Enums.h" namespace vcpkg::PostBuildLint { @@ -29,14 +30,10 @@ namespace vcpkg::PostBuildLint { switch (this->backing_enum) { - case LinkageTypeC::DYNAMIC: - return NAME_DYNAMIC; - case LinkageTypeC::STATIC: - return NAME_STATIC; - case LinkageTypeC::NULLVALUE: - return NULLVALUE_STRING; - default: - Checks::unreachable(VCPKG_LINE_INFO); + case LinkageTypeC::DYNAMIC: return NAME_DYNAMIC; + case LinkageTypeC::STATIC: return NAME_STATIC; + case LinkageTypeC::NULLVALUE: return NULLVALUE_STRING; + default: Checks::unreachable(VCPKG_LINE_INFO); } } } diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 11b83aedf..ac88e54ac 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -1,10 +1,11 @@ #include "pch.h" + #include "SourceParagraph.h" -#include "vcpkglib_helpers.h" -#include "vcpkg_System.h" -#include "vcpkg_Maps.h" #include "Triplet.h" #include "vcpkg_Checks.h" +#include "vcpkg_Maps.h" +#include "vcpkg_System.h" +#include "vcpkglib_helpers.h" namespace vcpkg { @@ -24,15 +25,12 @@ namespace vcpkg static const std::vector<std::string>& get_list_of_valid_fields() { - static const std::vector<std::string> valid_fields = - { - SourceParagraphRequiredField::SOURCE, - SourceParagraphRequiredField::VERSION, + static const std::vector<std::string> valid_fields = { SourceParagraphRequiredField::SOURCE, + SourceParagraphRequiredField::VERSION, - SourceParagraphOptionalField::DESCRIPTION, - SourceParagraphOptionalField::MAINTAINER, - SourceParagraphOptionalField::BUILD_DEPENDS - }; + SourceParagraphOptionalField::DESCRIPTION, + SourceParagraphOptionalField::MAINTAINER, + SourceParagraphOptionalField::BUILD_DEPENDS }; return valid_fields; } @@ -57,7 +55,8 @@ namespace vcpkg const std::string remaining_fields_as_string = Strings::join("\n ", remaining_fields); const std::string valid_fields_as_string = Strings::join("\n ", valid_fields); - System::println(System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", this->name); + System::println( + System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", this->name); System::println("The following fields were not expected:\n\n %s\n\n", remaining_fields_as_string); System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_fields_as_string); Checks::exit_fail(VCPKG_LINE_INFO); @@ -68,15 +67,14 @@ namespace vcpkg { auto convert = [&](const std::string& depend_string) -> Dependency { auto pos = depend_string.find(' '); - if (pos == std::string::npos) - return{ depend_string, "" }; + if (pos == std::string::npos) return { depend_string, "" }; // expect of the form "\w+ \[\w+\]" Dependency dep; dep.name = depend_string.substr(0, pos); if (depend_string.c_str()[pos + 1] != '[' || depend_string[depend_string.size() - 1] != ']') { // Error, but for now just slurp the entire string. - return{ depend_string, "" }; + return { depend_string, "" }; } dep.qualifier = depend_string.substr(pos + 2, depend_string.size() - pos - 3); return dep; @@ -96,7 +94,7 @@ namespace vcpkg { if (depends_string.empty()) { - return{}; + return {}; } std::vector<std::string> out; @@ -138,8 +136,5 @@ namespace vcpkg return ret; } - const std::string& to_string(const Dependency& dep) - { - return dep.name; - } + const std::string& to_string(const Dependency& dep) { return dep.name; } } diff --git a/toolsrc/src/StatusParagraph.cpp b/toolsrc/src/StatusParagraph.cpp index 63bfb2f9b..b9ceed278 100644 --- a/toolsrc/src/StatusParagraph.cpp +++ b/toolsrc/src/StatusParagraph.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "StatusParagraph.h" #include "vcpkglib_helpers.h" @@ -6,24 +7,24 @@ using namespace vcpkg::details; namespace vcpkg { - // namespace BinaryParagraphRequiredField { static const std::string STATUS = "Status"; } - StatusParagraph::StatusParagraph() : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE) - { - } + StatusParagraph::StatusParagraph() : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE) {} void serialize(const StatusParagraph& pgh, std::string& out_str) { serialize(pgh.package, out_str); - out_str.append("Status: ").append(to_string(pgh.want)).append(" ok ").append(to_string(pgh.state)).push_back('\n'); + out_str.append("Status: ") + .append(to_string(pgh.want)) + .append(" ok ") + .append(to_string(pgh.state)) + .push_back('\n'); } - StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields) - : package(fields) + StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields) : package(fields) { std::string status_field = required_field(fields, BinaryParagraphRequiredField::STATUS); @@ -35,35 +36,24 @@ namespace vcpkg while (b != e && *b != ' ') ++b; - want = [](const std::string& text) - { - if (text == "unknown") - return Want::UNKNOWN; - if (text == "install") - return Want::INSTALL; - if (text == "hold") - return Want::HOLD; - if (text == "deinstall") - return Want::DEINSTALL; - if (text == "purge") - return Want::PURGE; - return Want::ERROR_STATE; - }(std::string(mark, b)); + want = [](const std::string& text) { + if (text == "unknown") return Want::UNKNOWN; + if (text == "install") return Want::INSTALL; + if (text == "hold") return Want::HOLD; + if (text == "deinstall") return Want::DEINSTALL; + if (text == "purge") return Want::PURGE; + return Want::ERROR_STATE; + }(std::string(mark, b)); - if (std::distance(b, e) < 4) - return; + if (std::distance(b, e) < 4) return; b += 4; - state = [](const std::string& text) - { - if (text == "not-installed") - return InstallState::NOT_INSTALLED; - if (text == "installed") - return InstallState::INSTALLED; - if (text == "half-installed") - return InstallState::HALF_INSTALLED; - return InstallState::ERROR_STATE; - }(std::string(b, e)); + state = [](const std::string& text) { + if (text == "not-installed") return InstallState::NOT_INSTALLED; + if (text == "installed") return InstallState::INSTALLED; + if (text == "half-installed") return InstallState::HALF_INSTALLED; + return InstallState::ERROR_STATE; + }(std::string(b, e)); } std::string to_string(InstallState f) diff --git a/toolsrc/src/StatusParagraphs.cpp b/toolsrc/src/StatusParagraphs.cpp index f41630132..27f3c30a2 100644 --- a/toolsrc/src/StatusParagraphs.cpp +++ b/toolsrc/src/StatusParagraphs.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "StatusParagraphs.h" #include "vcpkg_Checks.h" #include <algorithm> @@ -8,29 +9,26 @@ namespace vcpkg StatusParagraphs::StatusParagraphs() = default; StatusParagraphs::StatusParagraphs(std::vector<std::unique_ptr<StatusParagraph>>&& ps) - : paragraphs(std::move(ps)) - { - }; + : paragraphs(std::move(ps)){}; StatusParagraphs::const_iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet) const { - return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) - { - const PackageSpec& spec = pgh->package.spec; - return spec.name() == name && spec.triplet() == triplet; - }); + return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) { + const PackageSpec& spec = pgh->package.spec; + return spec.name() == name && spec.triplet() == triplet; + }); } StatusParagraphs::iterator StatusParagraphs::find(const std::string& name, const Triplet& triplet) { - return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) - { - const PackageSpec& spec = pgh->package.spec; - return spec.name() == name && spec.triplet() == triplet; - }); + return std::find_if(begin(), end(), [&](const std::unique_ptr<StatusParagraph>& pgh) { + const PackageSpec& spec = pgh->package.spec; + return spec.name() == name && spec.triplet() == triplet; + }); } - StatusParagraphs::const_iterator StatusParagraphs::find_installed(const std::string& name, const Triplet& triplet) const + StatusParagraphs::const_iterator StatusParagraphs::find_installed(const std::string& name, + const Triplet& triplet) const { const const_iterator it = find(name, triplet); if (it != end() && (*it)->want == Want::INSTALL && (*it)->state == InstallState::INSTALLED) diff --git a/toolsrc/src/VcpkgCmdArguments.cpp b/toolsrc/src/VcpkgCmdArguments.cpp index 5abe69e66..a41bb10c6 100644 --- a/toolsrc/src/VcpkgCmdArguments.cpp +++ b/toolsrc/src/VcpkgCmdArguments.cpp @@ -1,16 +1,16 @@ #include "pch.h" + #include "VcpkgCmdArguments.h" -#include "vcpkg_Commands.h" #include "metrics.h" +#include "vcpkg_Commands.h" #include "vcpkg_System.h" namespace vcpkg { - static void parse_value( - const std::string* arg_begin, - const std::string* arg_end, - const std::string& option_name, - std::unique_ptr<std::string>& option_field) + static void parse_value(const std::string* arg_begin, + const std::string* arg_end, + const std::string& option_name, + std::unique_ptr<std::string>& option_field) { if (arg_begin == arg_end) { @@ -31,10 +31,7 @@ namespace vcpkg option_field = std::make_unique<std::string>(*arg_begin); } - static void parse_switch( - OptBool new_setting, - const std::string& option_name, - OptBool& option_field) + static void parse_switch(OptBool new_setting, const std::string& option_name, OptBool& option_field) { if (option_field != OptBoolC::UNSPECIFIED && option_field != new_setting) { @@ -57,7 +54,8 @@ namespace vcpkg return VcpkgCmdArguments::create_from_arg_sequence(v.data(), v.data() + v.size()); } - VcpkgCmdArguments VcpkgCmdArguments::create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end) + VcpkgCmdArguments VcpkgCmdArguments::create_from_arg_sequence(const std::string* arg_begin, + const std::string* arg_end) { VcpkgCmdArguments args; @@ -137,7 +135,8 @@ namespace vcpkg return args; } - std::unordered_set<std::string> VcpkgCmdArguments::check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) const + std::unordered_set<std::string> + VcpkgCmdArguments::check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) const { std::unordered_set<std::string> output; auto options_copy = this->optional_command_arguments; @@ -184,7 +183,11 @@ namespace vcpkg const size_t actual_arg_count = command_arguments.size(); if (actual_arg_count > expected_arg_count) { - System::println(System::Color::error, "Error: `%s` requires at most %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count); + System::println(System::Color::error, + "Error: `%s` requires at most %u arguments, but %u were provided", + this->command, + expected_arg_count, + actual_arg_count); System::print(example_text); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -195,18 +198,27 @@ namespace vcpkg const size_t actual_arg_count = command_arguments.size(); if (actual_arg_count < expected_arg_count) { - System::println(System::Color::error, "Error: `%s` requires at least %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count); + System::println(System::Color::error, + "Error: `%s` requires at least %u arguments, but %u were provided", + this->command, + expected_arg_count, + actual_arg_count); System::print(example_text); Checks::exit_fail(VCPKG_LINE_INFO); } } - void VcpkgCmdArguments::check_exact_arg_count(const size_t expected_arg_count, const std::string& example_text) const + void VcpkgCmdArguments::check_exact_arg_count(const size_t expected_arg_count, + const std::string& example_text) const { const size_t actual_arg_count = command_arguments.size(); if (actual_arg_count != expected_arg_count) { - System::println(System::Color::error, "Error: `%s` requires %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count); + System::println(System::Color::error, + "Error: `%s` requires %u arguments, but %u were provided", + this->command, + expected_arg_count, + actual_arg_count); System::print(example_text); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp index 5a1217d0a..389fffe27 100644 --- a/toolsrc/src/VcpkgPaths.cpp +++ b/toolsrc/src/VcpkgPaths.cpp @@ -1,15 +1,17 @@ #include "pch.h" -#include "vcpkg_expected.h" + +#include "PackageSpec.h" #include "VcpkgPaths.h" #include "metrics.h" -#include "vcpkg_System.h" -#include "PackageSpec.h" #include "vcpkg_Files.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" +#include "vcpkg_expected.h" namespace vcpkg { - static bool exists_and_has_equal_or_greater_version(const std::wstring& version_cmd, const std::array<int, 3>& expected_version) + static bool exists_and_has_equal_or_greater_version(const std::wstring& version_cmd, + const std::array<int, 3>& expected_version) { static const std::regex re(R"###((\d+)\.(\d+)\.(\d+))###"); @@ -29,7 +31,8 @@ namespace vcpkg int d1 = atoi(match[1].str().c_str()); int d2 = atoi(match[2].str().c_str()); int d3 = atoi(match[3].str().c_str()); - if (d1 > expected_version[0] || (d1 == expected_version[0] && d2 > expected_version[1]) || (d1 == expected_version[0] && d2 == expected_version[1] && d3 >= expected_version[2])) + if (d1 > expected_version[0] || (d1 == expected_version[0] && d2 > expected_version[1]) || + (d1 == expected_version[0] && d2 == expected_version[1] && d3 >= expected_version[2])) { // satisfactory version found return true; @@ -38,13 +41,14 @@ namespace vcpkg return false; } - static Optional<fs::path> find_if_has_equal_or_greater_version(const std::vector<fs::path>& candidate_paths, const std::wstring& version_check_arguments, const std::array<int, 3>& expected_version) + static Optional<fs::path> find_if_has_equal_or_greater_version(const std::vector<fs::path>& candidate_paths, + const std::wstring& version_check_arguments, + const std::array<int, 3>& expected_version) { - auto it = Util::find_if(candidate_paths, [&](const fs::path& p) - { - const std::wstring cmd = Strings::wformat(LR"("%s" %s)", p.native(), version_check_arguments); - return exists_and_has_equal_or_greater_version(cmd, expected_version); - }); + auto it = Util::find_if(candidate_paths, [&](const fs::path& p) { + const std::wstring cmd = Strings::wformat(LR"("%s" %s)", p.native(), version_check_arguments); + return exists_and_has_equal_or_greater_version(cmd, expected_version); + }); if (it != candidate_paths.cend()) { @@ -66,7 +70,9 @@ namespace vcpkg return Util::fmap(Strings::split(out.output, "\n"), [](auto&& s) { return fs::path(s); }); } - static fs::path fetch_dependency(const fs::path scripts_folder, const std::wstring& tool_name, const fs::path& expected_downloaded_path) + static fs::path fetch_dependency(const fs::path scripts_folder, + const std::wstring& tool_name, + const fs::path& expected_downloaded_path) { const fs::path script = scripts_folder / "fetchDependency.ps1"; auto install_cmd = System::create_powershell_script_cmd(script, Strings::wformat(L"-Dependency %s", tool_name)); @@ -80,14 +86,17 @@ namespace vcpkg } const fs::path actual_downloaded_path = Strings::trimmed(rc.output); - Checks::check_exit(VCPKG_LINE_INFO, expected_downloaded_path == actual_downloaded_path, "Expected dependency downloaded path to be %s, but was %s", - expected_downloaded_path.generic_string(), actual_downloaded_path.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, + expected_downloaded_path == actual_downloaded_path, + "Expected dependency downloaded path to be %s, but was %s", + expected_downloaded_path.generic_string(), + actual_downloaded_path.generic_string()); return actual_downloaded_path; } static fs::path get_cmake_path(const fs::path& downloads_folder, const fs::path scripts_folder) { - static constexpr std::array<int, 3> expected_version = { 3,8,0 }; + static constexpr std::array<int, 3> expected_version = { 3, 8, 0 }; static const std::wstring version_check_arguments = L"--version"; const fs::path downloaded_copy = downloads_folder / "cmake-3.8.0-win32-x86" / "bin" / "cmake.exe"; @@ -99,7 +108,8 @@ namespace vcpkg candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "CMake" / "bin" / "cmake.exe"); candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "CMake" / "bin"); - const Optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); + const Optional<fs::path> path = + find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); if (auto p = path.get()) { return *p; @@ -110,7 +120,7 @@ namespace vcpkg fs::path get_nuget_path(const fs::path& downloads_folder, const fs::path scripts_folder) { - static constexpr std::array<int, 3> expected_version = { 3,3,0 }; + static constexpr std::array<int, 3> expected_version = { 3, 3, 0 }; static const std::wstring version_check_arguments = L""; const fs::path downloaded_copy = downloads_folder / "nuget-3.5.0" / "nuget.exe"; @@ -131,7 +141,7 @@ namespace vcpkg fs::path get_git_path(const fs::path& downloads_folder, const fs::path scripts_folder) { - static constexpr std::array<int, 3> expected_version = { 2,0,0 }; + static constexpr std::array<int, 3> expected_version = { 2, 0, 0 }; static const std::wstring version_check_arguments = L"--version"; const fs::path downloaded_copy = downloads_folder / "MinGit-2.11.1-32-bit" / "cmd" / "git.exe"; @@ -143,7 +153,8 @@ namespace vcpkg candidate_paths.push_back(System::get_ProgramFiles_platform_bitness() / "git" / "cmd" / "git.exe"); candidate_paths.push_back(System::get_ProgramFiles_32_bit() / "git" / "cmd" / "git.exe"); - const Optional<fs::path> path = find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); + const Optional<fs::path> path = + find_if_has_equal_or_greater_version(candidate_paths, version_check_arguments, expected_version); if (auto p = path.get()) { return *p; @@ -191,15 +202,9 @@ namespace vcpkg return paths; } - fs::path VcpkgPaths::package_dir(const PackageSpec& spec) const - { - return this->packages / spec.dir(); - } + fs::path VcpkgPaths::package_dir(const PackageSpec& spec) const { return this->packages / spec.dir(); } - fs::path VcpkgPaths::port_dir(const PackageSpec& spec) const - { - return this->ports / spec.name(); - } + fs::path VcpkgPaths::port_dir(const PackageSpec& spec) const { return this->ports / spec.name(); } fs::path VcpkgPaths::build_info_file_path(const PackageSpec& spec) const { @@ -218,7 +223,7 @@ namespace vcpkg std::string triplet_file_name = path.stem().generic_u8string(); if (t.canonical_name() == triplet_file_name) // TODO: fuzzy compare { - //t.value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare + // t.value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare return true; } } @@ -254,7 +259,8 @@ namespace vcpkg const Optional<std::wstring> vs2015_cmntools_optional = System::get_environmental_variable(L"VS140COMNTOOLS"); if (auto v = vs2015_cmntools_optional.get()) { - const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash + const fs::path vs2015_cmntools = fs::path(*v).parent_path(); // The call to parent_path() is needed because + // the env variable has a trailing backslash return vs2015_cmntools.parent_path().parent_path(); } @@ -277,21 +283,17 @@ namespace vcpkg // Skip any instances that do not have vcvarsall. const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat"; paths_examined.push_back(vcvarsall_bat); - if (!fs.exists(vcvarsall_bat)) - continue; + if (!fs.exists(vcvarsall_bat)) continue; // Locate the "best" MSVC toolchain version const fs::path msvc_path = vc_dir / "Tools" / "MSVC"; std::vector<fs::path> msvc_subdirectories = fs.get_files_non_recursive(msvc_path); - Util::unstable_keep_if(msvc_subdirectories, [&fs](const fs::path& path) { - return fs.is_directory(path); - }); + Util::unstable_keep_if(msvc_subdirectories, [&fs](const fs::path& path) { return fs.is_directory(path); }); // Sort them so that latest comes first - std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [](const fs::path& left, const fs::path& right) - { - return left.filename() > right.filename(); - }); + std::sort(msvc_subdirectories.begin(), + msvc_subdirectories.end(), + [](const fs::path& left, const fs::path& right) { return left.filename() > right.filename(); }); for (const fs::path& subdir : msvc_subdirectories) { @@ -299,7 +301,7 @@ namespace vcpkg paths_examined.push_back(dumpbin_path); if (fs.exists(dumpbin_path)) { - return { dumpbin_path, vcvarsall_bat , L"v141" }; + return { dumpbin_path, vcvarsall_bat, L"v141" }; } } } @@ -335,8 +337,5 @@ namespace vcpkg { return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); }); } - Files::Filesystem & VcpkgPaths::get_filesystem() const - { - return Files::get_real_filesystem(); - } + Files::Filesystem& VcpkgPaths::get_filesystem() const { return Files::get_real_filesystem(); } } diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index e2bab3090..d97a25b9c 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "coff_file_reader.h" #include "vcpkg_Checks.h" @@ -6,13 +7,13 @@ using namespace std; namespace vcpkg::COFFFileReader { - template <class T> + template<class T> static T reinterpret_bytes(const char* data) { - return (*reinterpret_cast<const T *>(&data[0])); + return (*reinterpret_cast<const T*>(&data[0])); } - template <class T> + template<class T> static T read_value_from_stream(fstream& fs) { T data; @@ -20,7 +21,7 @@ namespace vcpkg::COFFFileReader return data; } - template <class T> + template<class T> static T peek_value_from_stream(fstream& fs) { fpos_t original_pos = fs.tellg().seekpos(); @@ -30,9 +31,15 @@ namespace vcpkg::COFFFileReader return data; } - static void verify_equal_strings(const LineInfo& line_info, const char* expected, const char* actual, int size, const char* label) + static void verify_equal_strings( + const LineInfo& line_info, const char* expected, const char* actual, int size, const char* label) { - Checks::check_exit(line_info, memcmp(expected, actual, size) == 0, "Incorrect string (%s) found. Expected: (%s) but found (%s)", label, expected, actual); + Checks::check_exit(line_info, + memcmp(expected, actual, size) == 0, + "Incorrect string (%s) found. Expected: (%s) but found (%s)", + label, + expected, + actual); } static void read_and_verify_PE_signature(fstream& fs) @@ -104,7 +111,8 @@ namespace vcpkg::COFFFileReader if (ret.data[0] != '\0') // Due to freeglut. github issue #223 { const std::string header_end = ret.data.substr(HEADER_END_OFFSET, HEADER_END_SIZE); - verify_equal_strings(VCPKG_LINE_INFO, HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); + verify_equal_strings( + VCPKG_LINE_INFO, HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); } return ret; @@ -229,30 +237,18 @@ namespace vcpkg::COFFFileReader read_and_verify_PE_signature(fs); CoffFileHeader header = CoffFileHeader::read(fs); MachineType machine = header.machineType(); - return {machine}; + return { machine }; } struct Marker { - void set_to_offset(const fpos_t position) - { - this->m_absolute_position = position; - } + void set_to_offset(const fpos_t position) { this->m_absolute_position = position; } - void set_to_current_pos(fstream& fs) - { - this->m_absolute_position = fs.tellg().seekpos(); - } + void set_to_current_pos(fstream& fs) { this->m_absolute_position = fs.tellg().seekpos(); } - void seek_to_marker(fstream& fs) const - { - fs.seekg(this->m_absolute_position, ios_base::beg); - } + void seek_to_marker(fstream& fs) const { fs.seekg(this->m_absolute_position, ios_base::beg); } - void advance_by(const uint64_t offset) - { - this->m_absolute_position += offset; - } + void advance_by(const uint64_t offset) { this->m_absolute_position += offset; } private: fpos_t m_absolute_position = 0; @@ -270,12 +266,16 @@ namespace vcpkg::COFFFileReader // First Linker Member const ArchiveMemberHeader first_linker_member_header = ArchiveMemberHeader::read(fs); - Checks::check_exit(VCPKG_LINE_INFO, first_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper first linker member"); + Checks::check_exit(VCPKG_LINE_INFO, + first_linker_member_header.name().substr(0, 2) == "/ ", + "Could not find proper first linker member"); marker.advance_by(ArchiveMemberHeader::HEADER_SIZE + first_linker_member_header.member_size()); marker.seek_to_marker(fs); const ArchiveMemberHeader second_linker_member_header = ArchiveMemberHeader::read(fs); - Checks::check_exit(VCPKG_LINE_INFO, second_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper second linker member"); + Checks::check_exit(VCPKG_LINE_INFO, + second_linker_member_header.name().substr(0, 2) == "/ ", + "Could not find proper second linker member"); // The first 4 bytes contains the number of archive members const uint32_t archive_member_count = read_value_from_stream<uint32_t>(fs); const OffsetsArray offsets = OffsetsArray::read(fs, archive_member_count); @@ -298,10 +298,11 @@ namespace vcpkg::COFFFileReader marker.seek_to_marker(fs); const uint16_t first_two_bytes = peek_value_from_stream<uint16_t>(fs); const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; - const MachineType machine = isImportHeader ? ImportHeader::read(fs).machineType() : CoffFileHeader::read(fs).machineType(); + const MachineType machine = + isImportHeader ? ImportHeader::read(fs).machineType() : CoffFileHeader::read(fs).machineType(); machine_types.insert(machine); } - return {std::vector<MachineType>(machine_types.cbegin(), machine_types.cend())}; + return { std::vector<MachineType>(machine_types.cbegin(), machine_types.cend()) }; } } diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp index 4fdccff1d..efe4ff740 100644 --- a/toolsrc/src/commands_available_commands.cpp +++ b/toolsrc/src/commands_available_commands.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" namespace vcpkg::Commands @@ -6,12 +7,9 @@ namespace vcpkg::Commands const std::vector<PackageNameAndFunction<CommandTypeA>>& get_available_commands_type_a() { static std::vector<PackageNameAndFunction<CommandTypeA>> t = { - { "install", &Install::perform_and_exit }, - { "ci", &CI::perform_and_exit }, - { "remove", &Remove::perform_and_exit }, - { "build", &Build::perform_and_exit }, - { "env", &Env::perform_and_exit }, - { "build-external", &BuildExternal::perform_and_exit }, + { "install", &Install::perform_and_exit }, { "ci", &CI::perform_and_exit }, + { "remove", &Remove::perform_and_exit }, { "build", &Build::perform_and_exit }, + { "env", &Env::perform_and_exit }, { "build-external", &BuildExternal::perform_and_exit }, { "export", &Export::perform_and_exit }, }; return t; diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 569283d22..c30da45fe 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -1,16 +1,17 @@ #include "pch.h" -#include "vcpkg_Commands.h" -#include "StatusParagraphs.h" -#include "vcpkglib.h" -#include "vcpkg_Input.h" + +#include "Paragraphs.h" #include "PostBuildLint.h" -#include "vcpkg_Dependencies.h" -#include "vcpkg_System.h" -#include "vcpkg_Chrono.h" +#include "StatusParagraphs.h" #include "metrics.h" +#include "vcpkg_Chrono.h" +#include "vcpkg_Commands.h" +#include "vcpkg_Dependencies.h" #include "vcpkg_Enums.h" -#include "Paragraphs.h" +#include "vcpkg_Input.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Build { @@ -19,7 +20,9 @@ namespace vcpkg::Commands::Build static const std::string OPTION_CHECKS_ONLY = "--checks-only"; - static void create_binary_control_file(const VcpkgPaths& paths, const SourceParagraph& source_paragraph, const Triplet& triplet) + static void create_binary_control_file(const VcpkgPaths& paths, + const SourceParagraph& source_paragraph, + const Triplet& triplet) { const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, triplet); const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL"; @@ -28,23 +31,24 @@ namespace vcpkg::Commands::Build std::wstring make_build_env_cmd(const Triplet& triplet, const Toolset& toolset) { - const wchar_t * tonull = L" >nul"; + const wchar_t* tonull = L" >nul"; if (g_debugging) { tonull = L""; } - return Strings::wformat(LR"("%s" %s %s 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(triplet.architecture()), tonull); + return Strings::wformat( + LR"("%s" %s %s 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(triplet.architecture()), tonull); } - ExtendedBuildResult build_package( - const SourceParagraph& source_paragraph, - const PackageSpec& spec, - const VcpkgPaths& paths, - const fs::path& port_dir, - const StatusParagraphs& status_db) + ExtendedBuildResult build_package(const SourceParagraph& source_paragraph, + const PackageSpec& spec, + const VcpkgPaths& paths, + const fs::path& port_dir, + const StatusParagraphs& status_db) { - Checks::check_exit(VCPKG_LINE_INFO, spec.name() == source_paragraph.name, "inconsistent arguments to build_package()"); + Checks::check_exit( + VCPKG_LINE_INFO, spec.name() == source_paragraph.name, "inconsistent arguments to build_package()"); const Triplet& triplet = spec.triplet(); { @@ -53,7 +57,8 @@ namespace vcpkg::Commands::Build { if (status_db.find_installed(dep, triplet) == status_db.end()) { - missing_specs.push_back(PackageSpec::from_name_and_triplet(dep, triplet).value_or_exit(VCPKG_LINE_INFO)); + missing_specs.push_back( + PackageSpec::from_name_and_triplet(dep, triplet).value_or_exit(VCPKG_LINE_INFO)); } } // Fail the build if any dependencies were missing @@ -70,15 +75,14 @@ namespace vcpkg::Commands::Build const Toolset& toolset = paths.get_toolset(); const auto cmd_set_environment = make_build_env_cmd(triplet, toolset); - const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, ports_cmake_script_path, - { - { L"CMD", L"BUILD" }, - { L"PORT", source_paragraph.name }, - { L"CURRENT_PORT_DIR", port_dir / "/." }, - { L"TARGET_TRIPLET", triplet.canonical_name() }, - { L"VCPKG_PLATFORM_TOOLSET", toolset.version }, - { L"GIT", git_exe_path } - }); + const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, + ports_cmake_script_path, + { { L"CMD", L"BUILD" }, + { L"PORT", source_paragraph.name }, + { L"CURRENT_PORT_DIR", port_dir / "/." }, + { L"TARGET_TRIPLET", triplet.canonical_name() }, + { L"VCPKG_PLATFORM_TOOLSET", toolset.version }, + { L"GIT", git_exe_path } }); const std::wstring command = Strings::wformat(LR"(%s && %s)", cmd_set_environment, cmd_launch_cmake); @@ -141,11 +145,15 @@ namespace vcpkg::Commands::Build " Package: %s\n" " Vcpkg version: %s\n" "\n" - "Additionally, attach any relevant sections from the log files above." - , spec, Version::version()); + "Additionally, attach any relevant sections from the log files above.", + spec, + Version::version()); } - void perform_and_exit(const PackageSpec& spec, const fs::path& port_dir, const std::unordered_set<std::string>& options, const VcpkgPaths& paths) + void perform_and_exit(const PackageSpec& spec, + const fs::path& port_dir, + const std::unordered_set<std::string>& options, + const VcpkgPaths& paths) { if (options.find(OPTION_CHECKS_ONLY) != options.end()) { @@ -155,14 +163,19 @@ namespace vcpkg::Commands::Build } const Expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.get_filesystem(), port_dir); - Checks::check_exit(VCPKG_LINE_INFO, !maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); + Checks::check_exit(VCPKG_LINE_INFO, + !maybe_spgh.error_code(), + "Could not find package named %s: %s", + spec, + maybe_spgh.error_code().message()); const SourceParagraph& spgh = *maybe_spgh.get(); StatusParagraphs status_db = database_load_check(paths); const auto result = build_package(spgh, spec, paths, paths.port_dir(spec), status_db); if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES) { - System::println(System::Color::error, "The build command requires all dependencies to be already installed."); + System::println(System::Color::error, + "The build command requires all dependencies to be already installed."); System::println("The following dependencies are missing:"); System::println(""); for (const auto& p : result.unmet_dependencies) @@ -186,10 +199,13 @@ namespace vcpkg::Commands::Build void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet) { static const std::string example = Commands::Help::create_example_string("build zlib:x64-windows"); - args.check_exact_arg_count(1, example); // Build only takes a single package and all dependencies must already be installed - const PackageSpec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_triplet, example); + args.check_exact_arg_count( + 1, example); // Build only takes a single package and all dependencies must already be installed + const PackageSpec spec = + Input::check_and_get_package_spec(args.command_arguments.at(0), default_triplet, example); Input::check_triplet(spec.triplet(), paths); - const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_CHECKS_ONLY }); + const std::unordered_set<std::string> options = + args.check_and_get_optional_command_arguments({ OPTION_CHECKS_ONLY }); perform_and_exit(spec, paths.port_dir(spec), options, paths); } } diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index d0dbf1d24..97f5c8335 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -1,15 +1,18 @@ #include "pch.h" + #include "vcpkg_Commands.h" -#include "vcpkg_System.h" #include "vcpkg_Input.h" +#include "vcpkg_System.h" namespace vcpkg::Commands::BuildExternal { void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet) { - static const std::string example = Commands::Help::create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); + static const std::string example = + Commands::Help::create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); args.check_exact_arg_count(2, example); - const PackageSpec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_triplet, example); + const PackageSpec spec = + Input::check_and_get_package_spec(args.command_arguments.at(0), default_triplet, example); Input::check_triplet(spec.triplet(), paths); const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({}); diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index cb26c6ef9..75de78461 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,9 +1,10 @@ #include "pch.h" + +#include "BinaryParagraph.h" +#include "Paragraphs.h" #include "vcpkg_Commands.h" -#include "vcpkg_System.h" #include "vcpkg_Files.h" -#include "Paragraphs.h" -#include "BinaryParagraph.h" +#include "vcpkg_System.h" namespace vcpkg::Commands::Cache { @@ -12,7 +13,8 @@ namespace vcpkg::Commands::Cache std::vector<BinaryParagraph> output; for (auto&& path : paths.get_filesystem().get_files_non_recursive(paths.packages)) { - const Expected<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_single_paragraph(paths.get_filesystem(), path / "CONTROL"); + const Expected<std::unordered_map<std::string, std::string>> pghs = + Paragraphs::get_single_paragraph(paths.get_filesystem(), path / "CONTROL"); if (auto p = pghs.get()) { const BinaryParagraph binary_paragraph = BinaryParagraph(*p); @@ -26,7 +28,8 @@ namespace vcpkg::Commands::Cache void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { static const std::string example = Strings::format( - "The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", Commands::Help::create_example_string("cache png")); + "The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", + Commands::Help::create_example_string("cache png")); args.check_max_arg_count(1, example); args.check_and_get_optional_command_arguments({}); diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp index b7fc9e1c0..91d1ff01a 100644 --- a/toolsrc/src/commands_ci.cpp +++ b/toolsrc/src/commands_ci.cpp @@ -1,12 +1,13 @@ #include "pch.h" + +#include "Paragraphs.h" +#include "vcpkg_Chrono.h" #include "vcpkg_Commands.h" -#include "vcpkglib.h" -#include "vcpkg_Files.h" -#include "vcpkg_System.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Files.h" #include "vcpkg_Input.h" -#include "vcpkg_Chrono.h" -#include "Paragraphs.h" +#include "vcpkg_System.h" +#include "vcpkglib.h" namespace vcpkg::Commands::CI { @@ -14,7 +15,9 @@ namespace vcpkg::Commands::CI using Dependencies::InstallPlanType; using Build::BuildResult; - static std::vector<PackageSpec> load_all_package_specs(Files::Filesystem& fs, const fs::path& ports_directory, const Triplet& triplet) + static std::vector<PackageSpec> load_all_package_specs(Files::Filesystem& fs, + const fs::path& ports_directory, + const Triplet& triplet) { std::vector<SourceParagraph> ports = Paragraphs::load_all_ports(fs, ports_directory); std::vector<PackageSpec> specs; @@ -30,7 +33,9 @@ namespace vcpkg::Commands::CI { static const std::string example = Commands::Help::create_example_string("ci x64-windows"); args.check_max_arg_count(1, example); - const Triplet triplet = args.command_arguments.size() == 1 ? Triplet::from_canonical_name(args.command_arguments.at(0)) : default_triplet; + const Triplet triplet = args.command_arguments.size() == 1 + ? Triplet::from_canonical_name(args.command_arguments.at(0)) + : default_triplet; Input::check_triplet(triplet, paths); args.check_and_get_optional_command_arguments({}); const std::vector<PackageSpec> specs = load_all_package_specs(paths.get_filesystem(), paths.ports, triplet); @@ -63,39 +68,37 @@ namespace vcpkg::Commands::CI System::println(System::Color::success, "Package %s is already installed", display_name); break; case InstallPlanType::BUILD_AND_INSTALL: + { + System::println("Building package %s... ", display_name); + auto&& source_paragraph = action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO); + const auto result_ex = Commands::Build::build_package( + source_paragraph, action.spec, paths, paths.port_dir(action.spec), status_db); + const auto result = result_ex.code; + + timing.back() = build_timer.to_string(); + results.back() = result; + if (result != BuildResult::SUCCEEDED) { - System::println("Building package %s... ", display_name); - auto&& source_paragraph = action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO); - const auto result_ex = Commands::Build::build_package(source_paragraph, - action.spec, - paths, - paths.port_dir(action.spec), - status_db); - const auto result = result_ex.code; - - timing.back() = build_timer.to_string(); - results.back() = result; - if (result != BuildResult::SUCCEEDED) - { - System::println(System::Color::error, Build::create_error_message(result, action.spec)); - continue; - } - System::println(System::Color::success, "Building package %s... done", display_name); - - const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO); - System::println("Installing package %s... ", display_name); - Install::install_package(paths, bpgh, &status_db); - System::println(System::Color::success, "Installing package %s... done", display_name); - break; + System::println(System::Color::error, Build::create_error_message(result, action.spec)); + continue; } + System::println(System::Color::success, "Building package %s... done", display_name); + + const BinaryParagraph bpgh = + Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO); + System::println("Installing package %s... ", display_name); + Install::install_package(paths, bpgh, &status_db); + System::println(System::Color::success, "Installing package %s... done", display_name); + break; + } case InstallPlanType::INSTALL: results.back() = BuildResult::SUCCEEDED; System::println("Installing package %s... ", display_name); - Install::install_package(paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db); + Install::install_package( + paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db); System::println(System::Color::success, "Installing package %s... done", display_name); break; - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } catch (const std::exception& e) diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp index 76734130a..7f4161802 100644 --- a/toolsrc/src/commands_contact.cpp +++ b/toolsrc/src/commands_contact.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index 31278f441..26f5a4938 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -1,15 +1,17 @@ #include "pch.h" + #include "vcpkg_Commands.h" -#include "vcpkg_System.h" #include "vcpkg_Files.h" #include "vcpkg_Input.h" +#include "vcpkg_System.h" #include "vcpkglib.h" namespace vcpkg::Commands::Create { void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - static const std::string example = Commands::Help::create_example_string(R"###(create zlib2 http://zlib.net/zlib1211.zip "zlib1211-2.zip")###"); + static const std::string example = Commands::Help::create_example_string( + R"###(create zlib2 http://zlib.net/zlib1211.zip "zlib1211-2.zip")###"); args.check_max_arg_count(3, example); args.check_min_arg_count(2, example); args.check_and_get_optional_command_arguments({}); @@ -18,19 +20,16 @@ namespace vcpkg::Commands::Create const fs::path& cmake_exe = paths.get_cmake_exe(); - std::vector<CMakeVariable> cmake_args - { - { L"CMD", L"CREATE" }, - { L"PORT", port_name }, - { L"URL", url } - }; + std::vector<CMakeVariable> cmake_args{ { L"CMD", L"CREATE" }, { L"PORT", port_name }, { L"URL", url } }; if (args.command_arguments.size() >= 3) { const std::string& zip_file_name = args.command_arguments.at(2); - Checks::check_exit(VCPKG_LINE_INFO, !Files::has_invalid_chars_for_filesystem(zip_file_name), - R"(Filename cannot contain invalid chars %s, but was %s)", - Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name); + Checks::check_exit(VCPKG_LINE_INFO, + !Files::has_invalid_chars_for_filesystem(zip_file_name), + R"(Filename cannot contain invalid chars %s, but was %s)", + Files::FILESYSTEM_INVALID_CHARACTERS, + zip_file_name); cmake_args.push_back({ L"FILENAME", zip_file_name }); } diff --git a/toolsrc/src/commands_depends.cpp b/toolsrc/src/commands_depends.cpp index 0f0509614..ad33bbad4 100644 --- a/toolsrc/src/commands_depends.cpp +++ b/toolsrc/src/commands_depends.cpp @@ -1,8 +1,9 @@ #include "pch.h" -#include "vcpkg_Commands.h" -#include "vcpkg_System.h" + #include "Paragraphs.h" +#include "vcpkg_Commands.h" #include "vcpkg_Strings.h" +#include "vcpkg_System.h" namespace vcpkg::Commands::DependInfo { @@ -12,7 +13,8 @@ namespace vcpkg::Commands::DependInfo args.check_exact_arg_count(0, example); args.check_and_get_optional_command_arguments({}); - const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); + const std::vector<SourceParagraph> source_paragraphs = + Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); for (const SourceParagraph& source_paragraph : source_paragraphs) { diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 4679a2465..bd23489ff 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -1,7 +1,8 @@ #include "pch.h" + #include "vcpkg_Commands.h" -#include "vcpkg_System.h" #include "vcpkg_Input.h" +#include "vcpkg_System.h" namespace vcpkg::Commands::Edit { @@ -48,7 +49,8 @@ namespace vcpkg::Commands::Edit }; for (auto&& keypath : regkeys) { - const Optional<std::wstring> code_installpath = System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation"); + const Optional<std::wstring> code_installpath = + System::get_registry_string(HKEY_LOCAL_MACHINE, keypath, L"InstallLocation"); if (auto c = code_installpath.get()) { auto p = fs::path(*c) / "Code.exe"; @@ -69,10 +71,12 @@ namespace vcpkg::Commands::Edit if (env_EDITOR.empty()) { - Checks::exit_with_message(VCPKG_LINE_INFO, "Visual Studio Code was not found and the environment variable EDITOR is not set"); + Checks::exit_with_message( + VCPKG_LINE_INFO, "Visual Studio Code was not found and the environment variable EDITOR is not set"); } - std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native()); + std::wstring cmdLine = Strings::wformat( + LR"("%s" "%s" "%s" -n)", env_EDITOR, portpath.native(), (portpath / "portfile.cmake").native()); Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmdLine)); } } diff --git a/toolsrc/src/commands_env.cpp b/toolsrc/src/commands_env.cpp index dd4c3af06..33f1e6bc0 100644 --- a/toolsrc/src/commands_env.cpp +++ b/toolsrc/src/commands_env.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_export.cpp b/toolsrc/src/commands_export.cpp index 144a2277a..cc1a6c4a4 100644 --- a/toolsrc/src/commands_export.cpp +++ b/toolsrc/src/commands_export.cpp @@ -1,11 +1,12 @@ #include "pch.h" + +#include "Paragraphs.h" #include "vcpkg_Commands.h" -#include "vcpkglib.h" -#include "vcpkg_System.h" #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" -#include "Paragraphs.h" +#include "vcpkglib.h" #include <regex> namespace vcpkg::Commands::Export @@ -41,8 +42,10 @@ namespace vcpkg::Commands::Export std::string nuspec_file_content = std::regex_replace(content_template, std::regex("@NUGET_ID@"), nuget_id); nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@VERSION@"), nupkg_version); - nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@RAW_EXPORTED_DIR@"), raw_exported_dir); - nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@TARGETS_REDIRECT_PATH@"), targets_redirect_path); + nuspec_file_content = + std::regex_replace(nuspec_file_content, std::regex("@RAW_EXPORTED_DIR@"), raw_exported_dir); + nuspec_file_content = + std::regex_replace(nuspec_file_content, std::regex("@TARGETS_REDIRECT_PATH@"), targets_redirect_path); return nuspec_file_content; } @@ -52,12 +55,15 @@ namespace vcpkg::Commands::Export <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Condition="Exists('%s')" Project="%s" /> </Project> -)###", target_path, target_path); +)###", + target_path, + target_path); } static void print_plan(const std::map<ExportPlanType, std::vector<const ExportPlanAction*>>& group_by_plan_type) { - static constexpr std::array<ExportPlanType, 2> order = { ExportPlanType::ALREADY_BUILT, ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT }; + static constexpr std::array<ExportPlanType, 2> order = { ExportPlanType::ALREADY_BUILT, + ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT }; for (const ExportPlanType plan_type : order) { @@ -69,10 +75,9 @@ namespace vcpkg::Commands::Export std::vector<const ExportPlanAction*> cont = it->second; std::sort(cont.begin(), cont.end(), &ExportPlanAction::compare_by_name); - const std::string as_string = Strings::join("\n", cont, [](const ExportPlanAction* p) - { - return Dependencies::to_output_string(p->request_type, p->spec.to_string()); - }); + const std::string as_string = Strings::join("\n", cont, [](const ExportPlanAction* p) { + return Dependencies::to_output_string(p->request_type, p->spec.to_string()); + }); switch (plan_type) { @@ -82,8 +87,7 @@ namespace vcpkg::Commands::Export case ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT: System::println("The following packages need to be built:\n%s", as_string); continue; - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } } @@ -96,12 +100,17 @@ namespace vcpkg::Commands::Export // 15 characters + 1 null terminating character will be written for a total of 16 chars char mbstr[16]; const size_t bytes_written = std::strftime(mbstr, sizeof(mbstr), "%Y%m%d-%H%M%S", &date_time); - Checks::check_exit(VCPKG_LINE_INFO, bytes_written == 15, "Expected 15 bytes to be written, but %u were written", bytes_written); + Checks::check_exit(VCPKG_LINE_INFO, + bytes_written == 15, + "Expected 15 bytes to be written, but %u were written", + bytes_written); const std::string date_time_as_string(mbstr); return ("vcpkg-export-" + date_time_as_string); } - static fs::path do_nuget_export(const VcpkgPaths& paths, const fs::path& raw_exported_dir, const fs::path& output_dir) + static fs::path do_nuget_export(const VcpkgPaths& paths, + const fs::path& raw_exported_dir, + const fs::path& output_dir) { static const std::string NUPKG_VERSION = "1.0.0"; @@ -109,18 +118,23 @@ namespace vcpkg::Commands::Export const fs::path& nuget_exe = paths.get_nuget_exe(); // This file will be placed in "build\native" in the nuget package. Therefore, go up two dirs. - const std::string targets_redirect_content = create_targets_redirect("../../scripts/buildsystems/msbuild/vcpkg.targets"); + const std::string targets_redirect_content = + create_targets_redirect("../../scripts/buildsystems/msbuild/vcpkg.targets"); const fs::path targets_redirect = paths.buildsystems / "tmp" / "vcpkg.export.nuget.targets"; fs.write_contents(targets_redirect, targets_redirect_content); const std::string nuget_id = raw_exported_dir.filename().string(); - const std::string nuspec_file_content = create_nuspec_file_contents(raw_exported_dir.string(), targets_redirect.string(), nuget_id, NUPKG_VERSION); + const std::string nuspec_file_content = + create_nuspec_file_contents(raw_exported_dir.string(), targets_redirect.string(), nuget_id, NUPKG_VERSION); const fs::path nuspec_file_path = paths.buildsystems / "tmp" / "vcpkg.export.nuspec"; fs.write_contents(nuspec_file_path, nuspec_file_content); // -NoDefaultExcludes is needed for ".vcpkg-root" - const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", - nuget_exe.native(), output_dir.native(), nuspec_file_path.native()); + const std::wstring cmd_line = + Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", + nuget_exe.native(), + output_dir.native(), + nuspec_file_path.native()); const int exit_code = System::cmd_execute_clean(cmd_line); Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed"); @@ -140,9 +154,9 @@ namespace vcpkg::Commands::Export constexpr ArchiveFormat() = delete; constexpr ArchiveFormat(BackingEnum backing_enum, const wchar_t* extension, const wchar_t* cmake_option) - : backing_enum(backing_enum) - , m_extension(extension) - , m_cmake_option(cmake_option) { } + : backing_enum(backing_enum), m_extension(extension), m_cmake_option(cmake_option) + { + } constexpr operator BackingEnum() const { return backing_enum; } constexpr CWStringView extension() const { return this->m_extension; } @@ -160,12 +174,16 @@ namespace vcpkg::Commands::Export constexpr const ArchiveFormat _7ZIP(ArchiveFormat::BackingEnum::_7ZIP, L"7z", L"7zip"); } - static fs::path do_archive_export(const VcpkgPaths& paths, const fs::path& raw_exported_dir, const fs::path& output_dir, const ArchiveFormat& format) + static fs::path do_archive_export(const VcpkgPaths& paths, + const fs::path& raw_exported_dir, + const fs::path& output_dir, + const ArchiveFormat& format) { const fs::path& cmake_exe = paths.get_cmake_exe(); const std::wstring exported_dir_filename = raw_exported_dir.filename().native(); - const std::wstring exported_archive_filename = Strings::wformat(L"%s.%s", exported_dir_filename, format.extension()); + const std::wstring exported_archive_filename = + Strings::wformat(L"%s.%s", exported_dir_filename, format.extension()); const fs::path exported_archive_path = (output_dir / exported_archive_filename); // -NoDefaultExcludes is needed for ".vcpkg-root" @@ -176,7 +194,8 @@ namespace vcpkg::Commands::Export raw_exported_dir.native()); const int exit_code = System::cmd_execute_clean(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: %s creation failed", exported_archive_path.generic_string()); + Checks::check_exit( + VCPKG_LINE_INFO, exit_code == 0, "Error: %s creation failed", exported_archive_path.generic_string()); return exported_archive_path; } @@ -189,28 +208,27 @@ namespace vcpkg::Commands::Export static const std::string OPTION_7ZIP = "--7zip"; // input sanitization - static const std::string example = Commands::Help::create_example_string("export zlib zlib:x64-windows boost --nuget"); + static const std::string example = + Commands::Help::create_example_string("export zlib zlib:x64-windows boost --nuget"); args.check_min_arg_count(1, example); - const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg) - { - return Input::check_and_get_package_spec(arg, default_triplet, example); - }); + const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg) { + return Input::check_and_get_package_spec(arg, default_triplet, example); + }); for (auto&& spec : specs) Input::check_triplet(spec.triplet(), paths); const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments( - { - OPTION_DRY_RUN, OPTION_RAW, OPTION_NUGET, OPTION_ZIP, OPTION_7ZIP - }); + { OPTION_DRY_RUN, OPTION_RAW, OPTION_NUGET, OPTION_ZIP, OPTION_7ZIP }); const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend(); const bool raw = options.find(OPTION_RAW) != options.cend(); const bool nuget = options.find(OPTION_NUGET) != options.cend(); const bool zip = options.find(OPTION_ZIP) != options.cend(); const bool _7zip = options.find(OPTION_7ZIP) != options.cend(); - Checks::check_exit(VCPKG_LINE_INFO, raw || nuget || zip || _7zip, - "Must provide at least one of the following options: --raw --nuget --zip --7zip"); + Checks::check_exit(VCPKG_LINE_INFO, + raw || nuget || zip || _7zip, + "Must provide at least one of the following options: --raw --nuget --zip --7zip"); // create the plan StatusParagraphs status_db = database_load_check(paths); @@ -221,14 +239,15 @@ namespace vcpkg::Commands::Export Util::group_by(export_plan, &group_by_plan_type, [](const ExportPlanAction& p) { return p.plan_type; }); print_plan(group_by_plan_type); - const bool has_non_user_requested_packages = Util::find_if(export_plan, [](const ExportPlanAction& package)-> bool - { - return package.request_type != RequestType::USER_REQUESTED; - }) != export_plan.cend(); + const bool has_non_user_requested_packages = + Util::find_if(export_plan, [](const ExportPlanAction& package) -> bool { + return package.request_type != RequestType::USER_REQUESTED; + }) != export_plan.cend(); if (has_non_user_requested_packages) { - System::println(System::Color::warning, "Additional packages (*) need to be exported to complete this operation."); + System::println(System::Color::warning, + "Additional packages (*) need to be exported to complete this operation."); } auto it = group_by_plan_type.find(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT); @@ -238,14 +257,13 @@ namespace vcpkg::Commands::Export // No need to show all of them, just the user-requested ones. Dependency resolution will handle the rest. std::vector<const ExportPlanAction*> unbuilt = it->second; - Util::erase_remove_if(unbuilt, [](const ExportPlanAction* a) - { - return a->request_type != RequestType::USER_REQUESTED; - }); + Util::erase_remove_if( + unbuilt, [](const ExportPlanAction* a) { return a->request_type != RequestType::USER_REQUESTED; }); auto s = Strings::join(" ", unbuilt, [](const ExportPlanAction* a) { return a->spec.to_string(); }); System::println("To build them, run:\n" - " vcpkg install %s", s); + " vcpkg install %s", + s); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -274,7 +292,8 @@ namespace vcpkg::Commands::Export const std::string display_name = action.spec.to_string(); System::println("Exporting package %s... ", display_name); - const BinaryParagraph& binary_paragraph = action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO); + const BinaryParagraph& binary_paragraph = + action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO); const InstallDir dirs = InstallDir::from_destination_root( raw_exported_dir_path / "installed", action.spec.triplet().to_string(), @@ -285,8 +304,7 @@ namespace vcpkg::Commands::Export } // Copy files needed for integration - const std::vector<fs::path> integration_files_relative_to_root = - { + const std::vector<fs::path> integration_files_relative_to_root = { { ".vcpkg-root" }, { fs::path{ "scripts" } / "buildsystems" / "msbuild" / "applocal.ps1" }, { fs::path{ "scripts" } / "buildsystems" / "msbuild" / "vcpkg.targets" }, @@ -309,7 +327,8 @@ namespace vcpkg::Commands::Export if (raw) { - System::println(System::Color::success, R"(Files exported at: "%s")", raw_exported_dir_path.generic_string()); + System::println( + System::Color::success, R"(Files exported at: "%s")", raw_exported_dir_path.generic_string()); } if (nuget) @@ -323,7 +342,8 @@ namespace vcpkg::Commands::Export if (zip) { System::println("Creating zip archive... "); - const fs::path output_path = do_archive_export(paths, raw_exported_dir_path, export_to_path, ArchiveFormatC::ZIP); + const fs::path output_path = + do_archive_export(paths, raw_exported_dir_path, export_to_path, ArchiveFormatC::ZIP); System::println(System::Color::success, "Creating zip archive... done"); System::println(System::Color::success, "Zip archive exported at: %s", output_path.generic_string()); } @@ -331,7 +351,8 @@ namespace vcpkg::Commands::Export if (_7zip) { System::println("Creating 7zip archive... "); - const fs::path output_path = do_archive_export(paths, raw_exported_dir_path, export_to_path, ArchiveFormatC::_7ZIP); + const fs::path output_path = + do_archive_export(paths, raw_exported_dir_path, export_to_path, ArchiveFormatC::_7ZIP); System::println(System::Color::success, "Creating 7zip archive... done"); System::println(System::Color::success, "7zip archive exported at: %s", output_path.generic_string()); } diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index b6355dfbd..349c0e58f 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Util.h" @@ -7,18 +8,26 @@ namespace vcpkg::Commands::Hash { static void do_file_hash(fs::path const& path, std::wstring const& hashType) { - auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", - path.c_str(), hashType); + auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", path.c_str(), hashType); auto ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + ec_data.exit_code == 0, + "Running command:\n %s\n failed", + Strings::utf16_to_utf8(cmd_line)); std::string const& output = ec_data.output; auto start = output.find_first_of("\r\n"); - Checks::check_exit(VCPKG_LINE_INFO, start != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + start != std::string::npos, + "Unexpected output format from command: %s", + Strings::utf16_to_utf8(cmd_line)); auto end = output.find_first_of("\r\n", start + 1); - Checks::check_exit(VCPKG_LINE_INFO, end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + Checks::check_exit(VCPKG_LINE_INFO, + end != std::string::npos, + "Unexpected output format from command: %s", + Strings::utf16_to_utf8(cmd_line)); auto hash = output.substr(start, end - start); Util::erase_remove_if(hash, isspace); @@ -27,8 +36,9 @@ namespace vcpkg::Commands::Hash void perform_and_exit(const VcpkgCmdArguments& args) { - static const std::string example = Strings::format( - "The argument should be a file path\n%s", Commands::Help::create_example_string("hash boost_1_62_0.tar.bz2")); + static const std::string example = + Strings::format("The argument should be a file path\n%s", + Commands::Help::create_example_string("hash boost_1_62_0.tar.bz2")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); args.check_and_get_optional_command_arguments({}); diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index 0c6b0c766..8a424e9a3 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" #include "vcpkg_System.h" @@ -47,14 +48,15 @@ namespace vcpkg::Commands::Help " --vcpkg-root <path> Specify the vcpkg root directory\n" " (default: %%VCPKG_ROOT%%)\n" "\n" - "For more help (including examples) see the accompanying README.md." - , Integrate::INTEGRATE_COMMAND_HELPSTRING); + "For more help (including examples) see the accompanying README.md.", + Integrate::INTEGRATE_COMMAND_HELPSTRING); } std::string create_example_string(const std::string& command_and_arguments) { std::string cs = Strings::format("Example:\n" - " vcpkg %s", command_and_arguments); + " vcpkg %s", + command_and_arguments); return cs; } diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 95e23302d..5db1885b2 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -1,7 +1,8 @@ #include "pch.h" -#include "vcpkg_Commands.h" + #include "Paragraphs.h" #include "StatusParagraph.h" +#include "vcpkg_Commands.h" #include "vcpkg_Files.h" namespace vcpkg::Commands::Import @@ -12,7 +13,6 @@ namespace vcpkg::Commands::Import std::vector<fs::path> libs; }; - static void check_is_directory(const LineInfo& line_info, const Files::Filesystem& fs, const fs::path& dirpath) { Checks::check_exit(line_info, fs.is_directory(dirpath), "The path %s is not a directory", dirpath.string()); @@ -27,8 +27,7 @@ namespace vcpkg::Commands::Import Binaries binaries; for (auto&& file : files) { - if (fs.is_directory(file)) - continue; + if (fs.is_directory(file)) continue; auto ext = file.extension(); if (ext == ".dll") binaries.dlls.push_back(std::move(file)); @@ -38,7 +37,9 @@ namespace vcpkg::Commands::Import return binaries; } - static void copy_files_into_directory(Files::Filesystem& fs, const std::vector<fs::path>& files, const fs::path& destination_folder) + static void copy_files_into_directory(Files::Filesystem& fs, + const std::vector<fs::path>& files, + const fs::path& destination_folder) { std::error_code ec; fs.create_directory(destination_folder, ec); @@ -50,7 +51,10 @@ namespace vcpkg::Commands::Import } } - static void place_library_files_in(Files::Filesystem& fs, const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) + static void place_library_files_in(Files::Filesystem& fs, + const fs::path& include_directory, + const fs::path& project_directory, + const fs::path& destination_path) { check_is_directory(VCPKG_LINE_INFO, fs, include_directory); check_is_directory(VCPKG_LINE_INFO, fs, project_directory); @@ -59,7 +63,9 @@ namespace vcpkg::Commands::Import Binaries release_binaries = find_binaries_in_dir(fs, project_directory / "Release"); fs::path destination_include_directory = destination_path / "include"; - fs.copy(include_directory, destination_include_directory, fs::copy_options::recursive | fs::copy_options::overwrite_existing); + fs.copy(include_directory, + destination_include_directory, + fs::copy_options::recursive | fs::copy_options::overwrite_existing); copy_files_into_directory(fs, release_binaries.dlls, destination_path / "bin"); copy_files_into_directory(fs, release_binaries.libs, destination_path / "lib"); @@ -70,7 +76,10 @@ namespace vcpkg::Commands::Import copy_files_into_directory(fs, debug_binaries.libs, destination_path / "debug" / "lib"); } - static void do_import(const VcpkgPaths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) + static void do_import(const VcpkgPaths& paths, + const fs::path& include_directory, + const fs::path& project_directory, + const BinaryParagraph& control_file_data) { auto& fs = paths.get_filesystem(); fs::path library_destination_path = paths.package_dir(control_file_data.spec); @@ -84,7 +93,8 @@ namespace vcpkg::Commands::Import void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - static const std::string example = Commands::Help::create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); + static const std::string example = Commands::Help::create_example_string( + R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); args.check_exact_arg_count(3, example); args.check_and_get_optional_command_arguments({}); @@ -92,8 +102,12 @@ namespace vcpkg::Commands::Import const fs::path include_directory(args.command_arguments[1]); const fs::path project_directory(args.command_arguments[2]); - const Expected<std::unordered_map<std::string, std::string>> pghs = Paragraphs::get_single_paragraph(paths.get_filesystem(), control_file_path); - Checks::check_exit(VCPKG_LINE_INFO, pghs.get() != nullptr, "Invalid control file %s for package", control_file_path.generic_string()); + const Expected<std::unordered_map<std::string, std::string>> pghs = + Paragraphs::get_single_paragraph(paths.get_filesystem(), control_file_path); + Checks::check_exit(VCPKG_LINE_INFO, + pghs.get() != nullptr, + "Invalid control file %s for package", + control_file_path.generic_string()); StatusParagraph spgh; spgh.package = BinaryParagraph(*pghs.get()); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index d1d9cec5f..bc77d6a9f 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -1,13 +1,14 @@ #include "pch.h" -#include "vcpkg_Commands.h" -#include "vcpkglib.h" + +#include "Paragraphs.h" #include "metrics.h" -#include "vcpkg_Files.h" -#include "vcpkg_System.h" +#include "vcpkg_Commands.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Files.h" #include "vcpkg_Input.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" -#include "Paragraphs.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Install { @@ -26,22 +27,15 @@ namespace vcpkg::Commands::Install return dirs; } - const fs::path& InstallDir::destination() const - { - return this->m_destination; - } + const fs::path& InstallDir::destination() const { return this->m_destination; } - const std::string& InstallDir::destination_subdirectory() const - { - return this->m_destination_subdirectory; - } + const std::string& InstallDir::destination_subdirectory() const { return this->m_destination_subdirectory; } - const fs::path& InstallDir::listfile() const - { - return this->m_listfile; - } + const fs::path& InstallDir::listfile() const { return this->m_listfile; } - void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& destination_dir) + void install_files_and_write_listfile(Files::Filesystem& fs, + const fs::path& source_dir, + const InstallDir& destination_dir) { std::vector<std::string> output; std::error_code ec; @@ -51,12 +45,15 @@ namespace vcpkg::Commands::Install const std::string& destination_subdirectory = destination_dir.destination_subdirectory(); const fs::path& listfile = destination_dir.listfile(); - Checks::check_exit(VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string()); + Checks::check_exit( + VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string()); fs.create_directories(destination, ec); - Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string()); + Checks::check_exit( + VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string()); const fs::path listfile_parent = listfile.parent_path(); fs.create_directories(listfile_parent, ec); - Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string()); + Checks::check_exit( + VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string()); output.push_back(Strings::format(R"(%s/)", destination_subdirectory)); auto files = fs.get_files_recursive(source_dir); @@ -70,7 +67,8 @@ namespace vcpkg::Commands::Install } const std::string filename = file.filename().generic_string(); - if (fs::is_regular_file(status) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)) + if (fs::is_regular_file(status) && + (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)) { // Do not copy the control file continue; @@ -96,7 +94,10 @@ namespace vcpkg::Commands::Install { if (fs.exists(target)) { - System::println(System::Color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message()); + System::println(System::Color::warning, + "File %s was already present and will be overwritten", + target.u8string(), + ec.message()); } fs.copy_file(file, target, fs::copy_options::overwrite_existing, ec); if (ec) @@ -129,7 +130,8 @@ namespace vcpkg::Commands::Install } }; - static std::vector<std::string> extract_files_in_triplet(const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet) + static std::vector<std::string> extract_files_in_triplet( + const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet) { std::vector<std::string> output; for (const StatusParagraphAndAssociatedFiles& t : pgh_and_files) @@ -146,21 +148,22 @@ namespace vcpkg::Commands::Install return output; } - static SortedVector<std::string> build_list_of_package_files(const Files::Filesystem& fs, const fs::path& package_dir) + static SortedVector<std::string> build_list_of_package_files(const Files::Filesystem& fs, + const fs::path& package_dir) { const std::vector<fs::path> package_file_paths = fs.get_files_recursive(package_dir); const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash - auto package_files = Util::fmap(package_file_paths, [package_remove_char_count](const fs::path& path) - { - std::string as_string = path.generic_string(); - as_string.erase(0, package_remove_char_count); - return std::move(as_string); - }); + auto package_files = Util::fmap(package_file_paths, [package_remove_char_count](const fs::path& path) { + std::string as_string = path.generic_string(); + as_string.erase(0, package_remove_char_count); + return std::move(as_string); + }); return SortedVector<std::string>(std::move(package_files)); } - static SortedVector<std::string> build_list_of_installed_files(const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet) + static SortedVector<std::string> build_list_of_installed_files( + const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet) { std::vector<std::string> installed_files = extract_files_in_triplet(pgh_and_files, triplet); const size_t installed_remove_char_count = triplet.canonical_name().size() + 1; // +1 for the slash @@ -171,7 +174,9 @@ namespace vcpkg::Commands::Install static void print_plan(const std::map<InstallPlanType, std::vector<const InstallPlanAction*>>& group_by_plan_type) { - static constexpr std::array<InstallPlanType, 3> order = { InstallPlanType::ALREADY_INSTALLED, InstallPlanType::BUILD_AND_INSTALL, InstallPlanType::INSTALL }; + static constexpr std::array<InstallPlanType, 3> order = { InstallPlanType::ALREADY_INSTALLED, + InstallPlanType::BUILD_AND_INSTALL, + InstallPlanType::INSTALL }; for (const InstallPlanType plan_type : order) { @@ -183,10 +188,9 @@ namespace vcpkg::Commands::Install std::vector<const InstallPlanAction*> cont = it->second; std::sort(cont.begin(), cont.end(), &InstallPlanAction::compare_by_name); - const std::string as_string = Strings::join("\n", cont, [](const InstallPlanAction* p) - { - return Dependencies::to_output_string(p->request_type, p->spec.to_string()); - }); + const std::string as_string = Strings::join("\n", cont, [](const InstallPlanAction* p) { + return Dependencies::to_output_string(p->request_type, p->spec.to_string()); + }); switch (plan_type) { @@ -199,8 +203,7 @@ namespace vcpkg::Commands::Install case InstallPlanType::INSTALL: System::println("The following packages will be installed:\n%s", as_string); continue; - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } } @@ -211,18 +214,22 @@ namespace vcpkg::Commands::Install const Triplet& triplet = binary_paragraph.spec.triplet(); const std::vector<StatusParagraphAndAssociatedFiles> pgh_and_files = get_installed_files(paths, *status_db); - const SortedVector<std::string> package_files = build_list_of_package_files(paths.get_filesystem(), package_dir); + const SortedVector<std::string> package_files = + build_list_of_package_files(paths.get_filesystem(), package_dir); const SortedVector<std::string> installed_files = build_list_of_installed_files(pgh_and_files, triplet); std::vector<std::string> intersection; - std::set_intersection(package_files.begin(), package_files.end(), - installed_files.begin(), installed_files.end(), + std::set_intersection(package_files.begin(), + package_files.end(), + installed_files.begin(), + installed_files.end(), std::back_inserter(intersection)); if (!intersection.empty()) { const fs::path triplet_install_path = paths.installed / triplet.canonical_name(); - System::println(System::Color::error, "The following files are already installed in %s and are in conflict with %s", + System::println(System::Color::error, + "The following files are already installed in %s and are in conflict with %s", triplet_install_path.generic_string(), binary_paragraph.spec); System::print("\n "); @@ -245,9 +252,8 @@ namespace vcpkg::Commands::Install write_update(paths, source_paragraph); status_db->insert(std::make_unique<StatusParagraph>(source_paragraph)); - const InstallDir install_dir = InstallDir::from_destination_root(paths.installed, - triplet.to_string(), - paths.listfile_path(binary_paragraph)); + const InstallDir install_dir = InstallDir::from_destination_root( + paths.installed, triplet.to_string(), paths.listfile_path(binary_paragraph)); install_files_and_write_listfile(paths.get_filesystem(), package_dir, install_dir); @@ -261,17 +267,18 @@ namespace vcpkg::Commands::Install static const std::string OPTION_DRY_RUN = "--dry-run"; // input sanitization - static const std::string example = Commands::Help::create_example_string("install zlib zlib:x64-windows curl boost"); + static const std::string example = + Commands::Help::create_example_string("install zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); - const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg) - { - return Input::check_and_get_package_spec(arg, default_triplet, example); - }); + const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg) { + return Input::check_and_get_package_spec(arg, default_triplet, example); + }); for (auto&& spec : specs) Input::check_triplet(spec.triplet(), paths); - const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_DRY_RUN }); + const std::unordered_set<std::string> options = + args.check_and_get_optional_command_arguments({ OPTION_DRY_RUN }); const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend(); // create the plan @@ -280,21 +287,23 @@ namespace vcpkg::Commands::Install Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty"); // log the plan - const std::string specs_string = Strings::join(",", install_plan, [](const InstallPlanAction& plan) { return plan.spec.to_string(); }); + const std::string specs_string = + Strings::join(",", install_plan, [](const InstallPlanAction& plan) { return plan.spec.to_string(); }); Metrics::track_property("installplan", specs_string); std::map<InstallPlanType, std::vector<const InstallPlanAction*>> group_by_plan_type; Util::group_by(install_plan, &group_by_plan_type, [](const InstallPlanAction& p) { return p.plan_type; }); print_plan(group_by_plan_type); - const bool has_non_user_requested_packages = Util::find_if(install_plan, [](const InstallPlanAction& package)-> bool - { - return package.request_type != RequestType::USER_REQUESTED; - }) != install_plan.cend(); + const bool has_non_user_requested_packages = + Util::find_if(install_plan, [](const InstallPlanAction& package) -> bool { + return package.request_type != RequestType::USER_REQUESTED; + }) != install_plan.cend(); if (has_non_user_requested_packages) { - System::println(System::Color::warning, "Additional packages (*) need to be installed to complete this operation."); + System::println(System::Color::warning, + "Additional packages (*) need to be installed to complete this operation."); } if (dryRun) @@ -315,36 +324,38 @@ namespace vcpkg::Commands::Install System::println(System::Color::success, "Package %s is already installed", display_name); break; case InstallPlanType::BUILD_AND_INSTALL: + { + System::println("Building package %s... ", display_name); + const auto result = Commands::Build::build_package( + action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO), + action.spec, + paths, + paths.port_dir(action.spec), + status_db); + if (result.code != Build::BuildResult::SUCCEEDED) { - System::println("Building package %s... ", display_name); - const auto result = Commands::Build::build_package( - action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO), - action.spec, - paths, - paths.port_dir(action.spec), - status_db); - if (result.code != Build::BuildResult::SUCCEEDED) - { - System::println(System::Color::error, Build::create_error_message(result.code, action.spec)); - System::println(Build::create_user_troubleshooting_message(action.spec)); - Checks::exit_fail(VCPKG_LINE_INFO); - } - System::println(System::Color::success, "Building package %s... done", display_name); - - const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO); - System::println("Installing package %s... ", display_name); - install_package(paths, bpgh, &status_db); - System::println(System::Color::success, "Installing package %s... done", display_name); - break; + System::println(System::Color::error, + Build::create_error_message(result.code, action.spec)); + System::println(Build::create_user_troubleshooting_message(action.spec)); + Checks::exit_fail(VCPKG_LINE_INFO); } + System::println(System::Color::success, "Building package %s... done", display_name); + + const BinaryParagraph bpgh = + Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO); + System::println("Installing package %s... ", display_name); + install_package(paths, bpgh, &status_db); + System::println(System::Color::success, "Installing package %s... done", display_name); + break; + } case InstallPlanType::INSTALL: System::println("Installing package %s... ", display_name); - install_package(paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db); + install_package( + paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db); System::println(System::Color::success, "Installing package %s... done", display_name); break; case InstallPlanType::UNKNOWN: - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } catch (const std::exception& e) diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 9b036b928..7d5e55d22 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -1,8 +1,9 @@ #include "pch.h" -#include "vcpkg_Commands.h" + #include "vcpkg_Checks.h" -#include "vcpkg_System.h" +#include "vcpkg_Commands.h" #include "vcpkg_Files.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" namespace vcpkg::Commands::Integrate @@ -11,7 +12,8 @@ namespace vcpkg::Commands::Integrate System::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets", System::get_ProgramFiles_32_bit() / "MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets" }; - static const fs::path system_wide_targets_file = System::get_ProgramFiles_32_bit() / "MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props"; + static const fs::path system_wide_targets_file = + System::get_ProgramFiles_32_bit() / "MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props"; static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept { @@ -19,7 +21,9 @@ namespace vcpkg::Commands::Integrate <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Condition="Exists('%s') and '$(VCPkgLocalAppDataDisabled)' == ''" Project="%s" /> </Project> -)###", target_path, target_path); +)###", + target_path, + target_path); } static std::string create_system_targets_shortcut() noexcept @@ -46,7 +50,9 @@ namespace vcpkg::Commands::Integrate <Error Text="Unsupported architecture combination. Remove the 'vcpkg' nuget package." Condition="'$(VCPkgEnabled)' != 'true' and '$(VCPkgDisableError)' == ''"/> </Target> </Project> -)###", as_string, as_string); +)###", + as_string, + as_string); } static std::string create_nuget_props_file_contents() noexcept @@ -73,7 +79,9 @@ namespace vcpkg::Commands::Integrate return nuget_id; } - static std::string create_nuspec_file_contents(const fs::path& vcpkg_root_dir, const std::string& nuget_id, const std::string& nupkg_version) + static std::string create_nuspec_file_contents(const fs::path& vcpkg_root_dir, + const std::string& nuget_id, + const std::string& nupkg_version) { static constexpr auto content_template = R"( <package> @@ -133,7 +141,8 @@ namespace vcpkg::Commands::Integrate static fs::path get_appdata_targets_path() { - static const fs::path local_app_data = fs::path(System::get_environmental_variable(L"LOCALAPPDATA").value_or_exit(VCPKG_LINE_INFO)); + static const fs::path local_app_data = + fs::path(System::get_environmental_variable(L"LOCALAPPDATA").value_or_exit(VCPKG_LINE_INFO)); return local_app_data / "vcpkg" / "vcpkg.user.targets"; } @@ -146,17 +155,16 @@ namespace vcpkg::Commands::Integrate { if (fs.exists(old_system_wide_targets_file)) { - const std::string param = Strings::format(R"(/c DEL "%s" /Q > nul)", old_system_wide_targets_file.string()); + const std::string param = + Strings::format(R"(/c DEL "%s" /Q > nul)", old_system_wide_targets_file.string()); ElevationPromptChoice user_choice = elevated_cmd_execute(param); switch (user_choice) { - case ElevationPromptChoice::YES: - break; + case ElevationPromptChoice::YES: break; case ElevationPromptChoice::NO: System::println(System::Color::warning, "Warning: Previous integration file was not removed"); Checks::exit_fail(VCPKG_LINE_INFO); - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } } @@ -176,8 +184,7 @@ namespace vcpkg::Commands::Integrate if (found) { int ver = atoi(match[1].str().c_str()); - if (ver >= 1) - should_install_system = false; + if (ver >= 1) should_install_system = false; } } @@ -186,31 +193,39 @@ namespace vcpkg::Commands::Integrate const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets"; fs.write_contents(sys_src_path, create_system_targets_shortcut()); - const std::string param = Strings::format(R"(/c mkdir "%s" & copy "%s" "%s" /Y > nul)", system_wide_targets_file.parent_path().string(), sys_src_path.string(), system_wide_targets_file.string()); + const std::string param = Strings::format(R"(/c mkdir "%s" & copy "%s" "%s" /Y > nul)", + system_wide_targets_file.parent_path().string(), + sys_src_path.string(), + system_wide_targets_file.string()); ElevationPromptChoice user_choice = elevated_cmd_execute(param); switch (user_choice) { - case ElevationPromptChoice::YES: - break; + case ElevationPromptChoice::YES: break; case ElevationPromptChoice::NO: System::println(System::Color::warning, "Warning: integration was not applied"); Checks::exit_fail(VCPKG_LINE_INFO); - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } - Checks::check_exit(VCPKG_LINE_INFO, fs.exists(system_wide_targets_file), "Error: failed to copy targets file to %s", system_wide_targets_file.string()); + Checks::check_exit(VCPKG_LINE_INFO, + fs.exists(system_wide_targets_file), + "Error: failed to copy targets file to %s", + system_wide_targets_file.string()); } const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets"; - fs.write_contents(appdata_src_path, create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string())); + fs.write_contents(appdata_src_path, + create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string())); auto appdata_dst_path = get_appdata_targets_path(); auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec); if (!rc || ec) { - System::println(System::Color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string()); + System::println(System::Color::error, + "Error: Failed to copy file: %s -> %s", + appdata_src_path.string(), + appdata_dst_path.string()); Checks::exit_fail(VCPKG_LINE_INFO); } System::println(System::Color::success, "Applied user-wide integration for this vcpkg root."); @@ -220,7 +235,8 @@ namespace vcpkg::Commands::Integrate "Linking will be handled automatically.\n" "Installing new libraries will make them instantly available.\n" "\n" - "CMake projects should use -DCMAKE_TOOLCHAIN_FILE=%s", cmake_toolchain.generic_string()); + "CMake projects should use -DCMAKE_TOOLCHAIN_FILE=%s", + cmake_toolchain.generic_string()); Checks::exit_success(VCPKG_LINE_INFO); } @@ -269,12 +285,16 @@ namespace vcpkg::Commands::Integrate fs.write_contents(nuspec_file_path, create_nuspec_file_contents(paths.root, nuget_id, nupkg_version)); // Using all forward slashes for the command line - const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" > nul)", nuget_exe.native(), buildsystems_dir.native(), nuspec_file_path.native()); + const std::wstring cmd_line = Strings::wformat(LR"("%s" pack -OutputDirectory "%s" "%s" > nul)", + nuget_exe.native(), + buildsystems_dir.native(), + nuspec_file_path.native()); const int exit_code = System::cmd_execute_clean(cmd_line); const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version); - Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0 && fs.exists(nuget_package), "Error: NuGet package creation failed"); + Checks::check_exit( + VCPKG_LINE_INFO, exit_code == 0 && fs.exists(nuget_package), "Error: NuGet package creation failed"); System::println(System::Color::success, "Created nupkg: %s", nuget_package.string()); auto source_path = buildsystems_dir.u8string(); @@ -283,20 +303,24 @@ namespace vcpkg::Commands::Integrate System::println(R"( With a project open, go to Tools->NuGet Package Manager->Package Manager Console and paste: Install-Package %s -Source "%s" -)", nuget_id, source_path); +)", + nuget_id, + source_path); Checks::exit_success(VCPKG_LINE_INFO); } const char* const INTEGRATE_COMMAND_HELPSTRING = - " vcpkg integrate install Make installed packages available user-wide. Requires admin privileges on first use\n" - " vcpkg integrate remove Remove user-wide integration\n" - " vcpkg integrate project Generate a referencing nuget package for individual VS project use\n"; + " vcpkg integrate install Make installed packages available user-wide. Requires admin privileges on " + "first use\n" + " vcpkg integrate remove Remove user-wide integration\n" + " vcpkg integrate project Generate a referencing nuget package for individual VS project use\n"; void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { static const std::string example = Strings::format("Commands:\n" - "%s", INTEGRATE_COMMAND_HELPSTRING); + "%s", + INTEGRATE_COMMAND_HELPSTRING); args.check_exact_arg_count(1, example); args.check_and_get_optional_command_arguments({}); diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 199ee5c16..6451ac5eb 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -1,7 +1,8 @@ #include "pch.h" + #include "vcpkg_Commands.h" -#include "vcpkglib.h" #include "vcpkg_System.h" +#include "vcpkglib.h" #include "vcpkglib_helpers.h" namespace vcpkg::Commands::List @@ -17,7 +18,8 @@ namespace vcpkg::Commands::List void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { static const std::string example = Strings::format( - "The argument should be a substring to search for, or no argument to display all installed libraries.\n%s", Commands::Help::create_example_string("list png")); + "The argument should be a substring to search for, or no argument to display all installed libraries.\n%s", + Commands::Help::create_example_string("list png")); args.check_max_arg_count(1, example); args.check_and_get_optional_command_arguments({}); @@ -30,9 +32,9 @@ namespace vcpkg::Commands::List Checks::exit_success(VCPKG_LINE_INFO); } - std::sort(installed_packages.begin(), installed_packages.end(), - [ ]( const StatusParagraph* lhs, const StatusParagraph* rhs ) -> bool - { + std::sort(installed_packages.begin(), + installed_packages.end(), + [](const StatusParagraph* lhs, const StatusParagraph* rhs) -> bool { return lhs->package.displayname() < rhs->package.displayname(); }); diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index ff7467c1e..757292e96 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkglib.h" @@ -24,7 +25,8 @@ namespace vcpkg::Commands::Owns void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - static const std::string example = Strings::format("The argument should be a pattern to search for. %s", Commands::Help::create_example_string("owns zlib.dll")); + static const std::string example = Strings::format("The argument should be a pattern to search for. %s", + Commands::Help::create_example_string("owns zlib.dll")); args.check_exact_arg_count(1, example); args.check_and_get_optional_command_arguments({}); diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index e262a8338..7cead8961 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -1,10 +1,11 @@ #include "pch.h" -#include "vcpkg_Commands.h" -#include "vcpkg_System.h" -#include "vcpkg_Maps.h" -#include "SourceParagraph.h" + #include "Paragraphs.h" #include "SortedVector.h" +#include "SourceParagraph.h" +#include "vcpkg_Commands.h" +#include "vcpkg_Maps.h" +#include "vcpkg_System.h" namespace vcpkg::Commands::PortsDiff { @@ -19,16 +20,19 @@ namespace vcpkg::Commands::PortsDiff VersionDiff version_diff; }; - template <class T> + template<class T> struct SetElementPresence { static SetElementPresence create(std::vector<T> left, std::vector<T> right) { // TODO: This can be done with one pass instead of three passes SetElementPresence output; - std::set_difference(left.cbegin(), left.cend(), right.cbegin(), right.cend(), std::back_inserter(output.only_left)); - std::set_intersection(left.cbegin(), left.cend(), right.cbegin(), right.cend(), std::back_inserter(output.both)); - std::set_difference(right.cbegin(), right.cend(), left.cbegin(), left.cend(), std::back_inserter(output.only_right)); + std::set_difference( + left.cbegin(), left.cend(), right.cbegin(), right.cend(), std::back_inserter(output.only_left)); + std::set_intersection( + left.cbegin(), left.cend(), right.cbegin(), right.cend(), std::back_inserter(output.both)); + std::set_difference( + right.cbegin(), right.cend(), left.cbegin(), left.cend(), std::back_inserter(output.only_right)); return output; } @@ -38,9 +42,10 @@ namespace vcpkg::Commands::PortsDiff std::vector<T> only_right; }; - static std::vector<UpdatedPort> find_updated_ports(const std::vector<std::string>& ports, - const std::map<std::string, VersionT>& previous_names_and_versions, - const std::map<std::string, VersionT>& current_names_and_versions) + static std::vector<UpdatedPort> + find_updated_ports(const std::vector<std::string>& ports, + const std::map<std::string, VersionT>& previous_names_and_versions, + const std::map<std::string, VersionT>& current_names_and_versions) { std::vector<UpdatedPort> output; for (const std::string& name : ports) @@ -58,7 +63,8 @@ namespace vcpkg::Commands::PortsDiff return output; } - static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, VersionT>& names_and_versions) + static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, + const std::map<std::string, VersionT>& names_and_versions) { for (const std::string& name : ports_to_print) { @@ -67,28 +73,34 @@ namespace vcpkg::Commands::PortsDiff } } - static std::map<std::string, VersionT> read_ports_from_commit(const VcpkgPaths& paths, const std::wstring& git_commit_id) + static std::map<std::string, VersionT> read_ports_from_commit(const VcpkgPaths& paths, + const std::wstring& git_commit_id) { std::error_code ec; auto& fs = paths.get_filesystem(); const fs::path& git_exe = paths.get_git_exe(); const fs::path dot_git_dir = paths.root / ".git"; const std::wstring ports_dir_name_as_string = paths.ports.filename().native(); - const fs::path temp_checkout_path = paths.root / Strings::wformat(L"%s-%s", ports_dir_name_as_string, git_commit_id); + const fs::path temp_checkout_path = + paths.root / Strings::wformat(L"%s-%s", ports_dir_name_as_string, git_commit_id); fs.create_directory(temp_checkout_path, ec); - const std::wstring checkout_this_dir = Strings::wformat(LR"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository - - const std::wstring cmd = Strings::wformat(LR"("%s" --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & "%s" reset >NUL)", - git_exe.native(), - dot_git_dir.native(), - temp_checkout_path.native(), - git_commit_id, - checkout_this_dir, - L".vcpkg-root", - git_exe.native()); + const std::wstring checkout_this_dir = + Strings::wformat(LR"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository + + const std::wstring cmd = + Strings::wformat(LR"("%s" --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & "%s" reset >NUL)", + git_exe.native(), + dot_git_dir.native(), + temp_checkout_path.native(), + git_commit_id, + checkout_this_dir, + L".vcpkg-root", + git_exe.native()); System::cmd_execute_clean(cmd); - const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), temp_checkout_path / ports_dir_name_as_string); - const std::map<std::string, VersionT> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); + const std::vector<SourceParagraph> source_paragraphs = + Paragraphs::load_all_ports(paths.get_filesystem(), temp_checkout_path / ports_dir_name_as_string); + const std::map<std::string, VersionT> names_and_versions = + Paragraphs::extract_port_names_and_versions(source_paragraphs); fs.remove_all(temp_checkout_path, ec); return names_and_versions; } @@ -99,12 +111,17 @@ namespace vcpkg::Commands::PortsDiff const std::wstring cmd = Strings::wformat(LR"("%s" cat-file -t %s)", git_exe.native(), git_commit_id); const System::ExitCodeAndOutput output = System::cmd_execute_and_capture_output(cmd); - Checks::check_exit(VCPKG_LINE_INFO, output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); + Checks::check_exit(VCPKG_LINE_INFO, + output.output == VALID_COMMIT_OUTPUT, + "Invalid commit id %s", + Strings::utf16_to_utf8(git_commit_id)); } void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Help::create_example_string("portsdiff mybranchname")); + static const std::string example = + Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", + Commands::Help::create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); args.check_and_get_optional_command_arguments({}); @@ -112,19 +129,23 @@ namespace vcpkg::Commands::PortsDiff const fs::path& git_exe = paths.get_git_exe(); const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0)); - const std::wstring git_commit_id_for_current_snapshot = args.command_arguments.size() < 2 ? L"HEAD" : Strings::utf8_to_utf16(args.command_arguments.at(1)); + const std::wstring git_commit_id_for_current_snapshot = + args.command_arguments.size() < 2 ? L"HEAD" : Strings::utf8_to_utf16(args.command_arguments.at(1)); check_commit_exists(git_exe, git_commit_id_for_current_snapshot); check_commit_exists(git_exe, git_commit_id_for_previous_snapshot); - const std::map<std::string, VersionT> current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot); - const std::map<std::string, VersionT> previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot); + const std::map<std::string, VersionT> current_names_and_versions = + read_ports_from_commit(paths, git_commit_id_for_current_snapshot); + const std::map<std::string, VersionT> previous_names_and_versions = + read_ports_from_commit(paths, git_commit_id_for_previous_snapshot); // Already sorted, so set_difference can work on std::vector too std::vector<std::string> current_ports = Maps::extract_keys(current_names_and_versions); std::vector<std::string> previous_ports = Maps::extract_keys(previous_names_and_versions); - const SetElementPresence<std::string> setp = SetElementPresence<std::string>::create(current_ports, previous_ports); + const SetElementPresence<std::string> setp = + SetElementPresence<std::string>::create(current_ports, previous_ports); const std::vector<std::string>& added_ports = setp.only_left; if (!added_ports.empty()) @@ -141,7 +162,8 @@ namespace vcpkg::Commands::PortsDiff } const std::vector<std::string>& common_ports = setp.both; - const std::vector<UpdatedPort> updated_ports = find_updated_ports(common_ports, previous_names_and_versions, current_names_and_versions); + const std::vector<UpdatedPort> updated_ports = + find_updated_ports(common_ports, previous_names_and_versions, current_names_and_versions); if (!updated_ports.empty()) { diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 225241bdf..b2d9f602a 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -1,10 +1,11 @@ #include "pch.h" + #include "vcpkg_Commands.h" -#include "vcpkglib.h" -#include "vcpkg_System.h" -#include "vcpkg_Input.h" #include "vcpkg_Dependencies.h" +#include "vcpkg_Input.h" +#include "vcpkg_System.h" #include "vcpkg_Util.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Remove { @@ -29,8 +30,7 @@ namespace vcpkg::Commands::Remove std::vector<fs::path> dirs_touched; for (auto&& suffix : *lines) { - if (!suffix.empty() && suffix.back() == '\r') - suffix.pop_back(); + if (!suffix.empty() && suffix.back() == '\r') suffix.pop_back(); std::error_code ec; @@ -89,7 +89,8 @@ namespace vcpkg::Commands::Remove static void print_plan(const std::map<RemovePlanType, std::vector<const RemovePlanAction*>>& group_by_plan_type) { - static constexpr std::array<RemovePlanType, 2> order = { RemovePlanType::NOT_INSTALLED, RemovePlanType::REMOVE }; + static constexpr std::array<RemovePlanType, 2> order = { RemovePlanType::NOT_INSTALLED, + RemovePlanType::REMOVE }; for (const RemovePlanType plan_type : order) { @@ -101,10 +102,9 @@ namespace vcpkg::Commands::Remove std::vector<const RemovePlanAction*> cont = it->second; std::sort(cont.begin(), cont.end(), &RemovePlanAction::compare_by_name); - const std::string as_string = Strings::join("\n", cont, [](const RemovePlanAction* p) - { - return Dependencies::to_output_string(p->request_type, p->spec.to_string()); - }); + const std::string as_string = Strings::join("\n", cont, [](const RemovePlanAction* p) { + return Dependencies::to_output_string(p->request_type, p->spec.to_string()); + }); switch (plan_type) { @@ -114,8 +114,7 @@ namespace vcpkg::Commands::Remove case RemovePlanType::REMOVE: System::println("The following packages will be removed:\n%s", as_string); continue; - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } } } @@ -127,20 +126,25 @@ namespace vcpkg::Commands::Remove static const std::string OPTION_RECURSE = "--recurse"; static const std::string OPTION_DRY_RUN = "--dry-run"; static const std::string OPTION_OUTDATED = "--outdated"; - static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); - const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_PURGE, OPTION_NO_PURGE, OPTION_RECURSE, OPTION_DRY_RUN, OPTION_OUTDATED }); + static const std::string example = + Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); + const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments( + { OPTION_PURGE, OPTION_NO_PURGE, OPTION_RECURSE, OPTION_DRY_RUN, OPTION_OUTDATED }); StatusParagraphs status_db = database_load_check(paths); std::vector<PackageSpec> specs; if (options.find(OPTION_OUTDATED) != options.cend()) { args.check_exact_arg_count(0, example); - specs = Util::fmap(Update::find_outdated_packages(paths, status_db), [](auto&& outdated) { return outdated.spec; }); + specs = Util::fmap(Update::find_outdated_packages(paths, status_db), + [](auto&& outdated) { return outdated.spec; }); } else { args.check_min_arg_count(1, example); - specs = Util::fmap(args.command_arguments, [&](auto&& arg) { return Input::check_and_get_package_spec(arg, default_triplet, example); }); + specs = Util::fmap(args.command_arguments, [&](auto&& arg) { + return Input::check_and_get_package_spec(arg, default_triplet, example); + }); for (auto&& spec : specs) Input::check_triplet(spec.triplet(), paths); } @@ -163,18 +167,20 @@ namespace vcpkg::Commands::Remove Util::group_by(remove_plan, &group_by_plan_type, [](const RemovePlanAction& p) { return p.plan_type; }); print_plan(group_by_plan_type); - const bool has_non_user_requested_packages = Util::find_if(remove_plan, [](const RemovePlanAction& package)-> bool - { - return package.request_type != RequestType::USER_REQUESTED; - }) != remove_plan.cend(); + const bool has_non_user_requested_packages = + Util::find_if(remove_plan, [](const RemovePlanAction& package) -> bool { + return package.request_type != RequestType::USER_REQUESTED; + }) != remove_plan.cend(); if (has_non_user_requested_packages) { - System::println(System::Color::warning, "Additional packages (*) need to be removed to complete this operation."); + System::println(System::Color::warning, + "Additional packages (*) need to be removed to complete this operation."); if (!isRecursive) { - System::println(System::Color::warning, "If you are sure you want to remove them, run the command with the --recurse option"); + System::println(System::Color::warning, + "If you are sure you want to remove them, run the command with the --recurse option"); Checks::exit_fail(VCPKG_LINE_INFO); } } @@ -199,8 +205,7 @@ namespace vcpkg::Commands::Remove System::println(System::Color::success, "Removing package %s... done", display_name); break; case RemovePlanType::UNKNOWN: - default: - Checks::unreachable(VCPKG_LINE_INFO); + default: Checks::unreachable(VCPKG_LINE_INFO); } if (alsoRemoveFolderFromPackages) diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 691a66289..44b4779a6 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,13 +1,14 @@ #include "pch.h" + +#include "Paragraphs.h" +#include "SourceParagraph.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "Paragraphs.h" #include "vcpkglib_helpers.h" -#include "SourceParagraph.h" namespace vcpkg::Commands::Search { - static const std::string OPTION_GRAPH = "--graph"; //TODO: This should find a better home, eventually + static const std::string OPTION_GRAPH = "--graph"; // TODO: This should find a better home, eventually static std::string replace_dashes_with_underscore(const std::string& input) { @@ -54,12 +55,14 @@ namespace vcpkg::Commands::Search void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { - static const std::string example = Strings::format("The argument should be a substring to search for, or no argument to display all libraries.\n%s", - Commands::Help::create_example_string("search png")); + static const std::string example = Strings::format( + "The argument should be a substring to search for, or no argument to display all libraries.\n%s", + Commands::Help::create_example_string("search png")); args.check_max_arg_count(1, example); const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_GRAPH }); - const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); + const std::vector<SourceParagraph> source_paragraphs = + Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); if (options.find(OPTION_GRAPH) != options.cend()) { const std::string graph_as_string = create_graph_as_string(source_paragraphs); @@ -79,7 +82,8 @@ namespace vcpkg::Commands::Search // At this point there is 1 argument for (const SourceParagraph& source_paragraph : source_paragraphs) { - if (Strings::case_insensitive_ascii_find(source_paragraph.name, args.command_arguments[0]) == source_paragraph.name.end()) + if (Strings::case_insensitive_ascii_find(source_paragraph.name, args.command_arguments[0]) == + source_paragraph.name.end()) { continue; } @@ -88,7 +92,8 @@ namespace vcpkg::Commands::Search } } - System::println("\nIf your library is not listed, please open an issue at and/or consider making a pull request:\n" + System::println( + "\nIf your library is not listed, please open an issue at and/or consider making a pull request:\n" " https://github.com/Microsoft/vcpkg/issues"); Checks::exit_success(VCPKG_LINE_INFO); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 36a2858b1..5cc000649 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -1,9 +1,10 @@ #include "pch.h" + +#include "Paragraphs.h" #include "vcpkg_Commands.h" -#include "vcpkglib.h" -#include "vcpkg_System.h" #include "vcpkg_Files.h" -#include "Paragraphs.h" +#include "vcpkg_System.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Update { @@ -14,8 +15,10 @@ namespace vcpkg::Commands::Update std::vector<OutdatedPackage> find_outdated_packages(const VcpkgPaths& paths, const StatusParagraphs& status_db) { - const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); - const std::map<std::string, VersionT> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); + const std::vector<SourceParagraph> source_paragraphs = + Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); + const std::map<std::string, VersionT> src_names_to_versions = + Paragraphs::extract_port_names_and_versions(source_paragraphs); const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db); std::vector<OutdatedPackage> output; @@ -44,8 +47,8 @@ namespace vcpkg::Commands::Update const StatusParagraphs status_db = database_load_check(paths); - const auto outdated_packages = SortedVector<OutdatedPackage>(find_outdated_packages(paths, status_db), - &OutdatedPackage::compare_by_name); + const auto outdated_packages = + SortedVector<OutdatedPackage>(find_outdated_packages(paths, status_db), &OutdatedPackage::compare_by_name); if (outdated_packages.empty()) { @@ -59,9 +62,9 @@ namespace vcpkg::Commands::Update System::println(" %-32s %s", package.spec, package.version_diff.to_string()); } System::println("\n" - "To update these packages, run\n" - " vcpkg remove --outdated\n" - " vcpkg install <pkgs>..."); + "To update these packages, run\n" + " vcpkg remove --outdated\n" + " vcpkg install <pkgs>..."); } auto version_file = paths.get_filesystem().read_contents(paths.root / "toolsrc" / "VERSION.txt"); @@ -77,9 +80,14 @@ namespace vcpkg::Commands::Update { if (maj1 != maj2 || min1 != min2 || rev1 != rev2) { - System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use .\\bootstrap-vcpkg.bat to update.", - maj2, min2, rev2, - maj1, min1, rev1); + System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use " + ".\\bootstrap-vcpkg.bat to update.", + maj2, + min2, + rev2, + maj1, + min1, + rev1); } } } diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp index a7d12a1b1..cd21f2561 100644 --- a/toolsrc/src/commands_version.cpp +++ b/toolsrc/src/commands_version.cpp @@ -1,7 +1,8 @@ #include "pch.h" + +#include "metrics.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "metrics.h" #define STRINGIFY(...) #__VA_ARGS__ #define MACRO_TO_STRING(X) STRINGIFY(X) @@ -15,7 +16,7 @@ namespace vcpkg::Commands::Version static const std::string s_version = #include "../VERSION.txt" - + std::string(VCPKG_VERSION_AS_STRING) + +std::string(VCPKG_VERSION_AS_STRING) #ifndef NDEBUG + std::string("-debug") #endif @@ -30,8 +31,8 @@ namespace vcpkg::Commands::Version System::println("Vcpkg package management program version %s\n" "\n" - "See LICENSE.txt for license information.", version() - ); + "See LICENSE.txt for license information.", + version()); Checks::exit_success(VCPKG_LINE_INFO); } } diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index baefc3c35..67b06d3f1 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -1,9 +1,10 @@ #include "pch.h" -#include "metrics.h" + #include "filesystem_fs.h" +#include "metrics.h" +#include "vcpkg_Files.h" #include "vcpkg_Strings.h" #include "vcpkg_System.h" -#include "vcpkg_Files.h" namespace vcpkg::Metrics { @@ -47,7 +48,7 @@ namespace vcpkg::Metrics // Generating UUID format version 4 // http://en.wikipedia.org/wiki/Universally_unique_identifier - for (int i = 0; i < partSizes[part]; i++ , index++) + for (int i = 0; i < partSizes[part]; i++, index++) { if (part == 2 && i == 0) { @@ -98,9 +99,8 @@ namespace vcpkg::Metrics else if (ch < 0x20 || ch >= 0x80) { // Note: this treats incoming Strings as Latin-1 - static constexpr const char hex[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + static constexpr const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; encoded.append("\\u00"); encoded.push_back(hex[ch / 16]); encoded.push_back(hex[ch % 16]); @@ -123,21 +123,18 @@ namespace vcpkg::Metrics path += L"\\kernel32.dll"; auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr); - if (versz == 0) - return ""; + if (versz == 0) return ""; std::vector<char> verbuf; verbuf.resize(versz); - if (!GetFileVersionInfoW(path.c_str(), 0, static_cast<DWORD>(verbuf.size()), &verbuf[0])) - return ""; + if (!GetFileVersionInfoW(path.c_str(), 0, static_cast<DWORD>(verbuf.size()), &verbuf[0])) return ""; void* rootblock; UINT rootblocksize; - if (!VerQueryValueW(&verbuf[0], L"\\", &rootblock, &rootblocksize)) - return ""; + if (!VerQueryValueW(&verbuf[0], L"\\", &rootblock, &rootblocksize)) return ""; - auto rootblock_ffi = static_cast<VS_FIXEDFILEINFO *>(rootblock); + auto rootblock_ffi = static_cast<VS_FIXEDFILEINFO*>(rootblock); return Strings::format("%d.%d.%d", static_cast<int>(HIWORD(rootblock_ffi->dwProductVersionMS)), @@ -155,8 +152,7 @@ namespace vcpkg::Metrics void TrackProperty(const std::string& name, const std::string& value) { - if (properties.size() != 0) - properties.push_back(','); + if (properties.size() != 0) properties.push_back(','); properties.append(to_json_string(name)); properties.push_back(':'); properties.append(to_json_string(value)); @@ -164,8 +160,7 @@ namespace vcpkg::Metrics void TrackMetric(const std::string& name, double value) { - if (measurements.size() != 0) - measurements.push_back(','); + if (measurements.size() != 0) measurements.push_back(','); measurements.append(to_json_string(name)); measurements.push_back(':'); measurements.append(std::to_string(value)); @@ -212,21 +207,19 @@ namespace vcpkg::Metrics static MetricMessage g_metricmessage; static bool g_should_send_metrics = #if defined(NDEBUG) && (DISABLE_METRICS == 0) -true + true #else - false + false #endif - ; + ; static bool g_should_print_metrics = false; - bool get_compiled_metrics_enabled() - { - return DISABLE_METRICS == 0; - } + bool get_compiled_metrics_enabled() { return DISABLE_METRICS == 0; } std::wstring get_SQM_user() { - auto hkcu_sqmclient = System::get_registry_string(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", L"UserId"); + auto hkcu_sqmclient = + System::get_registry_string(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", L"UserId"); return hkcu_sqmclient.value_or(L"{}"); } @@ -242,20 +235,11 @@ true first_use_time = get_current_date_time(); } - void set_send_metrics(bool should_send_metrics) - { - g_should_send_metrics = should_send_metrics; - } + void set_send_metrics(bool should_send_metrics) { g_should_send_metrics = should_send_metrics; } - void set_print_metrics(bool should_print_metrics) - { - g_should_print_metrics = should_print_metrics; - } + void set_print_metrics(bool should_print_metrics) { g_should_print_metrics = should_print_metrics; } - void track_metric(const std::string& name, double value) - { - g_metricmessage.TrackMetric(name, value); - } + void track_metric(const std::string& name, double value) { g_metricmessage.TrackMetric(name, value); } void track_property(const std::string& name, const std::wstring& value) { @@ -263,12 +247,7 @@ true std::string converted_value; converted_value.resize(value.size()); std::transform( - value.begin(), value.end(), - converted_value.begin(), - [](wchar_t ch) - { - return static_cast<char>(ch); - }); + value.begin(), value.end(), converted_value.begin(), [](wchar_t ch) { return static_cast<char>(ch); }); g_metricmessage.TrackProperty(name, converted_value); } @@ -283,11 +262,8 @@ true HINTERNET hSession = nullptr, hConnect = nullptr, hRequest = nullptr; BOOL bResults = FALSE; - hSession = WinHttpOpen(L"vcpkg/1.0", - WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0); + hSession = WinHttpOpen( + L"vcpkg/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (hSession) hConnect = WinHttpConnect(hSession, L"dc.services.visualstudio.com", INTERNET_DEFAULT_HTTPS_PORT, 0); @@ -302,12 +278,14 @@ true if (hRequest) { - if (MAXDWORD <= payload.size()) - abort(); + if (MAXDWORD <= payload.size()) abort(); std::wstring hdrs = L"Content-Type: application/json\r\n"; bResults = WinHttpSendRequest(hRequest, - hdrs.c_str(), static_cast<DWORD>(hdrs.size()), - (void*)&payload[0], static_cast<DWORD>(payload.size()), static_cast<DWORD>(payload.size()), + hdrs.c_str(), + static_cast<DWORD>(hdrs.size()), + (void*)&payload[0], + static_cast<DWORD>(payload.size()), + static_cast<DWORD>(payload.size()), 0); } @@ -320,7 +298,12 @@ true if (bResults) { - bResults = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, nullptr, &http_code, &junk, WINHTTP_NO_HEADER_INDEX); + bResults = WinHttpQueryHeaders(hRequest, + WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, + nullptr, + &http_code, + &junk, + WINHTTP_NO_HEADER_INDEX); } std::vector<char> responseBuffer; @@ -353,30 +336,24 @@ true #endif } - if (hRequest) - WinHttpCloseHandle(hRequest); - if (hConnect) - WinHttpCloseHandle(hConnect); - if (hSession) - WinHttpCloseHandle(hSession); + if (hRequest) WinHttpCloseHandle(hRequest); + if (hConnect) WinHttpCloseHandle(hConnect); + if (hSession) WinHttpCloseHandle(hSession); } static fs::path get_bindir() { - wchar_t buf[_MAX_PATH ]; + wchar_t buf[_MAX_PATH]; int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); - if (bytes == 0) - std::abort(); + if (bytes == 0) std::abort(); return fs::path(buf, buf + bytes); } void flush() { std::string payload = g_metricmessage.format_event_data_template(); - if (g_should_print_metrics) - std::cerr << payload << "\n"; - if (!g_should_send_metrics) - return; + if (g_should_print_metrics) std::cerr << payload << "\n"; + if (!g_should_send_metrics) return; // upload(payload); @@ -390,30 +367,27 @@ true if (true) { - const fs::path exe_path = [&fs]() -> fs::path - { - auto vcpkgdir = get_bindir().parent_path(); - auto path = vcpkgdir / "vcpkgmetricsuploader.exe"; - if (fs.exists(path)) - return path; + const fs::path exe_path = [&fs]() -> fs::path { + auto vcpkgdir = get_bindir().parent_path(); + auto path = vcpkgdir / "vcpkgmetricsuploader.exe"; + if (fs.exists(path)) return path; - path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe"; - if (fs.exists(path)) - return path; + path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe"; + if (fs.exists(path)) return path; - return L""; - }(); + return L""; + }(); std::error_code ec; fs.copy_file(exe_path, temp_folder_path_exe, fs::copy_options::skip_existing, ec); - if (ec) - return; + if (ec) return; } const fs::path vcpkg_metrics_txt_path = temp_folder_path / ("vcpkg" + generate_random_UUID() + ".txt"); fs.write_contents(vcpkg_metrics_txt_path, payload); - const std::wstring cmdLine = Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native()); + const std::wstring cmdLine = + Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native()); System::cmd_execute_clean(cmdLine); } } diff --git a/toolsrc/src/triplet.cpp b/toolsrc/src/triplet.cpp index cbdafb14c..411c6c28a 100644 --- a/toolsrc/src/triplet.cpp +++ b/toolsrc/src/triplet.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "Triplet.h" #include "vcpkg_Checks.h" #include "vcpkg_Strings.h" @@ -16,10 +17,7 @@ namespace vcpkg return left.canonical_name() == right.canonical_name(); } - bool operator!=(const Triplet& left, const Triplet& right) - { - return !(left == right); - } + bool operator!=(const Triplet& left, const Triplet& right) { return !(left == right); } Triplet Triplet::from_canonical_name(const std::string& triplet_as_string) { @@ -32,10 +30,7 @@ namespace vcpkg return t; } - const std::string& Triplet::canonical_name() const - { - return this->m_canonical_name; - } + const std::string& Triplet::canonical_name() const { return this->m_canonical_name; } std::string Triplet::architecture() const { @@ -49,8 +44,5 @@ namespace vcpkg return std::string(it + 1, this->m_canonical_name.cend()); } - const std::string& Triplet::to_string() const - { - return this->m_canonical_name; - } + const std::string& Triplet::to_string() const { return this->m_canonical_name; } } diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 8a80e3afe..817ed895a 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -1,12 +1,12 @@ #include "pch.h" + #include "vcpkg_Checks.h" #include "vcpkg_System.h" #include "vcpkglib.h" namespace vcpkg::Checks { - [[noreturn]] - void unreachable(const LineInfo& line_info) + [[noreturn]] void unreachable(const LineInfo& line_info) { System::println(System::Color::error, "Error: Unreachable code was reached"); System::println(System::Color::error, line_info.to_string()); // Always print line_info here @@ -17,8 +17,7 @@ namespace vcpkg::Checks #endif } - [[noreturn]] - void exit_with_code(const LineInfo& line_info, const int exit_code) + [[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code) { if (g_debugging) { @@ -28,8 +27,7 @@ namespace vcpkg::Checks ::exit(exit_code); } - [[noreturn]] - void exit_with_message(const LineInfo& line_info, const CStringView errorMessage) + [[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView errorMessage) { System::println(System::Color::error, errorMessage); exit_fail(line_info); diff --git a/toolsrc/src/vcpkg_Chrono.cpp b/toolsrc/src/vcpkg_Chrono.cpp index cfff1de07..d70f4a054 100644 --- a/toolsrc/src/vcpkg_Chrono.cpp +++ b/toolsrc/src/vcpkg_Chrono.cpp @@ -1,6 +1,7 @@ #include "pch.h" -#include "vcpkg_Chrono.h" + #include "vcpkg_Checks.h" +#include "vcpkg_Chrono.h" namespace vcpkg { @@ -56,8 +57,5 @@ namespace vcpkg return t; } - std::string ElapsedTime::to_string() const - { - return format_time_userfriendly(elapsed<std::chrono::nanoseconds>()); - } + std::string ElapsedTime::to_string() const { return format_time_userfriendly(elapsed<std::chrono::nanoseconds>()); } } diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 56bff7954..9a6428874 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -1,25 +1,24 @@ #include "pch.h" -#include "vcpkg_Dependencies.h" -#include "vcpkg_Graphs.h" -#include "VcpkgPaths.h" + #include "PackageSpec.h" +#include "Paragraphs.h" #include "StatusParagraphs.h" +#include "VcpkgPaths.h" +#include "vcpkg_Dependencies.h" #include "vcpkg_Files.h" +#include "vcpkg_Graphs.h" #include "vcpkg_Util.h" #include "vcpkglib.h" -#include "Paragraphs.h" namespace vcpkg::Dependencies { std::vector<PackageSpec> AnyParagraph::dependencies(const Triplet& triplet) const { - auto to_package_specs = [&](const std::vector<std::string>& dependencies_as_string) - { - return Util::fmap(dependencies_as_string, [&](const std::string s) - { - return PackageSpec::from_name_and_triplet(s, triplet).value_or_exit(VCPKG_LINE_INFO); - }); - }; + auto to_package_specs = [&](const std::vector<std::string>& dependencies_as_string) { + return Util::fmap(dependencies_as_string, [&](const std::string s) { + return PackageSpec::from_name_and_triplet(s, triplet).value_or_exit(VCPKG_LINE_INFO); + }); + }; if (auto p = this->status_paragraph.get()) { @@ -36,28 +35,29 @@ namespace vcpkg::Dependencies return to_package_specs(filter_dependencies(p->depends, triplet)); } - Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot get dependencies because there was none of: source/binary/status paragraphs"); + Checks::exit_with_message(VCPKG_LINE_INFO, + "Cannot get dependencies because there was none of: source/binary/status paragraphs"); } std::string to_output_string(RequestType request_type, const CStringView s) { switch (request_type) { - case RequestType::AUTO_SELECTED: - return Strings::format(" * %s", s); - case RequestType::USER_REQUESTED: - return Strings::format(" %s", s); - default: - Checks::unreachable(VCPKG_LINE_INFO); + case RequestType::AUTO_SELECTED: return Strings::format(" * %s", s); + case RequestType::USER_REQUESTED: return Strings::format(" %s", s); + default: Checks::unreachable(VCPKG_LINE_INFO); } } - InstallPlanAction::InstallPlanAction() : spec() - , any_paragraph() - , plan_type(InstallPlanType::UNKNOWN) - , request_type(RequestType::UNKNOWN) { } + InstallPlanAction::InstallPlanAction() + : spec(), any_paragraph(), plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) + { + } - InstallPlanAction::InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type) : InstallPlanAction() + InstallPlanAction::InstallPlanAction(const PackageSpec& spec, + const AnyParagraph& any_paragraph, + const RequestType& request_type) + : InstallPlanAction() { this->spec = spec; this->request_type = request_type; @@ -90,25 +90,29 @@ namespace vcpkg::Dependencies return left->spec.name() < right->spec.name(); } - RemovePlanAction::RemovePlanAction() : plan_type(RemovePlanType::UNKNOWN) - , request_type(RequestType::UNKNOWN) { } + RemovePlanAction::RemovePlanAction() : plan_type(RemovePlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {} - RemovePlanAction::RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type) - : spec(spec) - , plan_type(plan_type) - , request_type(request_type) { } + RemovePlanAction::RemovePlanAction(const PackageSpec& spec, + const RemovePlanType& plan_type, + const RequestType& request_type) + : spec(spec), plan_type(plan_type), request_type(request_type) + { + } bool ExportPlanAction::compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right) { return left->spec.name() < right->spec.name(); } - ExportPlanAction::ExportPlanAction() : spec() - , any_paragraph() - , plan_type(ExportPlanType::UNKNOWN) - , request_type(RequestType::UNKNOWN) { } + ExportPlanAction::ExportPlanAction() + : spec(), any_paragraph(), plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) + { + } - ExportPlanAction::ExportPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type) : ExportPlanAction() + ExportPlanAction::ExportPlanAction(const PackageSpec& spec, + const AnyParagraph& any_paragraph, + const RequestType& request_type) + : ExportPlanAction() { this->spec = spec; this->request_type = request_type; @@ -135,7 +139,9 @@ namespace vcpkg::Dependencies return left->spec.name() < right->spec.name(); } - std::vector<InstallPlanAction> create_install_plan(const VcpkgPaths& paths, const std::vector<PackageSpec>& specs, const StatusParagraphs& status_db) + std::vector<InstallPlanAction> create_install_plan(const VcpkgPaths& paths, + const std::vector<PackageSpec>& specs, + const StatusParagraphs& status_db) { struct InstallAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, InstallPlanAction> { @@ -143,20 +149,24 @@ namespace vcpkg::Dependencies const StatusParagraphs& status_db; const std::unordered_set<PackageSpec>& specs_as_set; - InstallAdjacencyProvider(const VcpkgPaths& p, const StatusParagraphs& s, const std::unordered_set<PackageSpec>& specs_as_set) : paths(p) - , status_db(s) - , specs_as_set(specs_as_set) {} + InstallAdjacencyProvider(const VcpkgPaths& p, + const StatusParagraphs& s, + const std::unordered_set<PackageSpec>& specs_as_set) + : paths(p), status_db(s), specs_as_set(specs_as_set) + { + } std::vector<PackageSpec> adjacency_list(const InstallPlanAction& plan) const override { - if (plan.any_paragraph.status_paragraph.get()) - return std::vector<PackageSpec>{}; + if (plan.any_paragraph.status_paragraph.get()) return std::vector<PackageSpec>{}; return plan.any_paragraph.dependencies(plan.spec.triplet()); } InstallPlanAction load_vertex_data(const PackageSpec& spec) const override { - const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() ? RequestType::USER_REQUESTED : RequestType::AUTO_SELECTED; + const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() + ? RequestType::USER_REQUESTED + : RequestType::AUTO_SELECTED; auto it = status_db.find_installed(spec); if (it != status_db.end()) return InstallPlanAction{ spec, { *it->get(), nullopt, nullopt }, request_type }; @@ -165,25 +175,28 @@ namespace vcpkg::Dependencies if (auto bpgh = maybe_bpgh.get()) return InstallPlanAction{ spec, { nullopt, *bpgh, nullopt }, request_type }; - Expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec)); + Expected<SourceParagraph> maybe_spgh = + Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec)); if (auto spgh = maybe_spgh.get()) return InstallPlanAction{ spec, { nullopt, nullopt, *spgh }, request_type }; - return InstallPlanAction{ spec , { nullopt, nullopt, nullopt }, request_type }; + return InstallPlanAction{ spec, { nullopt, nullopt, nullopt }, request_type }; } }; const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend()); - std::vector<InstallPlanAction> toposort = Graphs::topological_sort(specs, InstallAdjacencyProvider{ paths, status_db, specs_as_set }); - Util::erase_remove_if(toposort, [](const InstallPlanAction& plan) - { - return plan.request_type == RequestType::AUTO_SELECTED && plan.plan_type == InstallPlanType::ALREADY_INSTALLED; - }); + std::vector<InstallPlanAction> toposort = + Graphs::topological_sort(specs, InstallAdjacencyProvider{ paths, status_db, specs_as_set }); + Util::erase_remove_if(toposort, [](const InstallPlanAction& plan) { + return plan.request_type == RequestType::AUTO_SELECTED && + plan.plan_type == InstallPlanType::ALREADY_INSTALLED; + }); return toposort; } - std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs, const StatusParagraphs& status_db) + std::vector<RemovePlanAction> create_remove_plan(const std::vector<PackageSpec>& specs, + const StatusParagraphs& status_db) { struct RemoveAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, RemovePlanAction> { @@ -191,10 +204,12 @@ namespace vcpkg::Dependencies const std::vector<StatusParagraph*>& installed_ports; const std::unordered_set<PackageSpec>& specs_as_set; - RemoveAdjacencyProvider(const StatusParagraphs& status_db, const std::vector<StatusParagraph*>& installed_ports, const std::unordered_set<PackageSpec>& specs_as_set) - : status_db(status_db) - , installed_ports(installed_ports) - , specs_as_set(specs_as_set) { } + RemoveAdjacencyProvider(const StatusParagraphs& status_db, + const std::vector<StatusParagraph*>& installed_ports, + const std::unordered_set<PackageSpec>& specs_as_set) + : status_db(status_db), installed_ports(installed_ports), specs_as_set(specs_as_set) + { + } std::vector<PackageSpec> adjacency_list(const RemovePlanAction& plan) const override { @@ -207,12 +222,10 @@ namespace vcpkg::Dependencies std::vector<PackageSpec> dependents; for (const StatusParagraph* an_installed_package : installed_ports) { - if (an_installed_package->package.spec.triplet() != spec.triplet()) - continue; + if (an_installed_package->package.spec.triplet() != spec.triplet()) continue; const std::vector<std::string>& deps = an_installed_package->package.depends; - if (std::find(deps.begin(), deps.end(), spec.name()) == deps.end()) - continue; + if (std::find(deps.begin(), deps.end(), spec.name()) == deps.end()) continue; dependents.push_back(an_installed_package->package.spec); } @@ -222,7 +235,9 @@ namespace vcpkg::Dependencies RemovePlanAction load_vertex_data(const PackageSpec& spec) const override { - const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() ? RequestType::USER_REQUESTED : RequestType::AUTO_SELECTED; + const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() + ? RequestType::USER_REQUESTED + : RequestType::AUTO_SELECTED; const StatusParagraphs::const_iterator it = status_db.find_installed(spec); if (it == status_db.end()) { @@ -237,7 +252,9 @@ namespace vcpkg::Dependencies return Graphs::topological_sort(specs, RemoveAdjacencyProvider{ status_db, installed_ports, specs_as_set }); } - std::vector<ExportPlanAction> create_export_plan(const VcpkgPaths& paths, const std::vector<PackageSpec>& specs, const StatusParagraphs& status_db) + std::vector<ExportPlanAction> create_export_plan(const VcpkgPaths& paths, + const std::vector<PackageSpec>& specs, + const StatusParagraphs& status_db) { struct ExportAdjacencyProvider final : Graphs::AdjacencyProvider<PackageSpec, ExportPlanAction> { @@ -245,9 +262,12 @@ namespace vcpkg::Dependencies const StatusParagraphs& status_db; const std::unordered_set<PackageSpec>& specs_as_set; - ExportAdjacencyProvider(const VcpkgPaths& p, const StatusParagraphs& s, const std::unordered_set<PackageSpec>& specs_as_set) : paths(p) - , status_db(s) - , specs_as_set(specs_as_set) {} + ExportAdjacencyProvider(const VcpkgPaths& p, + const StatusParagraphs& s, + const std::unordered_set<PackageSpec>& specs_as_set) + : paths(p), status_db(s), specs_as_set(specs_as_set) + { + } std::vector<PackageSpec> adjacency_list(const ExportPlanAction& plan) const override { @@ -256,22 +276,26 @@ namespace vcpkg::Dependencies ExportPlanAction load_vertex_data(const PackageSpec& spec) const override { - const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() ? RequestType::USER_REQUESTED : RequestType::AUTO_SELECTED; + const RequestType request_type = specs_as_set.find(spec) != specs_as_set.end() + ? RequestType::USER_REQUESTED + : RequestType::AUTO_SELECTED; Expected<BinaryParagraph> maybe_bpgh = Paragraphs::try_load_cached_package(paths, spec); if (auto bpgh = maybe_bpgh.get()) - return ExportPlanAction{ spec,{ nullopt, *bpgh, nullopt }, request_type }; + return ExportPlanAction{ spec, { nullopt, *bpgh, nullopt }, request_type }; - Expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec)); + Expected<SourceParagraph> maybe_spgh = + Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec)); if (auto spgh = maybe_spgh.get()) - return ExportPlanAction{ spec,{ nullopt, nullopt, *spgh }, request_type }; + return ExportPlanAction{ spec, { nullopt, nullopt, *spgh }, request_type }; - return ExportPlanAction{ spec ,{ nullopt, nullopt, nullopt }, request_type }; + return ExportPlanAction{ spec, { nullopt, nullopt, nullopt }, request_type }; } }; const std::unordered_set<PackageSpec> specs_as_set(specs.cbegin(), specs.cend()); - std::vector<ExportPlanAction> toposort = Graphs::topological_sort(specs, ExportAdjacencyProvider{ paths, status_db, specs_as_set }); + std::vector<ExportPlanAction> toposort = + Graphs::topological_sort(specs, ExportAdjacencyProvider{ paths, status_db, specs_as_set }); return toposort; } } diff --git a/toolsrc/src/vcpkg_Enums.cpp b/toolsrc/src/vcpkg_Enums.cpp index 38102a804..41479d592 100644 --- a/toolsrc/src/vcpkg_Enums.cpp +++ b/toolsrc/src/vcpkg_Enums.cpp @@ -1,16 +1,13 @@ #include "pch.h" -#include "vcpkg_Enums.h" + #include "vcpkg_Checks.h" +#include "vcpkg_Enums.h" namespace vcpkg::Enums { - std::string nullvalue_to_string(const std::string& enum_name) - { - return Strings::format("%s_NULLVALUE", enum_name); - } + std::string nullvalue_to_string(const std::string& enum_name) { return Strings::format("%s_NULLVALUE", enum_name); } - [[noreturn]] - void nullvalue_used(const LineInfo& line_info, const std::string& enum_name) + [[noreturn]] void nullvalue_used(const LineInfo& line_info, const std::string& enum_name) { Checks::exit_with_message(line_info, "NULLVALUE of enum %s was used", enum_name); } diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 599c6f5ef..385e95f27 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Files.h" #include "vcpkg_System.h" #include <thread> @@ -51,7 +52,8 @@ namespace vcpkg::Files return std::move(output); } - virtual fs::path find_file_recursively_up(const fs::path & starting_dir, const std::string & filename) const override + virtual fs::path find_file_recursively_up(const fs::path& starting_dir, + const std::string& filename) const override { fs::path current_dir = starting_dir; for (; !current_dir.empty(); current_dir = current_dir.parent_path()) @@ -66,7 +68,7 @@ namespace vcpkg::Files return current_dir; } - virtual std::vector<fs::path> get_files_recursive(const fs::path & dir) const override + virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const override { std::vector<fs::path> ret; @@ -79,7 +81,7 @@ namespace vcpkg::Files return ret; } - virtual std::vector<fs::path> get_files_non_recursive(const fs::path & dir) const override + virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const override { std::vector<fs::path> ret; @@ -92,7 +94,7 @@ namespace vcpkg::Files return ret; } - virtual void write_lines(const fs::path & file_path, const std::vector<std::string>& lines) override + virtual void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) override { std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); for (const std::string& line : lines) @@ -102,19 +104,13 @@ namespace vcpkg::Files output.close(); } - virtual void rename(const fs::path & oldpath, const fs::path & newpath) override + virtual void rename(const fs::path& oldpath, const fs::path& newpath) override { fs::stdfs::rename(oldpath, newpath); } - virtual bool remove(const fs::path & path) override - { - return fs::stdfs::remove(path); - } - virtual bool remove(const fs::path & path, std::error_code& ec) override - { - return fs::stdfs::remove(path, ec); - } - virtual std::uintmax_t remove_all(const fs::path & path, std::error_code& ec) override + virtual bool remove(const fs::path& path) override { return fs::stdfs::remove(path); } + virtual bool remove(const fs::path& path, std::error_code& ec) override { return fs::stdfs::remove(path, ec); } + virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) override { // Working around the currently buggy remove_all() std::uintmax_t out = fs::stdfs::remove_all(path, ec); @@ -128,28 +124,19 @@ namespace vcpkg::Files if (this->exists(path)) { - System::println(System::Color::warning, "Some files in %s were unable to be removed. Close any editors operating in this directory and retry.", path.string()); + System::println(System::Color::warning, + "Some files in %s were unable to be removed. Close any editors operating in this " + "directory and retry.", + path.string()); } return out; } - virtual bool exists(const fs::path & path) const override - { - return fs::stdfs::exists(path); - } - virtual bool is_directory(const fs::path & path) const override - { - return fs::stdfs::is_directory(path); - } - virtual bool is_regular_file(const fs::path & path) const override - { - return fs::stdfs::is_regular_file(path); - } - virtual bool is_empty(const fs::path & path) const override - { - return fs::stdfs::is_empty(path); - } - virtual bool create_directory(const fs::path & path, std::error_code & ec) override + virtual bool exists(const fs::path& path) const override { return fs::stdfs::exists(path); } + virtual bool is_directory(const fs::path& path) const override { return fs::stdfs::is_directory(path); } + virtual bool is_regular_file(const fs::path& path) const override { return fs::stdfs::is_regular_file(path); } + virtual bool is_empty(const fs::path& path) const override { return fs::stdfs::is_empty(path); } + virtual bool create_directory(const fs::path& path, std::error_code& ec) override { return fs::stdfs::create_directory(path, ec); } @@ -157,11 +144,12 @@ namespace vcpkg::Files { return fs::stdfs::create_directories(path, ec); } - virtual void copy(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts) override + virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) override { fs::stdfs::copy(oldpath, newpath, opts); } - virtual bool copy_file(const fs::path & oldpath, const fs::path & newpath, fs::copy_options opts, std::error_code & ec) override + virtual bool + copy_file(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) override { return fs::stdfs::copy_file(oldpath, newpath, opts, ec); } @@ -180,10 +168,9 @@ namespace vcpkg::Files Checks::check_exit(VCPKG_LINE_INFO, count == data.size()); } - }; - Filesystem & get_real_filesystem() + Filesystem& get_real_filesystem() { static RealFilesystem real_fs; return real_fs; diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index 1e74f2e90..7d8e4767e 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -1,12 +1,15 @@ #include "pch.h" -#include "vcpkg_Input.h" -#include "vcpkg_System.h" + #include "metrics.h" #include "vcpkg_Commands.h" +#include "vcpkg_Input.h" +#include "vcpkg_System.h" namespace vcpkg::Input { - PackageSpec check_and_get_package_spec(const std::string& package_spec_as_string, const Triplet& default_triplet, CStringView example_text) + PackageSpec check_and_get_package_spec(const std::string& package_spec_as_string, + const Triplet& default_triplet, + CStringView example_text) { const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string); Expected<PackageSpec> expected_spec = PackageSpec::from_string(as_lowercase, default_triplet); diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 5f46af6d2..97f56e746 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -1,20 +1,15 @@ #include "pch.h" + #include "vcpkg_Strings.h" #include "vcpkg_Util.h" namespace vcpkg::Strings::details { // To disambiguate between two overloads - static const auto isspace = [](const char c) - { - return std::isspace(c); - }; + static const auto isspace = [](const char c) { return std::isspace(c); }; // Avoids C4244 warnings because of char<->int conversion that occur when using std::tolower() - static char tolower_char(const char c) - { - return static_cast<char>(std::tolower(c)); - } + static char tolower_char(const char c) { return static_cast<char>(std::tolower(c)); } static _locale_t& c_locale() { @@ -66,10 +61,11 @@ namespace vcpkg::Strings std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern) { const std::string pattern_as_lower_case(ascii_to_lowercase(pattern)); - return search(s.begin(), s.end(), pattern_as_lower_case.begin(), pattern_as_lower_case.end(), [](const char a, const char b) - { - return details::tolower_char(a) == b; - }); + return search(s.begin(), + s.end(), + pattern_as_lower_case.begin(), + pattern_as_lower_case.end(), + [](const char a, const char b) { return details::tolower_char(a) == b; }); } std::string ascii_to_lowercase(const std::string& input) diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index f5a34e3ea..7c06759af 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -1,6 +1,7 @@ #include "pch.h" -#include "vcpkg_System.h" + #include "vcpkg_Checks.h" +#include "vcpkg_System.h" #include "vcpkglib.h" namespace vcpkg::System @@ -18,19 +19,19 @@ namespace vcpkg::System { wchar_t buf[_MAX_PATH]; int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); - if (bytes == 0) - std::abort(); + if (bytes == 0) std::abort(); return fs::path(buf, buf + bytes); } int cmd_execute_clean(const CWStringView cmd_line) { - static const std::wstring system_root = get_environmental_variable(L"SystemRoot").value_or_exit(VCPKG_LINE_INFO); + static const std::wstring system_root = + get_environmental_variable(L"SystemRoot").value_or_exit(VCPKG_LINE_INFO); static const std::wstring system_32 = system_root + LR"(\system32)"; - static const std::wstring new_PATH = Strings::wformat(LR"(Path=%s;%s;%s\Wbem;%s\WindowsPowerShell\v1.0\)", system_32, system_root, system_32, system_32); + static const std::wstring new_PATH = Strings::wformat( + LR"(Path=%s;%s;%s\Wbem;%s\WindowsPowerShell\v1.0\)", system_32, system_root, system_32, system_32); - std::vector<std::wstring> env_wstrings = - { + std::vector<std::wstring> env_wstrings = { L"ALLUSERSPROFILE", L"APPDATA", L"CommonProgramFiles", @@ -84,8 +85,7 @@ namespace vcpkg::System { const Optional<std::wstring> value = System::get_environmental_variable(env_wstring); auto v = value.get(); - if (!v || v->empty()) - continue; + if (!v || v->empty()) continue; env_wstring.push_back(L'='); env_wstring.append(*v); @@ -97,11 +97,10 @@ namespace vcpkg::System // Basically we are wrapping it in quotes const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); - if (g_debugging) - System::println("[DEBUG] _wspawnlpe(cmd.exe /c %s)", Strings::utf16_to_utf8(actual_cmd_line)); - auto exit_code = _wspawnlpe(_P_WAIT, L"cmd.exe", L"cmd.exe", L"/c", actual_cmd_line.c_str(), nullptr, env_cstr.data()); - if (g_debugging) - System::println("[DEBUG] _wspawnlpe() returned %d", exit_code); + if (g_debugging) System::println("[DEBUG] _wspawnlpe(cmd.exe /c %s)", Strings::utf16_to_utf8(actual_cmd_line)); + auto exit_code = + _wspawnlpe(_P_WAIT, L"cmd.exe", L"cmd.exe", L"/c", actual_cmd_line.c_str(), nullptr, env_cstr.data()); + if (g_debugging) System::println("[DEBUG] _wspawnlpe() returned %d", exit_code); return static_cast<int>(exit_code); } @@ -112,11 +111,9 @@ namespace vcpkg::System // Basically we are wrapping it in quotes const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line); - if (g_debugging) - System::println("[DEBUG] _wsystem(%s)", Strings::utf16_to_utf8(actual_cmd_line)); + if (g_debugging) System::println("[DEBUG] _wsystem(%s)", Strings::utf16_to_utf8(actual_cmd_line)); int exit_code = _wsystem(actual_cmd_line.c_str()); - if (g_debugging) - System::println("[DEBUG] _wsystem() returned %d", exit_code); + if (g_debugging) System::println("[DEBUG] _wsystem() returned %d", exit_code); return exit_code; } @@ -149,13 +146,11 @@ namespace vcpkg::System std::wstring create_powershell_script_cmd(const fs::path& script_path, const CWStringView args) { // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - return Strings::wformat(LR"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args); + return Strings::wformat( + LR"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args); } - void print(const CStringView message) - { - fputs(message, stdout); - } + void print(const CStringView message) { fputs(message, stdout); } void println(const CStringView message) { @@ -185,8 +180,7 @@ namespace vcpkg::System Optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept { auto sz = GetEnvironmentVariableW(varname, nullptr, 0); - if (sz == 0) - return nullopt; + if (sz == 0) return nullopt; std::wstring ret(sz, L'\0'); @@ -206,13 +200,13 @@ namespace vcpkg::System { HKEY k = nullptr; LSTATUS ec = RegOpenKeyExW(base, subKey, NULL, KEY_READ, &k); - if (ec != ERROR_SUCCESS) - return nullopt; + if (ec != ERROR_SUCCESS) return nullopt; DWORD dwBufferSize = 0; DWORD dwType = 0; auto rc = RegQueryValueExW(k, valuename, nullptr, &dwType, nullptr, &dwBufferSize); - if (rc != ERROR_SUCCESS || !is_string_keytype(dwType) || dwBufferSize == 0 || dwBufferSize % sizeof(wchar_t) != 0) + if (rc != ERROR_SUCCESS || !is_string_keytype(dwType) || dwBufferSize == 0 || + dwBufferSize % sizeof(wchar_t) != 0) return nullopt; std::wstring ret; ret.resize(dwBufferSize / sizeof(wchar_t)); @@ -233,29 +227,27 @@ namespace vcpkg::System const fs::path& get_ProgramFiles_32_bit() { - static const fs::path p = []() -> fs::path + static const fs::path p = []() -> fs::path { + auto value = System::get_environmental_variable(L"ProgramFiles(x86)"); + if (auto v = value.get()) { - auto value = System::get_environmental_variable(L"ProgramFiles(x86)"); - if (auto v = value.get()) - { - return std::move(*v); - } - return get_ProgramFiles(); - }(); + return std::move(*v); + } + return get_ProgramFiles(); + }(); return p; } const fs::path& get_ProgramFiles_platform_bitness() { - static const fs::path p = []() -> fs::path + static const fs::path p = []() -> fs::path { + auto value = System::get_environmental_variable(L"ProgramW6432"); + if (auto v = value.get()) { - auto value = System::get_environmental_variable(L"ProgramW6432"); - if (auto v = value.get()) - { - return std::move(*v); - } - return get_ProgramFiles(); - }(); + return std::move(*v); + } + return get_ProgramFiles(); + }(); return p; } } diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index 90d3e99b9..af0d1baba 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/src/vcpkglib.cpp @@ -1,17 +1,19 @@ #include "pch.h" -#include "vcpkglib.h" -#include "vcpkg_Files.h" + #include "Paragraphs.h" #include "metrics.h" -#include "vcpkg_Util.h" +#include "vcpkg_Files.h" #include "vcpkg_Strings.h" #include "vcpkg_Util.h" +#include "vcpkglib.h" namespace vcpkg { bool g_debugging = false; - static StatusParagraphs load_current_database(Files::Filesystem& fs, const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) + static StatusParagraphs load_current_database(Files::Filesystem& fs, + const fs::path& vcpkg_dir_status_file, + const fs::path& vcpkg_dir_status_file_old) { if (!fs.exists(vcpkg_dir_status_file)) { @@ -61,10 +63,8 @@ namespace vcpkg } for (auto&& file : update_files) { - if (!fs.is_regular_file(file)) - continue; - if (file.filename() == "incomplete") - continue; + if (!fs.is_regular_file(file)) continue; + if (file.filename() == "incomplete") continue; auto pghs = Paragraphs::get_paragraphs(fs, file).value_or_exit(VCPKG_LINE_INFO); for (auto&& p : pghs) @@ -79,8 +79,7 @@ namespace vcpkg for (auto&& file : update_files) { - if (!fs.is_regular_file(file)) - continue; + if (!fs.is_regular_file(file)) continue; fs.remove(file); } @@ -101,7 +100,9 @@ namespace vcpkg fs.rename(tmp_update_filename, update_filename); } - static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs, std::vector<std::string>* lines, const fs::path& listfile_path) + static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs, + std::vector<std::string>* lines, + const fs::path& listfile_path) { static bool was_tracked = false; @@ -174,15 +175,15 @@ namespace vcpkg std::vector<StatusParagraph*> installed_packages; for (auto&& pgh : status_db) { - if (pgh->state != InstallState::INSTALLED || pgh->want != Want::INSTALL) - continue; + if (pgh->state != InstallState::INSTALLED || pgh->want != Want::INSTALL) continue; installed_packages.push_back(pgh.get()); } return installed_packages; } - std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const VcpkgPaths& paths, const StatusParagraphs& status_db) + std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const VcpkgPaths& paths, + const StatusParagraphs& status_db) { auto& fs = paths.get_filesystem(); @@ -196,28 +197,47 @@ namespace vcpkg } const fs::path listfile_path = paths.listfile_path(pgh->package); - std::vector<std::string> installed_files_of_current_pgh = fs.read_lines(listfile_path).value_or_exit(VCPKG_LINE_INFO); + std::vector<std::string> installed_files_of_current_pgh = + fs.read_lines(listfile_path).value_or_exit(VCPKG_LINE_INFO); Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); upgrade_to_slash_terminated_sorted_format(fs, &installed_files_of_current_pgh, listfile_path); // Remove the directories - Util::erase_remove_if(installed_files_of_current_pgh, [](const std::string& file) { return file.back() == '/'; }); + Util::erase_remove_if(installed_files_of_current_pgh, + [](const std::string& file) { return file.back() == '/'; }); - StatusParagraphAndAssociatedFiles pgh_and_files = { *pgh, SortedVector<std::string>(std::move(installed_files_of_current_pgh)) }; + StatusParagraphAndAssociatedFiles pgh_and_files = { + *pgh, SortedVector<std::string>(std::move(installed_files_of_current_pgh)) + }; installed_files.push_back(std::move(pgh_and_files)); } return installed_files; } - CMakeVariable::CMakeVariable(const CWStringView varname, const wchar_t* varvalue) : s(Strings::wformat(LR"("-D%s=%s")", varname, varvalue)) { } - CMakeVariable::CMakeVariable(const CWStringView varname, const std::string& varvalue) : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str()) { } - CMakeVariable::CMakeVariable(const CWStringView varname, const std::wstring& varvalue) : CMakeVariable(varname, varvalue.c_str()) {} - CMakeVariable::CMakeVariable(const CWStringView varname, const fs::path& path) : CMakeVariable(varname, path.generic_wstring()) {} + CMakeVariable::CMakeVariable(const CWStringView varname, const wchar_t* varvalue) + : s(Strings::wformat(LR"("-D%s=%s")", varname, varvalue)) + { + } + CMakeVariable::CMakeVariable(const CWStringView varname, const std::string& varvalue) + : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str()) + { + } + CMakeVariable::CMakeVariable(const CWStringView varname, const std::wstring& varvalue) + : CMakeVariable(varname, varvalue.c_str()) + { + } + CMakeVariable::CMakeVariable(const CWStringView varname, const fs::path& path) + : CMakeVariable(varname, path.generic_wstring()) + { + } - std::wstring make_cmake_cmd(const fs::path& cmake_exe, const fs::path& cmake_script, const std::vector<CMakeVariable>& pass_variables) + std::wstring make_cmake_cmd(const fs::path& cmake_exe, + const fs::path& cmake_script, + const std::vector<CMakeVariable>& pass_variables) { std::wstring cmd_cmake_pass_variables = Strings::join(L" ", pass_variables, [](auto&& v) { return v.s; }); - return Strings::wformat(LR"("%s" %s -P "%s")", cmake_exe.native(), cmd_cmake_pass_variables, cmake_script.generic_wstring()); + return Strings::wformat( + LR"("%s" %s -P "%s")", cmake_exe.native(), cmd_cmake_pass_variables, cmake_script.generic_wstring()); } } diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 12bf01d7e..9f992d320 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "vcpkg_Checks.h" #include "vcpkglib_helpers.h" @@ -15,7 +16,8 @@ namespace vcpkg::details return it->second; } - std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname) + std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, + const std::string& fieldname) { auto it = fields->find(fieldname); if (it == fields->end()) @@ -35,7 +37,8 @@ namespace vcpkg::details return it->second; } - std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname) + std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, + const std::string& fieldname) { auto it = fields->find(fieldname); Checks::check_exit(VCPKG_LINE_INFO, it != fields->end(), "Required field not present: %s", fieldname); @@ -48,8 +51,6 @@ namespace vcpkg::details std::string shorten_description(const std::string& desc) { auto simple_desc = std::regex_replace(desc, std::regex("\\s+"), " "); - return simple_desc.size() <= 52 - ? simple_desc - : simple_desc.substr(0, 49) + "..."; + return simple_desc.size() <= 52 ? simple_desc : simple_desc.substr(0, 49) + "..."; } } |
