From af120041b68f2b9221bdd3cf0047f7e20705aa5a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 17:04:41 -0800 Subject: Move file functions to vcpkg_Files.h --- toolsrc/src/post_build_lint.cpp | 119 ++++++++++++++-------------------------- toolsrc/src/vcpkg_Files.cpp | 15 +++++ 2 files changed, 55 insertions(+), 79 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index d358cca45..b93844f03 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -1,7 +1,7 @@ #include #include "vcpkg_paths.h" #include "package_spec.h" -#include +#include "vcpkg_Files.h" #include #include "vcpkg_System.h" #include "coff_file_reader.h" @@ -20,52 +20,14 @@ namespace vcpkg static const fs::path DUMPBIN_EXE = R"(%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe)"; - namespace + static void print_vector_of_files(const std::vector& paths) { - void print_vector_of_files(const std::vector& paths) - { - System::println(""); - for (const fs::path& p : paths) - { - System::println(" %s", p.generic_string()); - } - System::println(""); - } - - template - void non_recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector* output) - { - std::copy_if(fs::directory_iterator(dir), fs::directory_iterator(), std::back_inserter(*output), predicate); - } - - template - void recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector* output) - { - std::copy_if(fs::recursive_directory_iterator(dir), fs::recursive_directory_iterator(), std::back_inserter(*output), predicate); - } - - template - std::vector recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate) - { - std::vector v; - recursive_find_matching_paths_in_dir(dir, predicate, &v); - return v; - } - - void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector* output) - { - recursive_find_matching_paths_in_dir(dir, [&extension](const fs::path& current) - { - return !fs::is_directory(current) && current.extension() == extension; - }, output); - } - - std::vector recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension) + System::println(""); + for (const fs::path& p : paths) { - std::vector v; - recursive_find_files_with_extension_in_dir(dir, extension, &v); - return v; + System::println(" %s", p.generic_string()); } + System::println(""); } static lint_status check_for_files_in_include_directory(const fs::path& package_dir) @@ -85,10 +47,10 @@ namespace vcpkg const fs::path debug_include_dir = package_dir / "debug" / "include"; std::vector files_found; - recursive_find_matching_paths_in_dir(debug_include_dir, [&](const fs::path& current) - { - return !fs::is_directory(current) && current.extension() != ".ifc"; - }, &files_found); + Files::recursive_find_matching_paths_in_dir(debug_include_dir, [&](const fs::path& current) + { + return !fs::is_directory(current) && current.extension() != ".ifc"; + }, &files_found); if (!files_found.empty()) { @@ -129,10 +91,10 @@ namespace vcpkg static lint_status check_for_misplaced_cmake_files(const fs::path& package_dir, const package_spec& spec) { std::vector misplaced_cmake_files; - recursive_find_files_with_extension_in_dir(package_dir / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(package_dir / "debug" / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(package_dir / "lib" / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(package_dir / "debug" / "lib" / "cmake", ".cmake", &misplaced_cmake_files); + Files::recursive_find_files_with_extension_in_dir(package_dir / "cmake", ".cmake", &misplaced_cmake_files); + Files::recursive_find_files_with_extension_in_dir(package_dir / "debug" / "cmake", ".cmake", &misplaced_cmake_files); + Files::recursive_find_files_with_extension_in_dir(package_dir / "lib" / "cmake", ".cmake", &misplaced_cmake_files); + Files::recursive_find_files_with_extension_in_dir(package_dir / "debug" / "lib" / "cmake", ".cmake", &misplaced_cmake_files); if (!misplaced_cmake_files.empty()) { @@ -159,8 +121,8 @@ namespace vcpkg static lint_status check_for_dlls_in_lib_dirs(const fs::path& package_dir) { std::vector dlls; - recursive_find_files_with_extension_in_dir(package_dir / "lib", ".dll", &dlls); - recursive_find_files_with_extension_in_dir(package_dir / "debug" / "lib", ".dll", &dlls); + Files::recursive_find_files_with_extension_in_dir(package_dir / "lib", ".dll", &dlls); + Files::recursive_find_files_with_extension_in_dir(package_dir / "debug" / "lib", ".dll", &dlls); if (!dlls.empty()) { @@ -223,8 +185,8 @@ namespace vcpkg static lint_status check_for_exes(const fs::path& package_dir) { std::vector exes; - recursive_find_files_with_extension_in_dir(package_dir / "bin", ".exe", &exes); - recursive_find_files_with_extension_in_dir(package_dir / "debug" / "bin", ".exe", &exes); + Files::recursive_find_files_with_extension_in_dir(package_dir / "bin", ".exe", &exes); + Files::recursive_find_files_with_extension_in_dir(package_dir / "debug" / "bin", ".exe", &exes); if (!exes.empty()) { @@ -434,10 +396,10 @@ namespace vcpkg static lint_status check_no_subdirectories(const fs::path& dir) { - const std::vector subdirectories = recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) - { - return fs::is_directory(current); - }); + const std::vector subdirectories = Files::recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) + { + return fs::is_directory(current); + }); if (!subdirectories.empty()) { @@ -483,10 +445,10 @@ namespace vcpkg static lint_status check_no_empty_folders(const fs::path& dir) { - const std::vector empty_directories = recursive_find_matching_paths_in_dir(dir, [](const fs::path& current) - { - return fs::is_directory(current) && fs::is_empty(current); - }); + const std::vector empty_directories = Files::recursive_find_matching_paths_in_dir(dir, [](const fs::path& current) + { + return fs::is_directory(current) && fs::is_empty(current); + }); if (!empty_directories.empty()) { @@ -599,17 +561,17 @@ namespace vcpkg { std::vector misplaced_files; - non_recursive_find_matching_paths_in_dir(package_dir, [](const fs::path& current) - { - const std::string filename = current.filename().generic_string(); - return !fs::is_directory(current) && !((_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)); - }, &misplaced_files); + Files::non_recursive_find_matching_paths_in_dir(package_dir, [](const fs::path& current) + { + const std::string filename = current.filename().generic_string(); + return !fs::is_directory(current) && !((_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)); + }, &misplaced_files); const fs::path debug_dir = package_dir / "debug"; - non_recursive_find_matching_paths_in_dir(debug_dir, [](const fs::path& current) - { - return !fs::is_directory(current); - }, &misplaced_files); + Files::non_recursive_find_matching_paths_in_dir(debug_dir, [](const fs::path& current) + { + return !fs::is_directory(current); + }, &misplaced_files); if (!misplaced_files.empty()) { @@ -645,14 +607,13 @@ namespace vcpkg error_count += check_for_copyright_file(spec, paths); error_count += check_for_exes(package_dir); - const fs::path debug_lib_dir = package_dir / "debug" / "lib"; const fs::path release_lib_dir = package_dir / "lib"; const fs::path debug_bin_dir = package_dir / "debug" / "bin"; const fs::path release_bin_dir = package_dir / "bin"; - const std::vector debug_libs = recursive_find_files_with_extension_in_dir(debug_lib_dir, ".lib"); - const std::vector release_libs = recursive_find_files_with_extension_in_dir(release_lib_dir, ".lib"); + const std::vector debug_libs = Files::recursive_find_files_with_extension_in_dir(debug_lib_dir, ".lib"); + const std::vector release_libs = Files::recursive_find_files_with_extension_in_dir(release_lib_dir, ".lib"); error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); @@ -666,8 +627,8 @@ namespace vcpkg { case LinkageType::DYNAMIC: { - const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(debug_bin_dir, ".dll"); - const std::vector release_dlls = recursive_find_files_with_extension_in_dir(release_bin_dir, ".dll"); + const std::vector debug_dlls = Files::recursive_find_files_with_extension_in_dir(debug_bin_dir, ".dll"); + const std::vector release_dlls = Files::recursive_find_files_with_extension_in_dir(release_bin_dir, ".dll"); error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); @@ -688,7 +649,7 @@ namespace vcpkg case LinkageType::STATIC: { std::vector dlls; - recursive_find_files_with_extension_in_dir(package_dir, ".dll", &dlls); + Files::recursive_find_files_with_extension_in_dir(package_dir, ".dll", &dlls); error_count += check_no_dlls_present(dlls); error_count += check_bin_folders_are_not_present_in_static_build(package_dir); diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 611aa7450..42e815cc2 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -58,4 +58,19 @@ namespace vcpkg {namespace Files return current_dir; } + + void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector* output) + { + recursive_find_matching_paths_in_dir(dir, [&extension](const fs::path& current) + { + return !fs::is_directory(current) && current.extension() == extension; + }, output); + } + + std::vector recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension) + { + std::vector v; + recursive_find_files_with_extension_in_dir(dir, extension, &v); + return v; + } }} -- cgit v1.2.3 From 74f69ade187dbe091cb00ace4d40ef9d20a3e416 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 17:17:45 -0800 Subject: Introduce PostBuildLint namespace --- toolsrc/src/BuildInfo.cpp | 4 ++-- toolsrc/src/commands_installation.cpp | 4 ++-- toolsrc/src/post_build_lint.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 44c7fdcf0..d96df8e8c 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -2,7 +2,7 @@ #include "vcpkg_Checks.h" #include "vcpkglib_helpers.h" -namespace vcpkg +namespace vcpkg { namespace PostBuildLint { const ConfigurationType& BuildType::config() const { @@ -161,4 +161,4 @@ namespace vcpkg { return this->m_dll_name; } -} +}} diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index f7af2ef7c..93335220d 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -59,7 +59,7 @@ namespace vcpkg exit(EXIT_FAILURE); } - perform_all_checks(spec, paths); + PostBuildLint::perform_all_checks(spec, paths); create_binary_control_file(paths, source_paragraph, target_triplet); @@ -140,7 +140,7 @@ namespace vcpkg const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_CHECKS_ONLY}); if (options.find(OPTION_CHECKS_ONLY) != options.end()) { - perform_all_checks(spec, paths); + PostBuildLint::perform_all_checks(spec, paths); exit(EXIT_SUCCESS); } diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index b93844f03..3ef906353 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -10,7 +10,7 @@ namespace fs = std::tr2::sys; -namespace vcpkg +namespace vcpkg { namespace PostBuildLint { enum class lint_status { @@ -668,8 +668,8 @@ namespace vcpkg Checks::unreachable(); } #if 0 - error_count += check_no_subdirectories(package_dir / "lib"); - error_count += check_no_subdirectories(package_dir / "debug" / "lib"); + error_count += check_no_subdirectories(package_dir / "lib"); + error_count += check_no_subdirectories(package_dir / "debug" / "lib"); #endif error_count += check_no_empty_folders(package_dir); @@ -684,4 +684,4 @@ namespace vcpkg System::println("-- Performing post-build validation done"); } -} +}} -- cgit v1.2.3 From 0b996a002ec6d90d8a132e7603553b60b332c9fe Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 18:08:00 -0800 Subject: [Files] Add functions to get all files of a dir recursively or non-recursively --- toolsrc/src/vcpkg_Files.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 42e815cc2..bb34915d7 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -73,4 +73,34 @@ namespace vcpkg {namespace Files recursive_find_files_with_extension_in_dir(dir, extension, &v); return v; } + + void recursive_find_all_files_in_dir(const fs::path& dir, std::vector* output) + { + recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) + { + return !fs::is_directory(current); + }, output); + } + + std::vector recursive_find_all_files_in_dir(const fs::path& dir) + { + std::vector v; + recursive_find_all_files_in_dir(dir, &v); + return v; + } + + void non_recursive_find_all_files_in_dir(const fs::path& dir, std::vector* output) + { + non_recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) + { + return !fs::is_directory(current); + }, output); + } + + std::vector non_recursive_find_all_files_in_dir(const fs::path& dir) + { + std::vector v; + non_recursive_find_all_files_in_dir(dir, &v); + return v; + } }} -- cgit v1.2.3 From 35152bb4fddc63f6166611a6a01fe7429e955743 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 18:08:53 -0800 Subject: Use new Files functions --- toolsrc/src/post_build_lint.cpp | 5 +---- toolsrc/src/vcpkg_Files.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 3ef906353..61fbba52a 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -568,10 +568,7 @@ namespace vcpkg { namespace PostBuildLint }, &misplaced_files); const fs::path debug_dir = package_dir / "debug"; - Files::non_recursive_find_matching_paths_in_dir(debug_dir, [](const fs::path& current) - { - return !fs::is_directory(current); - }, &misplaced_files); + Files::non_recursive_find_all_files_in_dir(debug_dir, &misplaced_files); if (!misplaced_files.empty()) { diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index bb34915d7..86e7080e4 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -77,9 +77,9 @@ namespace vcpkg {namespace Files void recursive_find_all_files_in_dir(const fs::path& dir, std::vector* output) { recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) - { - return !fs::is_directory(current); - }, output); + { + return !fs::is_directory(current); + }, output); } std::vector recursive_find_all_files_in_dir(const fs::path& dir) @@ -92,9 +92,9 @@ namespace vcpkg {namespace Files void non_recursive_find_all_files_in_dir(const fs::path& dir, std::vector* output) { non_recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) - { - return !fs::is_directory(current); - }, output); + { + return !fs::is_directory(current); + }, output); } std::vector non_recursive_find_all_files_in_dir(const fs::path& dir) -- cgit v1.2.3 From 0042316c4b57cf91ded8e474a8dda354340e7381 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 18:08:53 -0800 Subject: Introduce filesystem_fs.h --- toolsrc/src/commands_hash.cpp | 2 -- toolsrc/src/commands_search.cpp | 2 -- toolsrc/src/metrics.cpp | 4 +--- toolsrc/src/post_build_lint.cpp | 3 --- toolsrc/src/vcpkg.cpp | 1 - toolsrc/src/vcpkg_Files.cpp | 3 --- toolsrc/src/vcpkg_System.cpp | 2 -- toolsrc/src/vcpkg_metrics_uploader.cpp | 2 -- toolsrc/src/vcpkg_paths.cpp | 1 - 9 files changed, 1 insertion(+), 19 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 4b89f2894..17c191b78 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,8 +1,6 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -namespace fs = std::tr2::sys; - namespace vcpkg { static void do_file_hash(fs::path const& path, std::wstring const& hashType) diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 923368252..a604c5383 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -4,8 +4,6 @@ #include "vcpkglib_helpers.h" #include "SourceParagraph.h" -namespace fs = std::tr2::sys; - namespace vcpkg { static std::vector read_all_source_paragraphs(const vcpkg_paths& paths) diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index ada065fd6..23962bcfe 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -10,12 +10,10 @@ #include #include #include -#include +#include "filesystem_fs.h" #include "vcpkg_Strings.h" #include "vcpkg_System.h" -namespace fs = std::tr2::sys; - namespace vcpkg { static std::string GetCurrentDateTime() diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 61fbba52a..1a09c99b7 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -1,4 +1,3 @@ -#include #include "vcpkg_paths.h" #include "package_spec.h" #include "vcpkg_Files.h" @@ -8,8 +7,6 @@ #include "BuildInfo.h" #include -namespace fs = std::tr2::sys; - namespace vcpkg { namespace PostBuildLint { enum class lint_status diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index b1fe76982..4b65ea972 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include "vcpkg_Files.h" diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 86e7080e4..b86edb4ab 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -1,10 +1,7 @@ #include "vcpkg_Files.h" #include -#include #include -namespace fs = std::tr2::sys; - namespace vcpkg {namespace Files { static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index cc7080069..cb3eb6584 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -3,8 +3,6 @@ #include #include -namespace fs = std::tr2::sys; - namespace vcpkg {namespace System { fs::path get_exe_path_of_current_process() diff --git a/toolsrc/src/vcpkg_metrics_uploader.cpp b/toolsrc/src/vcpkg_metrics_uploader.cpp index f1f4a52ed..63668d1d7 100644 --- a/toolsrc/src/vcpkg_metrics_uploader.cpp +++ b/toolsrc/src/vcpkg_metrics_uploader.cpp @@ -1,10 +1,8 @@ #include "metrics.h" -#include #include "vcpkg_Checks.h" #include "vcpkg_Files.h" #include -namespace fs = std::tr2::sys; using namespace vcpkg; int WINAPI diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 5347b79d8..b7e716307 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -1,4 +1,3 @@ -#include #include "expected.h" #include "vcpkg_paths.h" #include "metrics.h" -- cgit v1.2.3 From 5b6baf0ce065c1aa0e176ca2730226e0e6beae18 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 30 Nov 2016 14:06:49 -0800 Subject: Rename function --- toolsrc/src/post_build_lint.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 1a09c99b7..5287ae359 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -17,7 +17,7 @@ namespace vcpkg { namespace PostBuildLint static const fs::path DUMPBIN_EXE = R"(%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe)"; - static void print_vector_of_files(const std::vector& paths) + static void print_paths(const std::vector& paths) { System::println(""); for (const fs::path& p : paths) @@ -96,7 +96,7 @@ namespace vcpkg { namespace 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()); - print_vector_of_files(misplaced_cmake_files); + print_paths(misplaced_cmake_files); return lint_status::ERROR_DETECTED; } @@ -124,7 +124,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls.empty()) { System::println(System::color::warning, "\nThe following dlls were found in /lib and /debug/lib. Please move them to /bin or /debug/bin, respectively."); - print_vector_of_files(dlls); + print_paths(dlls); return lint_status::ERROR_DETECTED; } @@ -172,7 +172,7 @@ namespace vcpkg { namespace PostBuildLint if (potential_copyright_files.size() > 1) { System::println(System::color::warning, "The following files are potential copyright files:"); - print_vector_of_files(potential_copyright_files); + print_paths(potential_copyright_files); } System::println(" %s/share/%s/copyright", packages_dir.generic_string(), spec.name()); @@ -188,7 +188,7 @@ namespace vcpkg { namespace PostBuildLint if (!exes.empty()) { System::println(System::color::warning, "The following EXEs were found in /bin and /debug/bin. EXEs are not valid distribution targets."); - print_vector_of_files(exes); + print_paths(exes); return lint_status::ERROR_DETECTED; } @@ -213,7 +213,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls_with_no_exports.empty()) { System::println(System::color::warning, "The following DLLs have no exports:"); - print_vector_of_files(dlls_with_no_exports); + print_paths(dlls_with_no_exports); System::println(System::color::warning, "DLLs without any exports are likely a bug in the build script."); return lint_status::ERROR_DETECTED; } @@ -244,7 +244,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls_with_improper_uwp_bit.empty()) { System::println(System::color::warning, "The following DLLs do not have the App Container bit set:"); - print_vector_of_files(dlls_with_improper_uwp_bit); + print_paths(dlls_with_improper_uwp_bit); System::println(System::color::warning, "This bit is required for Windows Store apps."); return lint_status::ERROR_DETECTED; } @@ -346,7 +346,7 @@ namespace vcpkg { namespace PostBuildLint } System::println(System::color::warning, "DLLs should not be present in a static build, but the following DLLs were found:"); - print_vector_of_files(dlls); + print_paths(dlls); return lint_status::ERROR_DETECTED; } @@ -361,10 +361,10 @@ namespace vcpkg { namespace PostBuildLint 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"); - print_vector_of_files(debug_binaries); + print_paths(debug_binaries); System::println("Release binaries"); - print_vector_of_files(release_binaries); + print_paths(release_binaries); if (debug_count == 0) { @@ -402,7 +402,7 @@ namespace vcpkg { namespace PostBuildLint { System::println(System::color::warning, "Directory %s should have no subdirectories", dir.generic_string()); System::println("The following subdirectories were found: "); - print_vector_of_files(subdirectories); + print_paths(subdirectories); return lint_status::ERROR_DETECTED; } @@ -451,7 +451,7 @@ namespace vcpkg { namespace PostBuildLint { System::println(System::color::warning, "There should be no empty directories in %s", dir.generic_string()); System::println("The following empty directories were found: "); - print_vector_of_files(empty_directories); + 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" @@ -570,7 +570,7 @@ namespace vcpkg { namespace PostBuildLint if (!misplaced_files.empty()) { System::println(System::color::warning, "The following files are placed in\n%s and\n%s: ", package_dir.generic_string(), debug_dir.generic_string()); - print_vector_of_files(misplaced_files); + print_paths(misplaced_files); System::println(System::color::warning, "Files cannot be present in those directories.\n"); return lint_status::ERROR_DETECTED; } -- cgit v1.2.3 From ae379fedea589552ad7c98eb350c492ce830fb48 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 30 Nov 2016 14:08:43 -0800 Subject: Move print_paths() to Files:: --- toolsrc/src/post_build_lint.cpp | 34 ++++++++++++---------------------- toolsrc/src/vcpkg_Files.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 5287ae359..3043bd4fa 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -17,16 +17,6 @@ namespace vcpkg { namespace PostBuildLint static const fs::path DUMPBIN_EXE = R"(%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe)"; - static void print_paths(const std::vector& paths) - { - System::println(""); - for (const fs::path& p : paths) - { - System::println(" %s", p.generic_string()); - } - System::println(""); - } - static lint_status check_for_files_in_include_directory(const fs::path& package_dir) { const fs::path include_dir = package_dir / "include"; @@ -96,7 +86,7 @@ namespace vcpkg { namespace 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()); - print_paths(misplaced_cmake_files); + Files::print_paths(misplaced_cmake_files); return lint_status::ERROR_DETECTED; } @@ -124,7 +114,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls.empty()) { System::println(System::color::warning, "\nThe following dlls were found in /lib and /debug/lib. Please move them to /bin or /debug/bin, respectively."); - print_paths(dlls); + Files::print_paths(dlls); return lint_status::ERROR_DETECTED; } @@ -172,7 +162,7 @@ namespace vcpkg { namespace PostBuildLint if (potential_copyright_files.size() > 1) { System::println(System::color::warning, "The following files are potential copyright files:"); - print_paths(potential_copyright_files); + Files::print_paths(potential_copyright_files); } System::println(" %s/share/%s/copyright", packages_dir.generic_string(), spec.name()); @@ -188,7 +178,7 @@ namespace vcpkg { namespace PostBuildLint if (!exes.empty()) { System::println(System::color::warning, "The following EXEs were found in /bin and /debug/bin. EXEs are not valid distribution targets."); - print_paths(exes); + Files::print_paths(exes); return lint_status::ERROR_DETECTED; } @@ -213,7 +203,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls_with_no_exports.empty()) { System::println(System::color::warning, "The following DLLs have no exports:"); - print_paths(dlls_with_no_exports); + Files::print_paths(dlls_with_no_exports); System::println(System::color::warning, "DLLs without any exports are likely a bug in the build script."); return lint_status::ERROR_DETECTED; } @@ -244,7 +234,7 @@ namespace vcpkg { namespace PostBuildLint if (!dlls_with_improper_uwp_bit.empty()) { System::println(System::color::warning, "The following DLLs do not have the App Container bit set:"); - print_paths(dlls_with_improper_uwp_bit); + Files::print_paths(dlls_with_improper_uwp_bit); System::println(System::color::warning, "This bit is required for Windows Store apps."); return lint_status::ERROR_DETECTED; } @@ -346,7 +336,7 @@ namespace vcpkg { namespace PostBuildLint } System::println(System::color::warning, "DLLs should not be present in a static build, but the following DLLs were found:"); - print_paths(dlls); + Files::print_paths(dlls); return lint_status::ERROR_DETECTED; } @@ -361,10 +351,10 @@ namespace vcpkg { namespace PostBuildLint 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"); - print_paths(debug_binaries); + Files::print_paths(debug_binaries); System::println("Release binaries"); - print_paths(release_binaries); + Files::print_paths(release_binaries); if (debug_count == 0) { @@ -402,7 +392,7 @@ namespace vcpkg { namespace PostBuildLint { System::println(System::color::warning, "Directory %s should have no subdirectories", dir.generic_string()); System::println("The following subdirectories were found: "); - print_paths(subdirectories); + Files::print_paths(subdirectories); return lint_status::ERROR_DETECTED; } @@ -451,7 +441,7 @@ namespace vcpkg { namespace PostBuildLint { System::println(System::color::warning, "There should be no empty directories in %s", dir.generic_string()); System::println("The following empty directories were found: "); - print_paths(empty_directories); + 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" @@ -570,7 +560,7 @@ namespace vcpkg { namespace PostBuildLint if (!misplaced_files.empty()) { System::println(System::color::warning, "The following files are placed in\n%s and\n%s: ", package_dir.generic_string(), debug_dir.generic_string()); - print_paths(misplaced_files); + Files::print_paths(misplaced_files); System::println(System::color::warning, "Files cannot be present in those directories.\n"); return lint_status::ERROR_DETECTED; } diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index b86edb4ab..698579736 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -1,6 +1,7 @@ #include "vcpkg_Files.h" #include #include +#include "vcpkg_System.h" namespace vcpkg {namespace Files { @@ -100,4 +101,14 @@ namespace vcpkg {namespace Files non_recursive_find_all_files_in_dir(dir, &v); return v; } + + void print_paths(const std::vector& paths) + { + System::println(""); + for (const fs::path& p : paths) + { + System::println(" %s", p.generic_string()); + } + System::println(""); + } }} -- cgit v1.2.3 From 223e7f970d30d3d97e64af3d1970d52cc0ddaaf5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 30 Nov 2016 14:16:37 -0800 Subject: Use check_exit() instead of check_throw() --- toolsrc/src/BuildInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index d96df8e8c..ddd44a1e6 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -127,7 +127,7 @@ namespace vcpkg { namespace PostBuildLint BuildInfo read_build_info(const fs::path& filepath) { const std::vector> pghs = Paragraphs::get_paragraphs(filepath); - Checks::check_throw(pghs.size() == 1, "Invalid BUILD_INFO file for package"); + Checks::check_exit(pghs.size() == 1, "Invalid BUILD_INFO file for package"); return BuildInfo::create(pghs[0]); } -- cgit v1.2.3 From 1f758b19a5250ae16e10ba21700976ba53197516 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 30 Nov 2016 13:26:28 -0800 Subject: [install-command] Verify files will not overwrite existing files --- toolsrc/src/vcpkg.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 4b65ea972..c198365e1 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -12,19 +12,13 @@ #include "vcpkg_System.h" #include "Paragraphs.h" #include +#include +#include "vcpkg_Maps.h" using namespace vcpkg; bool vcpkg::g_do_dry_run = false; -namespace -{ - std::fstream open_status_file(const vcpkg_paths& paths, std::ios_base::openmode mode = std::ios_base::app | std::ios_base::in | std::ios_base::out | std::ios_base::binary) - { - return std::fstream(paths.vcpkg_dir_status_file, mode); - } -} - static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) { if (!fs::exists(vcpkg_dir_status_file)) @@ -189,8 +183,56 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar listfile.close(); } +static std::map remove_first_n_chars_and_map(const std::vector absolute_paths, const size_t n) +{ + std::map output; + + for (const fs::path& absolute_path : absolute_paths) + { + std::string suffix = absolute_path.generic_string(); + suffix.erase(0, n); + output.emplace(suffix, absolute_path); + } + + return output; +} + +static void print_map_values(const std::vector keys, const std::map& map) +{ + System::println(""); + for (const std::string& key : keys) + { + System::println(" %s", map.at(key).generic_string()); + } + System::println(""); +} + void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) { + const fs::path package_dir = paths.package_dir(binary_paragraph.spec); + const std::vector package_files = Files::recursive_find_all_files_in_dir(package_dir); + + const fs::path installed_dir = paths.installed / binary_paragraph.spec.target_triplet().canonical_name(); + const std::vector installed_files = Files::recursive_find_all_files_in_dir(installed_dir); + + const std::map package_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(package_files, package_dir.generic_string().size() + 1); + const std::map installed_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(installed_files, installed_dir.generic_string().size() + 1); + + const std::vector package_files_set = Maps::extract_keys(package_files_relative_paths_to_absolute_paths); + const std::vector installed_files_set = Maps::extract_keys(installed_files_relative_paths_to_absolute_paths); + + std::vector intersection; + std::set_intersection(package_files_set.cbegin(), package_files_set.cend(), + installed_files_set.cbegin(), installed_files_set.cend(), + std::back_inserter(intersection)); + + if (!intersection.empty()) + { + System::println(System::color::error, "The following files are already installed and are in conflict with %s:", binary_paragraph.spec); + print_map_values(intersection, installed_files_relative_paths_to_absolute_paths); + exit(EXIT_FAILURE); + } + StatusParagraph spgh; spgh.package = binary_paragraph; spgh.want = want_t::install; -- cgit v1.2.3 From 89aaf195fbdfa63708fd6ac90103cac0cdedf3c6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 01:37:41 -0800 Subject: Remove unused variable --- toolsrc/src/vcpkg.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index c198365e1..6c34497b2 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -17,8 +17,6 @@ using namespace vcpkg; -bool vcpkg::g_do_dry_run = false; - static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_file, const fs::path& vcpkg_dir_status_file_old) { if (!fs::exists(vcpkg_dir_status_file)) -- cgit v1.2.3 From 6eac44c9640a50fbde88535df6261a1a3f234350 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 01:49:24 -0800 Subject: Move install_package() and deinstall_package() to the files of the appropriate commands --- toolsrc/src/commands_installation.cpp | 132 ++++++++++++++++ toolsrc/src/commands_remove.cpp | 145 ++++++++++++++++++ toolsrc/src/vcpkg.cpp | 278 +--------------------------------- 3 files changed, 278 insertions(+), 277 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 93335220d..23342070d 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -67,6 +67,138 @@ namespace vcpkg // delete_directory(port_buildtrees_dir); } + static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) + { + std::fstream listfile(paths.listfile_path(bpgh), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + + auto package_prefix_path = paths.package_dir(bpgh.spec); + auto prefix_length = package_prefix_path.native().size(); + + const triplet& target_triplet = bpgh.spec.target_triplet(); + const std::string& target_triplet_as_string = target_triplet.canonical_name(); + std::error_code ec; + fs::create_directory(paths.installed / target_triplet_as_string, ec); + listfile << target_triplet << "\n"; + + for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) + { + const std::string filename = it->path().filename().generic_string(); + if (fs::is_regular_file(it->status()) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)) + { + // Do not copy the control file + continue; + } + + auto suffix = it->path().generic_u8string().substr(prefix_length + 1); + auto target = paths.installed / target_triplet_as_string / suffix; + + auto status = it->status(ec); + if (ec) + { + System::println(System::color::error, "failed: %s: %s", it->path().u8string(), ec.message()); + continue; + } + if (fs::is_directory(status)) + { + fs::create_directory(target, ec); + if (ec) + { + System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); + } + + listfile << target_triplet << "/" << suffix << "\n"; + } + else if (fs::is_regular_file(status)) + { + fs::copy_file(*it, target, ec); + if (ec) + { + System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); + } + listfile << target_triplet << "/" << suffix << "\n"; + } + else if (!fs::status_known(status)) + { + System::println(System::color::error, "failed: %s: unknown status", it->path().u8string()); + } + else + System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); + } + + listfile.close(); + } + + static std::map remove_first_n_chars_and_map(const std::vector absolute_paths, const size_t n) + { + std::map output; + + for (const fs::path& absolute_path : absolute_paths) + { + std::string suffix = absolute_path.generic_string(); + suffix.erase(0, n); + output.emplace(suffix, absolute_path); + } + + return output; + } + + static void print_map_values(const std::vector keys, const std::map& map) + { + System::println(""); + for (const std::string& key : keys) + { + System::println(" %s", map.at(key).generic_string()); + } + System::println(""); + } + + static void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) + { + const fs::path package_dir = paths.package_dir(binary_paragraph.spec); + const std::vector package_files = Files::recursive_find_all_files_in_dir(package_dir); + + const fs::path installed_dir = paths.installed / binary_paragraph.spec.target_triplet().canonical_name(); + const std::vector installed_files = Files::recursive_find_all_files_in_dir(installed_dir); + + const std::map package_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(package_files, package_dir.generic_string().size() + 1); + const std::map installed_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(installed_files, installed_dir.generic_string().size() + 1); + + const std::vector package_files_set = Maps::extract_keys(package_files_relative_paths_to_absolute_paths); + const std::vector installed_files_set = Maps::extract_keys(installed_files_relative_paths_to_absolute_paths); + + std::vector intersection; + std::set_intersection(package_files_set.cbegin(), package_files_set.cend(), + installed_files_set.cbegin(), installed_files_set.cend(), + std::back_inserter(intersection)); + + if (!intersection.empty()) + { + System::println(System::color::error, "The following files are already installed and are in conflict with %s:", binary_paragraph.spec); + print_map_values(intersection, installed_files_relative_paths_to_absolute_paths); + exit(EXIT_FAILURE); + } + + StatusParagraph spgh; + spgh.package = binary_paragraph; + spgh.want = want_t::install; + spgh.state = install_state_t::half_installed; + for (auto&& dep : spgh.package.depends) + { + if (status_db.find_installed(dep, spgh.package.spec.target_triplet()) == status_db.end()) + { + Checks::unreachable(); + } + } + write_update(paths, spgh); + status_db.insert(std::make_unique(spgh)); + + install_and_write_listfile(paths, spgh.package); + + spgh.state = install_state_t::installed; + write_update(paths, spgh); + status_db.insert(std::make_unique(spgh)); + } + void install_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { static const std::string example = create_example_string("install zlib zlib:x64-windows curl boost"); diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 5bb9ecc96..31331fc2f 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -2,6 +2,7 @@ #include "vcpkg.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" +#include namespace vcpkg { @@ -21,6 +22,150 @@ namespace vcpkg } } + enum class deinstall_plan + { + not_installed, + dependencies_not_satisfied, + should_deinstall + }; + + static deinstall_plan deinstall_package_plan( + const StatusParagraphs::iterator package_it, + const StatusParagraphs& status_db, + std::vector& dependencies_out) + { + dependencies_out.clear(); + + if (package_it == status_db.end() || (*package_it)->state == install_state_t::not_installed) + { + return deinstall_plan::not_installed; + } + + auto& pkg = (*package_it)->package; + + for (auto&& inst_pkg : status_db) + { + if (inst_pkg->want != want_t::install) + continue; + if (inst_pkg->package.spec.target_triplet() != pkg.spec.target_triplet()) + continue; + + const auto& deps = inst_pkg->package.depends; + + if (std::find(deps.begin(), deps.end(), pkg.spec.name()) != deps.end()) + { + dependencies_out.push_back(inst_pkg.get()); + } + } + + if (!dependencies_out.empty()) + return deinstall_plan::dependencies_not_satisfied; + + return deinstall_plan::should_deinstall; + } + + static void deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db) + { + auto package_it = status_db.find(spec.name(), spec.target_triplet()); + if (package_it == status_db.end()) + { + System::println(System::color::success, "Package %s is not installed", spec); + return; + } + + auto& pkg = **package_it; + + std::vector deps; + auto plan = deinstall_package_plan(package_it, status_db, deps); + switch (plan) + { + case deinstall_plan::not_installed: + System::println(System::color::success, "Package %s is not installed", spec); + return; + case deinstall_plan::dependencies_not_satisfied: + System::println(System::color::error, "Error: Cannot remove package %s:", spec); + for (auto&& dep : deps) + { + System::println(" %s depends on %s", dep->package.displayname(), pkg.package.displayname()); + } + exit(EXIT_FAILURE); + case deinstall_plan::should_deinstall: + break; + default: + Checks::unreachable(); + } + + pkg.want = want_t::purge; + pkg.state = install_state_t::half_installed; + write_update(paths, pkg); + + std::fstream listfile(paths.listfile_path(pkg.package), std::ios_base::in | std::ios_base::binary); + if (listfile) + { + std::vector dirs_touched; + std::string suffix; + while (std::getline(listfile, suffix)) + { + if (!suffix.empty() && suffix.back() == '\r') + suffix.pop_back(); + + std::error_code ec; + + auto target = paths.installed / suffix; + + auto status = fs::status(target, ec); + if (ec) + { + System::println(System::color::error, "failed: %s", ec.message()); + continue; + } + + if (fs::is_directory(status)) + { + dirs_touched.push_back(target); + } + else if (fs::is_regular_file(status)) + { + fs::remove(target, ec); + if (ec) + { + System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); + } + } + else if (!fs::status_known(status)) + { + System::println(System::color::warning, "Warning: unknown status: %s", target.u8string()); + } + else + { + System::println(System::color::warning, "Warning: %s: cannot handle file type", target.u8string()); + } + } + + auto b = dirs_touched.rbegin(); + auto e = dirs_touched.rend(); + for (; b != e; ++b) + { + if (fs::directory_iterator(*b) == fs::directory_iterator()) + { + std::error_code ec; + fs::remove(*b, ec); + if (ec) + { + System::println(System::color::error, "failed: %s", ec.message()); + } + } + } + + listfile.close(); + fs::remove(paths.listfile_path(pkg.package)); + } + + pkg.state = install_state_t::not_installed; + write_update(paths, pkg); + System::println(System::color::success, "Package %s was successfully removed", pkg.package.displayname()); + } + void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { static const std::string example = create_example_string("remove zlib zlib:x64-windows curl boost"); diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6c34497b2..f8ebc7de4 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -108,7 +108,7 @@ static std::string get_fullpkgname_from_listfile(const fs::path& path) return ret; } -static void write_update(const vcpkg_paths& paths, const StatusParagraph& p) +void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) { static int update_id = 0; auto my_update_id = update_id++; @@ -120,282 +120,6 @@ static void write_update(const vcpkg_paths& paths, const StatusParagraph& p) fs::rename(tmp_update_filename, update_filename); } -static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) -{ - std::fstream listfile(paths.listfile_path(bpgh), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); - - auto package_prefix_path = paths.package_dir(bpgh.spec); - auto prefix_length = package_prefix_path.native().size(); - - const triplet& target_triplet = bpgh.spec.target_triplet(); - const std::string& target_triplet_as_string = target_triplet.canonical_name(); - std::error_code ec; - fs::create_directory(paths.installed / target_triplet_as_string, ec); - listfile << target_triplet << "\n"; - - for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) - { - const std::string filename = it->path().filename().generic_string(); - if (fs::is_regular_file(it->status()) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0)) - { - // Do not copy the control file - continue; - } - - auto suffix = it->path().generic_u8string().substr(prefix_length + 1); - auto target = paths.installed / target_triplet_as_string / suffix; - - auto status = it->status(ec); - if (ec) - { - System::println(System::color::error, "failed: %s: %s", it->path().u8string(), ec.message()); - continue; - } - if (fs::is_directory(status)) - { - fs::create_directory(target, ec); - if (ec) - { - System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); - } - - listfile << target_triplet << "/" << suffix << "\n"; - } - else if (fs::is_regular_file(status)) - { - fs::copy_file(*it, target, ec); - if (ec) - { - System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); - } - listfile << target_triplet << "/" << suffix << "\n"; - } - else if (!fs::status_known(status)) - { - System::println(System::color::error, "failed: %s: unknown status", it->path().u8string()); - } - else - System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); - } - - listfile.close(); -} - -static std::map remove_first_n_chars_and_map(const std::vector absolute_paths, const size_t n) -{ - std::map output; - - for (const fs::path& absolute_path : absolute_paths) - { - std::string suffix = absolute_path.generic_string(); - suffix.erase(0, n); - output.emplace(suffix, absolute_path); - } - - return output; -} - -static void print_map_values(const std::vector keys, const std::map& map) -{ - System::println(""); - for (const std::string& key : keys) - { - System::println(" %s", map.at(key).generic_string()); - } - System::println(""); -} - -void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) -{ - const fs::path package_dir = paths.package_dir(binary_paragraph.spec); - const std::vector package_files = Files::recursive_find_all_files_in_dir(package_dir); - - const fs::path installed_dir = paths.installed / binary_paragraph.spec.target_triplet().canonical_name(); - const std::vector installed_files = Files::recursive_find_all_files_in_dir(installed_dir); - - const std::map package_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(package_files, package_dir.generic_string().size() + 1); - const std::map installed_files_relative_paths_to_absolute_paths = remove_first_n_chars_and_map(installed_files, installed_dir.generic_string().size() + 1); - - const std::vector package_files_set = Maps::extract_keys(package_files_relative_paths_to_absolute_paths); - const std::vector installed_files_set = Maps::extract_keys(installed_files_relative_paths_to_absolute_paths); - - std::vector intersection; - std::set_intersection(package_files_set.cbegin(), package_files_set.cend(), - installed_files_set.cbegin(), installed_files_set.cend(), - std::back_inserter(intersection)); - - if (!intersection.empty()) - { - System::println(System::color::error, "The following files are already installed and are in conflict with %s:", binary_paragraph.spec); - print_map_values(intersection, installed_files_relative_paths_to_absolute_paths); - exit(EXIT_FAILURE); - } - - StatusParagraph spgh; - spgh.package = binary_paragraph; - spgh.want = want_t::install; - spgh.state = install_state_t::half_installed; - for (auto&& dep : spgh.package.depends) - { - if (status_db.find_installed(dep, spgh.package.spec.target_triplet()) == status_db.end()) - { - Checks::unreachable(); - } - } - write_update(paths, spgh); - status_db.insert(std::make_unique(spgh)); - - install_and_write_listfile(paths, spgh.package); - - spgh.state = install_state_t::installed; - write_update(paths, spgh); - status_db.insert(std::make_unique(spgh)); -} - -enum class deinstall_plan -{ - not_installed, - dependencies_not_satisfied, - should_deinstall -}; - -static deinstall_plan deinstall_package_plan( - const StatusParagraphs::iterator package_it, - const StatusParagraphs& status_db, - std::vector& dependencies_out) -{ - dependencies_out.clear(); - - if (package_it == status_db.end() || (*package_it)->state == install_state_t::not_installed) - { - return deinstall_plan::not_installed; - } - - auto& pkg = (*package_it)->package; - - for (auto&& inst_pkg : status_db) - { - if (inst_pkg->want != want_t::install) - continue; - if (inst_pkg->package.spec.target_triplet() != pkg.spec.target_triplet()) - continue; - - const auto& deps = inst_pkg->package.depends; - - if (std::find(deps.begin(), deps.end(), pkg.spec.name()) != deps.end()) - { - dependencies_out.push_back(inst_pkg.get()); - } - } - - if (!dependencies_out.empty()) - return deinstall_plan::dependencies_not_satisfied; - - return deinstall_plan::should_deinstall; -} - -void vcpkg::deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db) -{ - auto package_it = status_db.find(spec.name(), spec.target_triplet()); - if (package_it == status_db.end()) - { - System::println(System::color::success, "Package %s is not installed", spec); - return; - } - - auto& pkg = **package_it; - - std::vector deps; - auto plan = deinstall_package_plan(package_it, status_db, deps); - switch (plan) - { - case deinstall_plan::not_installed: - System::println(System::color::success, "Package %s is not installed", spec); - return; - case deinstall_plan::dependencies_not_satisfied: - System::println(System::color::error, "Error: Cannot remove package %s:", spec); - for (auto&& dep : deps) - { - System::println(" %s depends on %s", dep->package.displayname(), pkg.package.displayname()); - } - exit(EXIT_FAILURE); - case deinstall_plan::should_deinstall: - break; - default: - Checks::unreachable(); - } - - pkg.want = want_t::purge; - pkg.state = install_state_t::half_installed; - write_update(paths, pkg); - - std::fstream listfile(paths.listfile_path(pkg.package), std::ios_base::in | std::ios_base::binary); - if (listfile) - { - std::vector dirs_touched; - std::string suffix; - while (std::getline(listfile, suffix)) - { - if (!suffix.empty() && suffix.back() == '\r') - suffix.pop_back(); - - std::error_code ec; - - auto target = paths.installed / suffix; - - auto status = fs::status(target, ec); - if (ec) - { - System::println(System::color::error, "failed: %s", ec.message()); - continue; - } - - if (fs::is_directory(status)) - { - dirs_touched.push_back(target); - } - else if (fs::is_regular_file(status)) - { - fs::remove(target, ec); - if (ec) - { - System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); - } - } - else if (!fs::status_known(status)) - { - System::println(System::color::warning, "Warning: unknown status: %s", target.u8string()); - } - else - { - System::println(System::color::warning, "Warning: %s: cannot handle file type", target.u8string()); - } - } - - auto b = dirs_touched.rbegin(); - auto e = dirs_touched.rend(); - for (; b != e; ++b) - { - if (fs::directory_iterator(*b) == fs::directory_iterator()) - { - std::error_code ec; - fs::remove(*b, ec); - if (ec) - { - System::println(System::color::error, "failed: %s", ec.message()); - } - } - } - - listfile.close(); - fs::remove(paths.listfile_path(pkg.package)); - } - - pkg.state = install_state_t::not_installed; - write_update(paths, pkg); - System::println(System::color::success, "Package %s was successfully removed", pkg.package.displayname()); -} - expected vcpkg::try_load_port(const fs::path& path) { try -- cgit v1.2.3 From 53598df2874436a31ea6d4f1dd112310afaa83f4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 02:02:49 -0800 Subject: Remove unused #include directives --- toolsrc/src/vcpkg.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index f8ebc7de4..05ff7340f 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -7,13 +7,9 @@ #include #include #include -#include #include "vcpkg_Files.h" -#include "vcpkg_System.h" #include "Paragraphs.h" #include -#include -#include "vcpkg_Maps.h" using namespace vcpkg; -- cgit v1.2.3 From 79399923b6cd98b9e77020615e433ef0560d5dc2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 02:03:07 -0800 Subject: Remove unused function --- toolsrc/src/vcpkg.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 05ff7340f..6c5224f56 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -97,13 +97,6 @@ StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) return current_status_db; } -static std::string get_fullpkgname_from_listfile(const fs::path& path) -{ - auto ret = path.stem().generic_u8string(); - std::replace(ret.begin(), ret.end(), '_', ':'); - return ret; -} - void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) { static int update_id = 0; -- cgit v1.2.3