diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-21 23:51:45 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-09-21 23:51:45 -0700 |
| commit | aeab2fee872f38189d069cf60da1e45c4dbf13bd (patch) | |
| tree | 7ae6ffdd118eb1deab24888c6906bfe9ca9b4e0a | |
| parent | 03b43aad42c8eca03937148cda7afffceeeeca1c (diff) | |
| download | vcpkg-aeab2fee872f38189d069cf60da1e45c4dbf13bd.tar.gz vcpkg-aeab2fee872f38189d069cf60da1e45c4dbf13bd.zip | |
Place update_command() in a separate cpp file
| -rw-r--r-- | toolsrc/src/commands_other.cpp | 85 | ||||
| -rw-r--r-- | toolsrc/src/commands_update.cpp | 91 | ||||
| -rw-r--r-- | toolsrc/vcpkg/vcpkg.vcxproj | 1 | ||||
| -rw-r--r-- | toolsrc/vcpkg/vcpkg.vcxproj.filters | 3 |
4 files changed, 95 insertions, 85 deletions
diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index c7dcc2586..a8192691d 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -1,6 +1,5 @@ #include "vcpkg_Commands.h" #include <iostream> -#include <unordered_set> #include "vcpkg_Environment.h" #include "vcpkg.h" #include "vcpkg_System.h" @@ -51,90 +50,6 @@ namespace vcpkg " vcpkg " << command_and_arguments << "\n"; } - void update_command(const vcpkg_cmd_arguments& /*args*/, const vcpkg_paths& paths) - { - auto status_db = database_load_check(paths); - - std::unordered_map<std::string, std::string> src_names_to_versions; - - auto begin_it = fs::directory_iterator(paths.ports); - auto end_it = fs::directory_iterator(); - for (; begin_it != end_it; ++begin_it) - { - const auto& path = begin_it->path(); - try - { - auto pghs = get_paragraphs(path / "CONTROL"); - if (pghs.empty()) - continue; - auto srcpgh = SourceParagraph(pghs[0]); - src_names_to_versions.emplace(srcpgh.name, srcpgh.version); - } - catch (std::runtime_error const&) - { - } - } - - std::string packages_list; - - std::vector<std::string> packages_output; - for (auto&& pgh : database_load_check(paths)) - { - if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) - continue; - auto it = src_names_to_versions.find(pgh->package.name); - if (it == src_names_to_versions.end()) - { - // Package was not installed from portfile - continue; - } - if (it->second != pgh->package.version) - { - packages_output.push_back(Strings::format("%-27s %s -> %s", - pgh->package.displayname(), - pgh->package.version, - it->second)); - packages_list.append(" " + pgh->package.displayname()); - } - } - std::sort(packages_output.begin(), packages_output.end()); - if (packages_output.empty()) - { - System::println("No packages need updating."); - } - else - { - System::println("The following packages differ from their port versions:"); - for (auto&& package : packages_output) - { - System::println(" %s", package.c_str()); - } - System::println("\nTo update these packages, run\n vcpkg remove --purge <pkgs>...\n vcpkg install <pkgs>..."); - } - - auto version_file = Files::get_contents(paths.root / "toolsrc" / "VERSION.txt"); - if (auto version_contents = version_file.get()) - { - int maj1, min1, rev1; - auto num1 = sscanf_s(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1); - - int maj2, min2, rev2; - auto num2 = sscanf_s(version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2); - - if (num1 == 3 && num2 == 3) - { - if (maj1 != maj2 || min1 != min2 || rev1 != rev2) - { - System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use scripts\\bootstrap.ps1 to update.", - maj2, min2, rev2, - maj1, min1, rev1); - } - } - } - - exit(EXIT_SUCCESS); - } - void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { static auto example = "edit zlib"; diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp new file mode 100644 index 000000000..eec3e46a7 --- /dev/null +++ b/toolsrc/src/commands_update.cpp @@ -0,0 +1,91 @@ +#include "vcpkg_Commands.h" +#include "vcpkg.h" +#include "vcpkg_System.h" +#include "vcpkg_Files.h" + +namespace vcpkg +{ + void update_command(const vcpkg_cmd_arguments& /*args*/, const vcpkg_paths& paths) + { + auto status_db = database_load_check(paths); + + std::unordered_map<std::string, std::string> src_names_to_versions; + + auto begin_it = fs::directory_iterator(paths.ports); + auto end_it = fs::directory_iterator(); + for (; begin_it != end_it; ++begin_it) + { + const auto& path = begin_it->path(); + try + { + auto pghs = get_paragraphs(path / "CONTROL"); + if (pghs.empty()) + continue; + auto srcpgh = SourceParagraph(pghs[0]); + src_names_to_versions.emplace(srcpgh.name, srcpgh.version); + } + catch (std::runtime_error const&) + { + } + } + + std::string packages_list; + + std::vector<std::string> packages_output; + for (auto&& pgh : database_load_check(paths)) + { + if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) + continue; + auto it = src_names_to_versions.find(pgh->package.name); + if (it == src_names_to_versions.end()) + { + // Package was not installed from portfile + continue; + } + if (it->second != pgh->package.version) + { + packages_output.push_back(Strings::format("%-27s %s -> %s", + pgh->package.displayname(), + pgh->package.version, + it->second)); + packages_list.append(" " + pgh->package.displayname()); + } + } + std::sort(packages_output.begin(), packages_output.end()); + if (packages_output.empty()) + { + System::println("No packages need updating."); + } + else + { + System::println("The following packages differ from their port versions:"); + for (auto&& package : packages_output) + { + System::println(" %s", package.c_str()); + } + System::println("\nTo update these packages, run\n vcpkg remove --purge <pkgs>...\n vcpkg install <pkgs>..."); + } + + auto version_file = Files::get_contents(paths.root / "toolsrc" / "VERSION.txt"); + if (auto version_contents = version_file.get()) + { + int maj1, min1, rev1; + auto num1 = sscanf_s(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1); + + int maj2, min2, rev2; + auto num2 = sscanf_s(version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2); + + if (num1 == 3 && num2 == 3) + { + if (maj1 != maj2 || min1 != min2 || rev1 != rev2) + { + System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use scripts\\bootstrap.ps1 to update.", + maj2, min2, rev2, + maj1, min1, rev1); + } + } + } + + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/vcpkg/vcpkg.vcxproj b/toolsrc/vcpkg/vcpkg.vcxproj index 748c4522a..70c1a96ef 100644 --- a/toolsrc/vcpkg/vcpkg.vcxproj +++ b/toolsrc/vcpkg/vcpkg.vcxproj @@ -131,6 +131,7 @@ <ClCompile Include="..\src\commands_cache.cpp" /> <ClCompile Include="..\src\commands_remove.cpp" /> <ClCompile Include="..\src\commands_search.cpp" /> + <ClCompile Include="..\src\commands_update.cpp" /> <ClCompile Include="..\src\vcpkg_cmd_arguments.cpp" /> <ClCompile Include="..\src\commands_other.cpp" /> <ClCompile Include="..\src\vcpkg_Environment.cpp" /> diff --git a/toolsrc/vcpkg/vcpkg.vcxproj.filters b/toolsrc/vcpkg/vcpkg.vcxproj.filters index 88ef1f298..4511c989c 100644 --- a/toolsrc/vcpkg/vcpkg.vcxproj.filters +++ b/toolsrc/vcpkg/vcpkg.vcxproj.filters @@ -48,6 +48,9 @@ <ClCompile Include="..\src\commands_cache.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\src\commands_update.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\include\post_build_lint.h"> |
