From 2b8bdeb0441c9fb83fc79bf10a761d1bf11cd287 Mon Sep 17 00:00:00 2001 From: sdcb Date: Thu, 20 Oct 2016 13:03:58 +0800 Subject: Add hash file support. --- toolsrc/src/commands_hash.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ toolsrc/src/commands_other.cpp | 4 +++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 toolsrc/src/commands_hash.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp new file mode 100644 index 000000000..672e24a24 --- /dev/null +++ b/toolsrc/src/commands_hash.cpp @@ -0,0 +1,40 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" +#include "vcpkg.h" +#include +#include +#include + +namespace fs = std::tr2::sys; + +namespace vcpkg +{ + void file_hash_sha512(fs::path const & path, char const * hash) + { + auto cmd_line = Strings::format("Powershell -Command (Get-FileHash %s -Algorithm %s).Hash.ToLower()", + Strings::utf16_to_utf8(path.c_str()), + hash); + auto ec_data = System::cmd_execute_and_capture_output(Strings::utf8_to_utf16(cmd_line)); + Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line); + System::print(ec_data.output.c_str()); + } + + void hash_command(const vcpkg_cmd_arguments& args) + { + static const std::string example = Strings::format( + "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2")); + args.check_min_arg_count(1, example.c_str()); + args.check_max_arg_count(2, example.c_str()); + + if (args.command_arguments.size() == 1) + { + file_hash_sha512(args.command_arguments[0], "SHA512"); + } + if (args.command_arguments.size() == 2) + { + file_hash_sha512(args.command_arguments[0], args.command_arguments[1].c_str()); + } + + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 07549a437..53d6f2506 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -14,6 +14,7 @@ namespace vcpkg " vcpkg remove --purge Uninstall and delete a package. \n" " vcpkg list List installed packages\n" " vcpkg update Display list of packages for updating\n" + " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" "\n" "%s" // Integration help "\n" @@ -93,7 +94,8 @@ namespace vcpkg { static std::vector> t = { {"version", &version_command}, - {"contact", &contact_command} + {"contact", &contact_command}, + {"hash", &hash_command }, }; return t; } -- cgit v1.2.3 From 337c96fc067ae5908d4cf5c8a188aa37588044ac Mon Sep 17 00:00:00 2001 From: flysha Date: Fri, 21 Oct 2016 07:44:00 +0800 Subject: Switch to using CertUtil to generate hash. --- toolsrc/src/commands_hash.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 672e24a24..20e960d02 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -9,14 +9,24 @@ namespace fs = std::tr2::sys; namespace vcpkg { - void file_hash_sha512(fs::path const & path, char const * hash) + void file_hash_sha512(fs::path const & path, std::wstring const & hashType) { - auto cmd_line = Strings::format("Powershell -Command (Get-FileHash %s -Algorithm %s).Hash.ToLower()", - Strings::utf16_to_utf8(path.c_str()), - hash); - auto ec_data = System::cmd_execute_and_capture_output(Strings::utf8_to_utf16(cmd_line)); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line); - System::print(ec_data.output.c_str()); + auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", + path.c_str(), hashType.c_str()); + auto ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(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(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(end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + + auto hash = output.substr(start, end - start); + hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end()); + System::println(hash.c_str()); } void hash_command(const vcpkg_cmd_arguments& args) @@ -28,11 +38,11 @@ namespace vcpkg if (args.command_arguments.size() == 1) { - file_hash_sha512(args.command_arguments[0], "SHA512"); + file_hash_sha512(args.command_arguments[0], L"SHA512"); } if (args.command_arguments.size() == 2) { - file_hash_sha512(args.command_arguments[0], args.command_arguments[1].c_str()); + file_hash_sha512(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); } exit(EXIT_SUCCESS); -- cgit v1.2.3 From c12c3d90bee810abaec479c49d889957b52151db Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 20 Oct 2016 18:05:52 -0700 Subject: src Formatting --- toolsrc/src/commands_hash.cpp | 76 +++++++++++++++++++++--------------------- toolsrc/src/commands_other.cpp | 6 ++-- 2 files changed, 41 insertions(+), 41 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 20e960d02..07ce9d6e7 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -9,42 +9,42 @@ namespace fs = std::tr2::sys; namespace vcpkg { - void file_hash_sha512(fs::path const & path, std::wstring const & hashType) - { - auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", - path.c_str(), hashType.c_str()); - auto ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(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(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(end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); - - auto hash = output.substr(start, end - start); - hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end()); - System::println(hash.c_str()); - } - - void hash_command(const vcpkg_cmd_arguments& args) - { - static const std::string example = Strings::format( - "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2")); - args.check_min_arg_count(1, example.c_str()); - args.check_max_arg_count(2, example.c_str()); - - if (args.command_arguments.size() == 1) - { - file_hash_sha512(args.command_arguments[0], L"SHA512"); - } - if (args.command_arguments.size() == 2) - { - file_hash_sha512(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); - } - - exit(EXIT_SUCCESS); - } + void file_hash_sha512(fs::path const& path, std::wstring const& hashType) + { + auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)", + path.c_str(), hashType.c_str()); + auto ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(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(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(end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line)); + + auto hash = output.substr(start, end - start); + hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end()); + System::println(hash.c_str()); + } + + void hash_command(const vcpkg_cmd_arguments& args) + { + static const std::string example = Strings::format( + "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2")); + args.check_min_arg_count(1, example.c_str()); + args.check_max_arg_count(2, example.c_str()); + + if (args.command_arguments.size() == 1) + { + file_hash_sha512(args.command_arguments[0], L"SHA512"); + } + if (args.command_arguments.size() == 2) + { + file_hash_sha512(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); + } + + exit(EXIT_SUCCESS); + } } diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 53d6f2506..148673afe 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -14,7 +14,7 @@ namespace vcpkg " vcpkg remove --purge Uninstall and delete a package. \n" " vcpkg list List installed packages\n" " vcpkg update Display list of packages for updating\n" - " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" + " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" "\n" "%s" // Integration help "\n" @@ -94,8 +94,8 @@ namespace vcpkg { static std::vector> t = { {"version", &version_command}, - {"contact", &contact_command}, - {"hash", &hash_command }, + {"contact", &contact_command}, + {"hash", &hash_command}, }; return t; } -- cgit v1.2.3 From 251b3f03693a2001c0c4e8a5fdca2432e4a037a8 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 20 Oct 2016 18:11:50 -0700 Subject: Rename function and make it static --- toolsrc/src/commands_hash.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 07ce9d6e7..43e9456a7 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -9,7 +9,7 @@ namespace fs = std::tr2::sys; namespace vcpkg { - void file_hash_sha512(fs::path const& path, std::wstring const& hashType) + 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.c_str()); @@ -38,11 +38,11 @@ namespace vcpkg if (args.command_arguments.size() == 1) { - file_hash_sha512(args.command_arguments[0], L"SHA512"); + do_file_hash(args.command_arguments[0], L"SHA512"); } if (args.command_arguments.size() == 2) { - file_hash_sha512(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); + do_file_hash(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1])); } exit(EXIT_SUCCESS); -- cgit v1.2.3 From 1c37f9981d7f751d67d377bafc209d007a9be4b4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 20 Oct 2016 18:12:19 -0700 Subject: Remove unused include directives --- toolsrc/src/commands_hash.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 43e9456a7..4b89f2894 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,9 +1,5 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" -#include -#include -#include namespace fs = std::tr2::sys; -- cgit v1.2.3 From 7db7ea5ceb48d255ecc5d4822e45f24cb67ccf0b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sat, 22 Oct 2016 19:24:09 -0700 Subject: Use pointer instead of reference for output parameter --- toolsrc/src/post_build_lint.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index c68148fb2..33f1160f8 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -31,12 +31,12 @@ namespace vcpkg } template - void recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector& output) + 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); + std::copy_if(fs::recursive_directory_iterator(dir), fs::recursive_directory_iterator(), std::back_inserter(*output), predicate); } - void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector& output) + 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) { @@ -65,7 +65,7 @@ namespace vcpkg recursive_find_matching_paths_in_dir(debug_include_dir, [&](const fs::path& current) { return !fs::is_directory(current) && current.extension() != ".ifc"; - }, files_found); + }, &files_found); if (!files_found.empty()) { @@ -107,10 +107,10 @@ namespace vcpkg { const fs::path current_packages_dir = paths.packages / spec.dir(); std::vector misplaced_cmake_files; - recursive_find_files_with_extension_in_dir(current_packages_dir / "cmake", ".cmake", misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "cmake", ".cmake", misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "lib" / "cmake", ".cmake", misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "lib" / "cmake", ".cmake", misplaced_cmake_files); + recursive_find_files_with_extension_in_dir(current_packages_dir / "cmake", ".cmake", &misplaced_cmake_files); + recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "cmake", ".cmake", &misplaced_cmake_files); + recursive_find_files_with_extension_in_dir(current_packages_dir / "lib" / "cmake", ".cmake", &misplaced_cmake_files); + recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "lib" / "cmake", ".cmake", &misplaced_cmake_files); if (!misplaced_cmake_files.empty()) { @@ -137,8 +137,8 @@ namespace vcpkg static lint_status check_for_dlls_in_lib_dirs(const package_spec& spec, const vcpkg_paths& paths) { std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".dll", dlls); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".dll", dlls); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".dll", &dlls); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".dll", &dlls); if (!dlls.empty()) { @@ -202,8 +202,8 @@ namespace vcpkg static lint_status check_for_exes(const package_spec& spec, const vcpkg_paths& paths) { std::vector exes; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".exe", exes); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".exe", exes); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".exe", &exes); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".exe", &exes); if (!exes.empty()) { @@ -395,8 +395,8 @@ namespace vcpkg case triplet::BuildType::DYNAMIC: { std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll", dlls); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll", dlls); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll", &dlls); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll", &dlls); error_count += check_exports_of_dlls(dlls); error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls); @@ -406,7 +406,7 @@ namespace vcpkg case triplet::BuildType::STATIC: { std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir(), ".dll", dlls); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir(), ".dll", &dlls); error_count += check_no_dlls_present(dlls); break; @@ -417,8 +417,8 @@ namespace vcpkg } std::vector libs; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib", libs); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib", libs); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib", &libs); + recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib", &libs); error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); if (error_count != 0) -- cgit v1.2.3 From 4fcdf15651690673e61c30f3b3a8b393569d9144 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sat, 22 Oct 2016 20:00:59 -0700 Subject: [post-build-checks] Add check for mismatching number of debug/release binaries --- toolsrc/src/post_build_lint.cpp | 56 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 33f1160f8..532b189cd 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -43,6 +43,13 @@ namespace vcpkg 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; + } } static lint_status check_for_files_in_include_directory(const package_spec& spec, const vcpkg_paths& paths) @@ -370,6 +377,36 @@ namespace vcpkg return lint_status::ERROR_DETECTED; } + static lint_status check_matching_debug_and_release_binaries(const std::vector& debug_binaries, const std::vector& release_binaries) + { + const size_t debug_count = debug_binaries.size(); + const size_t release_count = release_binaries.size(); + if (debug_count == release_count) + { + return lint_status::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("Debug binaries"); + print_vector_of_files(debug_binaries); + + System::println("Release binaries"); + print_vector_of_files(release_binaries); + + if (debug_count == 0) + { + System::println(System::color::warning, "Debug binaries were not built"); + } + if (release_count == 0) + { + System::println(System::color::warning, "Release binaries were not built"); + } + + System::println(""); + + return lint_status::ERROR_DETECTED; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -394,9 +431,14 @@ namespace vcpkg { case triplet::BuildType::DYNAMIC: { + const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll"); + const std::vector release_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll"); + + error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); + std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll", &dlls); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll", &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); error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls); @@ -416,9 +458,15 @@ namespace vcpkg Checks::unreachable(); } + const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); + const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); + + error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); + std::vector libs; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib", &libs); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib", &libs); + libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); + libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); + error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); if (error_count != 0) -- cgit v1.2.3 From 5671a12eef744e81dd33b8314f8b55c48235071d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sat, 22 Oct 2016 20:29:36 -0700 Subject: [post-build-checks] Add checks about subdirectories in lib/ --- toolsrc/src/post_build_lint.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 532b189cd..75a57edc4 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -36,6 +36,14 @@ namespace vcpkg 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) @@ -407,6 +415,24 @@ namespace vcpkg return lint_status::ERROR_DETECTED; } + 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); + }); + + if (!subdirectories.empty()) + { + System::println("Directory %s should have no subdirectories", dir.generic_string()); + System::println("The following subdirectories were found: "); + print_vector_of_files(subdirectories); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -458,6 +484,8 @@ namespace vcpkg Checks::unreachable(); } + error_count += check_no_subdirectories(paths.packages / spec.dir() / "lib"); + error_count += check_no_subdirectories(paths.packages / spec.dir() / "debug" / "lib"); const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); -- cgit v1.2.3 From 16ecddf94d222baa6dbe10b32310a9292913be7c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sat, 22 Oct 2016 20:33:21 -0700 Subject: [post-build] Convert message to warning --- toolsrc/src/post_build_lint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 75a57edc4..4bcf5b008 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -424,7 +424,7 @@ namespace vcpkg if (!subdirectories.empty()) { - System::println("Directory %s should have no subdirectories", dir.generic_string()); + 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); return lint_status::ERROR_DETECTED; -- cgit v1.2.3 From 7625d837d52aa218526d02a98d1748e479b994a1 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sun, 23 Oct 2016 14:09:30 -0700 Subject: [vcpkg] Revert 5671a12. Fixes #206, we should reapply these checks once all existing ports have been fixed. --- toolsrc/src/post_build_lint.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 4bcf5b008..9b23013de 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -483,9 +483,10 @@ namespace vcpkg default: Checks::unreachable(); } - +#if 0 error_count += check_no_subdirectories(paths.packages / spec.dir() / "lib"); error_count += check_no_subdirectories(paths.packages / spec.dir() / "debug" / "lib"); +#endif const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); -- cgit v1.2.3 From 6380852f898c774897b6cfa74f0eaef3c0ca6b67 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 26 Oct 2016 12:46:26 -0700 Subject: [coff_file_reader] Improve error message --- toolsrc/src/coff_file_reader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 593bb18d1..f46150979 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -34,9 +34,9 @@ namespace vcpkg {namespace COFFFileReader return data; } - static void verify_equal_strings(const char* expected, const char* actual, int size) + static void verify_equal_strings(const char* expected, const char* actual, int size, const char* label) { - Checks::check_exit(memcmp(expected, actual, size) == 0, "Incorrect string found. Expected: %s but found %s", expected, actual); + Checks::check_exit(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) @@ -52,7 +52,7 @@ namespace vcpkg {namespace COFFFileReader fs.seekg(offset_to_PE_signature); char signature[PE_SIGNATURE_SIZE]; fs.read(signature, PE_SIGNATURE_SIZE); - verify_equal_strings(PE_SIGNATURE, signature, PE_SIGNATURE_SIZE); + verify_equal_strings(PE_SIGNATURE, signature, PE_SIGNATURE_SIZE, "PE_SIGNATURE"); fs.seekg(offset_to_PE_signature + PE_SIGNATURE_SIZE, ios_base::beg); } @@ -114,7 +114,7 @@ namespace vcpkg {namespace COFFFileReader fs.read(&ret.data[0], HEADER_SIZE); const std::string header_end = ret.data.substr(HEADER_END_OFFSET, HEADER_END_SIZE); - verify_equal_strings(HEADER_END, header_end.c_str(), HEADER_END_SIZE); + verify_equal_strings(HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); return ret; } @@ -207,7 +207,7 @@ namespace vcpkg {namespace COFFFileReader char file_start[FILE_START_SIZE]; fs.read(file_start, FILE_START_SIZE); - verify_equal_strings(FILE_START, file_start, FILE_START_SIZE); + verify_equal_strings(FILE_START, file_start, FILE_START_SIZE, "LIB FILE_START"); } dll_info read_dll(const fs::path path) -- cgit v1.2.3 From 5d1dccf618870da571e498a52923fbbe3b11c180 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 27 Oct 2016 14:09:40 -0700 Subject: [post-build-checks] Fix debug/release file vectors that were swapped --- toolsrc/src/post_build_lint.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 9b23013de..c9b36a0fb 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -403,11 +403,11 @@ namespace vcpkg if (debug_count == 0) { - System::println(System::color::warning, "Debug binaries were not built"); + System::println(System::color::warning, "Debug binaries were not found"); } if (release_count == 0) { - System::println(System::color::warning, "Release binaries were not built"); + System::println(System::color::warning, "Release binaries were not found"); } System::println(""); @@ -457,8 +457,8 @@ namespace vcpkg { case triplet::BuildType::DYNAMIC: { - const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll"); - const std::vector release_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll"); + const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll"); + const std::vector release_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll"); error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); @@ -487,8 +487,8 @@ namespace vcpkg error_count += check_no_subdirectories(paths.packages / spec.dir() / "lib"); error_count += check_no_subdirectories(paths.packages / spec.dir() / "debug" / "lib"); #endif - const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); - const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); + const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); + const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); -- cgit v1.2.3 From 4bf461c9cd136df6aa12a02d7f6ec09b91f8acb7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 14:38:16 -0700 Subject: [post-build-checks] Add check for bin folders in static builds --- toolsrc/src/post_build_lint.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index c9b36a0fb..40ddef3bb 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -433,6 +433,37 @@ namespace vcpkg return lint_status::SUCCESS; } + static lint_status check_bin_folders_are_not_present_in_static_build(const package_spec& spec, const vcpkg_paths& paths) + { + const fs::path bin = paths.packages / spec.dir() / "bin"; + const fs::path debug_bin = paths.packages / spec.dir() / "debug" / "bin"; + + if (!fs::exists(bin) && !fs::exists(debug_bin)) + { + return lint_status::SUCCESS; + } + + 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.generic_string()); + } + + 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.generic_string()); + } + + 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 lint_status::ERROR_DETECTED; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -477,6 +508,7 @@ namespace vcpkg recursive_find_files_with_extension_in_dir(paths.packages / spec.dir(), ".dll", &dlls); error_count += check_no_dlls_present(dlls); + error_count += check_bin_folders_are_not_present_in_static_build(spec, paths); break; } -- cgit v1.2.3 From e695f92dec6177ea28554638deb294aa0be2d2e6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 14:57:50 -0700 Subject: [post-build-checks] Add check for empty directories --- toolsrc/src/post_build_lint.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 40ddef3bb..8301e74cc 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -464,6 +464,29 @@ namespace vcpkg return lint_status::ERROR_DETECTED; } + 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); + }); + + 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: "); + print_vector_of_files(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"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -530,6 +553,8 @@ namespace vcpkg error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); + error_count += check_no_empty_folders(paths.packages / spec.dir()); + if (error_count != 0) { const fs::path portfile = paths.ports / spec.name() / "portfile.cmake"; -- cgit v1.2.3 From ce890f979945183f5a52663d869a9c7ee1e1bb01 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 17:47:25 -0700 Subject: check_exit() instead of check_throw() --- toolsrc/src/vcpkglib_helpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 3aa3735b0..04fdf214e 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -18,7 +18,7 @@ namespace vcpkg {namespace details std::string required_field(const std::unordered_map& fields, const std::string& fieldname) { auto it = fields.find(fieldname); - vcpkg::Checks::check_throw(it != fields.end(), "Required field not present: %s", fieldname); + vcpkg::Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname); return it->second; }; -- cgit v1.2.3 From 1fa055569540d887ceca0daadca7d0160b886089 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 19:30:53 -0700 Subject: [building] Parse SourceParagraph at the start of the build --- toolsrc/src/commands_installation.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 7e7da9e3f..c728c41dc 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -11,17 +11,19 @@ namespace vcpkg { - static void create_binary_control_file(const vcpkg_paths& paths, const fs::path& port_dir, const triplet& target_triplet) + static void create_binary_control_file(const vcpkg_paths& paths, const SourceParagraph& source_paragraph, const triplet& target_triplet) { - auto pghs = get_paragraphs(port_dir / "CONTROL"); - Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); - auto bpgh = BinaryParagraph(SourceParagraph(pghs[0]), target_triplet); + auto bpgh = BinaryParagraph(source_paragraph, target_triplet); const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL"; std::ofstream(binary_control_file) << bpgh; } static void build_internal(const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { + auto pghs = get_paragraphs(port_dir / "CONTROL"); + Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); + SourceParagraph source_paragraph(pghs[0]); + const fs::path ports_cmake_script_path = paths.ports_cmake; auto&& target_triplet = spec.target_triplet(); const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", @@ -54,7 +56,7 @@ namespace vcpkg perform_all_checks(spec, paths); - create_binary_control_file(paths, port_dir, target_triplet); + create_binary_control_file(paths, source_paragraph, target_triplet); // const fs::path port_buildtrees_dir = paths.buildtrees / spec.name; // delete_directory(port_buildtrees_dir); -- cgit v1.2.3 From 87a78a78dcb88d1656eda5dcbdf306fb55eba575 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 19:34:30 -0700 Subject: [Strings] Add join() --- toolsrc/src/vcpkg_Strings.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 56eeae7a0..c53cba1fc 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -64,4 +64,25 @@ namespace vcpkg {namespace Strings std::transform(output.begin(), output.end(), output.begin(), ::tolower); return output; } + + std::string join(const std::vector& v, const std::string& delimiter) + { + if (v.empty()) + { + return std::string(); + } + + std::string output; + size_t size = v.size(); + + output.append(v.at(0)); + + for (int i = 1; i < size; ++i) + { + output.append(delimiter); + output.append(v.at(i)); + } + + return output; + } }} -- cgit v1.2.3 From 079a027b1e81becd4ba448362579f625dd7bcca4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 19:39:45 -0700 Subject: parse_depends() now handles empty case internally --- toolsrc/src/BinaryParagraph.cpp | 6 +----- toolsrc/src/SourceParagraph.cpp | 6 +----- toolsrc/src/vcpkglib_helpers.cpp | 5 +++++ 3 files changed, 7 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index 48d04f686..61c74fcf5 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -23,11 +23,7 @@ namespace vcpkg } std::string deps = optional_field(fields, "Depends"); - if (!deps.empty()) - { - this->depends.clear(); - this->depends = parse_depends(deps); - } + this->depends = parse_depends(deps); } BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet) diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 374121ae9..75c8ebfef 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -12,9 +12,5 @@ vcpkg::SourceParagraph::SourceParagraph(const std::unordered_mapdepends.clear(); - this->depends = parse_depends(deps); - }; + this->depends = parse_depends(deps); } diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 04fdf214e..02182b995 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -24,6 +24,11 @@ namespace vcpkg {namespace details std::vector parse_depends(const std::string& depends_string) { + if (depends_string.empty()) + { + return {}; + } + std::vector out; size_t cur = 0; -- cgit v1.2.3 From 4665b16ab3556235ddcbdac160df261ee87694e4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 20:26:52 -0700 Subject: Add checks for fields in CONTROL file. Resolves #228 --- toolsrc/src/SourceParagraph.cpp | 54 ++++++++++++++++++++++++++++------- toolsrc/src/commands_installation.cpp | 15 ++++++++++ toolsrc/src/vcpkglib_helpers.cpp | 29 +++++++++++++++++-- 3 files changed, 85 insertions(+), 13 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 75c8ebfef..c870bde21 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -1,16 +1,50 @@ #include "SourceParagraph.h" #include "vcpkglib_helpers.h" -using namespace vcpkg::details; +namespace vcpkg +{ + // + namespace SourceParagraphRequiredField + { + static const std::string SOURCE = "Source"; + static const std::string VERSION = "Version"; + } -vcpkg::SourceParagraph::SourceParagraph() = default; + namespace SourceParagraphOptionalEntry + { + static const std::string DESCRIPTION = "Description"; + static const std::string MAINTAINER = "Maintainer"; + static const std::string BUILD_DEPENDS = "Build-Depends"; + } -vcpkg::SourceParagraph::SourceParagraph(const std::unordered_map& fields): - name(required_field(fields, "Source")), - version(required_field(fields, "Version")), - description(optional_field(fields, "Description")), - maintainer(optional_field(fields, "Maintainer")) -{ - std::string deps = optional_field(fields, "Build-Depends"); - this->depends = parse_depends(deps); + const std::vector& SourceParagraph::get_list_of_valid_entries() + { + static const std::vector valid_enties = + { + SourceParagraphRequiredField::SOURCE, + SourceParagraphRequiredField::VERSION, + + SourceParagraphOptionalEntry::DESCRIPTION, + SourceParagraphOptionalEntry::MAINTAINER, + SourceParagraphOptionalEntry::BUILD_DEPENDS + }; + + return valid_enties; + } + + SourceParagraph::SourceParagraph() = default; + + SourceParagraph::SourceParagraph(std::unordered_map fields) + { + using namespace vcpkg::details; + this->name = remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); + this->version = remove_required_field(&fields, SourceParagraphRequiredField::VERSION); + this->description = remove_optional_field(&fields, SourceParagraphOptionalEntry::DESCRIPTION); + this->maintainer = remove_optional_field(&fields, SourceParagraphOptionalEntry::MAINTAINER); + + std::string deps = remove_optional_field(&fields, SourceParagraphOptionalEntry::BUILD_DEPENDS); + this->depends = parse_depends(deps); + + this->unparsed_fields = std::move(fields); + } } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index c728c41dc..914168092 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -8,6 +8,7 @@ #include "vcpkg_System.h" #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" +#include "vcpkg_Maps.h" namespace vcpkg { @@ -24,6 +25,20 @@ namespace vcpkg Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); SourceParagraph source_paragraph(pghs[0]); + if (!source_paragraph.unparsed_fields.empty()) + { + const std::vector remaining_keys = Maps::extract_keys(source_paragraph.unparsed_fields); + const std::vector& valid_entries = SourceParagraph::get_list_of_valid_entries(); + + const std::string remaining_keys_as_string = Strings::join(remaining_keys, "\n "); + const std::string valid_keys_as_string = Strings::join(valid_entries, "\n "); + + System::println(System::color::error, "Error: There are invalid fields in the port file"); + System::println("The following fields were not expected in the port file:\n\n %s\n\n", remaining_keys_as_string); + System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_keys_as_string); + exit(EXIT_FAILURE); + } + const fs::path ports_cmake_script_path = paths.ports_cmake; auto&& target_triplet = spec.target_triplet(); const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 02182b995..3d14d4b06 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -13,14 +13,37 @@ namespace vcpkg {namespace details } return it->second; - }; + } + + std::string remove_optional_field(std::unordered_map* fields, const std::string& fieldname) + { + auto it = fields->find(fieldname); + if (it == fields->end()) + { + return std::string(); + } + + const std::string value = std::move(it->second); + fields->erase(it); + return value; + } std::string required_field(const std::unordered_map& fields, const std::string& fieldname) { auto it = fields.find(fieldname); - vcpkg::Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname); + Checks::check_exit(it != fields.end(), "Required field not present: %s", fieldname); return it->second; - }; + } + + std::string remove_required_field(std::unordered_map* fields, const std::string& fieldname) + { + auto it = fields->find(fieldname); + Checks::check_exit(it != fields->end(), "Required field not present: %s", fieldname); + + const std::string value = std::move(it->second); + fields->erase(it); + return value; + } std::vector parse_depends(const std::string& depends_string) { -- cgit v1.2.3 From a868bc96da158f3b2dcbc9e8e406b9577a8a1ab0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 2 Nov 2016 20:57:19 -0700 Subject: Add port name to the output message --- toolsrc/src/commands_installation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 914168092..67623b855 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -33,7 +33,7 @@ namespace vcpkg const std::string remaining_keys_as_string = Strings::join(remaining_keys, "\n "); const std::string valid_keys_as_string = Strings::join(valid_entries, "\n "); - System::println(System::color::error, "Error: There are invalid fields in the port file"); + System::println(System::color::error, "Error: There are invalid fields in port file %s", port_dir.generic_string()); System::println("The following fields were not expected in the port file:\n\n %s\n\n", remaining_keys_as_string); System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_keys_as_string); exit(EXIT_FAILURE); -- cgit v1.2.3 From 5b60e134665cdb33bd1f01f17e61c5b9ba4ad137 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 14:34:52 -0700 Subject: [SourceParagraph] Consistency rename --- toolsrc/src/SourceParagraph.cpp | 20 ++++++++++---------- toolsrc/src/commands_installation.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index c870bde21..34d2a8170 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -10,26 +10,26 @@ namespace vcpkg static const std::string VERSION = "Version"; } - namespace SourceParagraphOptionalEntry + namespace SourceParagraphOptionalField { static const std::string DESCRIPTION = "Description"; static const std::string MAINTAINER = "Maintainer"; static const std::string BUILD_DEPENDS = "Build-Depends"; } - const std::vector& SourceParagraph::get_list_of_valid_entries() + const std::vector& SourceParagraph::get_list_of_valid_fields() { - static const std::vector valid_enties = + static const std::vector valid_fields = { SourceParagraphRequiredField::SOURCE, SourceParagraphRequiredField::VERSION, - SourceParagraphOptionalEntry::DESCRIPTION, - SourceParagraphOptionalEntry::MAINTAINER, - SourceParagraphOptionalEntry::BUILD_DEPENDS + SourceParagraphOptionalField::DESCRIPTION, + SourceParagraphOptionalField::MAINTAINER, + SourceParagraphOptionalField::BUILD_DEPENDS }; - return valid_enties; + return valid_fields; } SourceParagraph::SourceParagraph() = default; @@ -39,10 +39,10 @@ namespace vcpkg using namespace vcpkg::details; this->name = remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); this->version = remove_required_field(&fields, SourceParagraphRequiredField::VERSION); - this->description = remove_optional_field(&fields, SourceParagraphOptionalEntry::DESCRIPTION); - this->maintainer = remove_optional_field(&fields, SourceParagraphOptionalEntry::MAINTAINER); + this->description = remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION); + this->maintainer = remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); - std::string deps = remove_optional_field(&fields, SourceParagraphOptionalEntry::BUILD_DEPENDS); + std::string deps = remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); this->depends = parse_depends(deps); this->unparsed_fields = std::move(fields); diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 67623b855..22309cabf 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -28,7 +28,7 @@ namespace vcpkg if (!source_paragraph.unparsed_fields.empty()) { const std::vector remaining_keys = Maps::extract_keys(source_paragraph.unparsed_fields); - const std::vector& valid_entries = SourceParagraph::get_list_of_valid_entries(); + const std::vector& valid_entries = SourceParagraph::get_list_of_valid_fields(); const std::string remaining_keys_as_string = Strings::join(remaining_keys, "\n "); const std::string valid_keys_as_string = Strings::join(valid_entries, "\n "); -- cgit v1.2.3 From 90876a3bfef586a20e475d5ef812bac843e7a1a8 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 15:43:09 -0700 Subject: SourceParagraph checks fields at construction time --- toolsrc/src/SourceParagraph.cpp | 16 +++++++++++++++- toolsrc/src/commands_installation.cpp | 14 -------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 34d2a8170..1fa50e233 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -1,5 +1,7 @@ #include "SourceParagraph.h" #include "vcpkglib_helpers.h" +#include "vcpkg_System.h" +#include "vcpkg_Maps.h" namespace vcpkg { @@ -45,6 +47,18 @@ namespace vcpkg std::string deps = remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); this->depends = parse_depends(deps); - this->unparsed_fields = std::move(fields); + if (!fields.empty()) + { + const std::vector remaining_fields = Maps::extract_keys(fields); + const std::vector& valid_fields = get_list_of_valid_fields(); + + const std::string remaining_fields_as_string = Strings::join(remaining_fields, "\n "); + const std::string valid_fields_as_string = Strings::join(valid_fields, "\n "); + + 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); + exit(EXIT_FAILURE); + } } } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 22309cabf..022b87139 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -25,20 +25,6 @@ namespace vcpkg Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); SourceParagraph source_paragraph(pghs[0]); - if (!source_paragraph.unparsed_fields.empty()) - { - const std::vector remaining_keys = Maps::extract_keys(source_paragraph.unparsed_fields); - const std::vector& valid_entries = SourceParagraph::get_list_of_valid_fields(); - - const std::string remaining_keys_as_string = Strings::join(remaining_keys, "\n "); - const std::string valid_keys_as_string = Strings::join(valid_entries, "\n "); - - System::println(System::color::error, "Error: There are invalid fields in port file %s", port_dir.generic_string()); - System::println("The following fields were not expected in the port file:\n\n %s\n\n", remaining_keys_as_string); - System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_keys_as_string); - exit(EXIT_FAILURE); - } - const fs::path ports_cmake_script_path = paths.ports_cmake; auto&& target_triplet = spec.target_triplet(); const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", -- cgit v1.2.3 From 99b3c491729187d87ba9fd1cc78bc9b63a046616 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 15:53:15 -0700 Subject: [SourceParagraph] Remove using namespace; --- toolsrc/src/SourceParagraph.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 1fa50e233..f46a9c2af 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -38,14 +38,13 @@ namespace vcpkg SourceParagraph::SourceParagraph(std::unordered_map fields) { - using namespace vcpkg::details; - this->name = remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); - this->version = remove_required_field(&fields, SourceParagraphRequiredField::VERSION); - this->description = remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION); - this->maintainer = remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); + this->name = details::remove_required_field(&fields, SourceParagraphRequiredField::SOURCE); + this->version = details::remove_required_field(&fields, SourceParagraphRequiredField::VERSION); + this->description = details::remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION); + this->maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); - std::string deps = remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); - this->depends = parse_depends(deps); + std::string deps = details::remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); + this->depends = details::parse_depends(deps); if (!fields.empty()) { -- cgit v1.2.3 From 95ef1b95e6e2f7933bb40f428514dcf178b201e6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 17:36:47 -0700 Subject: [BinaryParagraph] Refactor implementation --- toolsrc/src/BinaryParagraph.cpp | 57 ++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index 61c74fcf5..6dceb66d9 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -6,24 +6,57 @@ using namespace vcpkg::details; namespace vcpkg { + // + namespace BinaryParagraphRequiredField + { + static const std::string PACKAGE = "Package"; + static const std::string VERSION = "Version"; + static const std::string ARCHITECTURE = "Architecture"; + static const std::string MULTI_ARCH = "Multi-Arch"; + } + + namespace BinaryParagraphOptionalField + { + static const std::string DESCRIPTION = "Description"; + static const std::string MAINTAINER = "Maintainer"; + static const std::string DEPENDS = "Depends"; + } + + static const std::vector& get_list_of_valid_fields() + { + static const std::vector valid_fields = + { + BinaryParagraphRequiredField::PACKAGE, + BinaryParagraphRequiredField::VERSION, + BinaryParagraphRequiredField::ARCHITECTURE, + + BinaryParagraphOptionalField::DESCRIPTION, + BinaryParagraphOptionalField::MAINTAINER, + BinaryParagraphOptionalField::DEPENDS + }; + + return valid_fields; + } + BinaryParagraph::BinaryParagraph() = default; - BinaryParagraph::BinaryParagraph(const std::unordered_map& fields) : - version(required_field(fields, "Version")), - description(optional_field(fields, "Description")), - maintainer(optional_field(fields, "Maintainer")) + BinaryParagraph::BinaryParagraph(std::unordered_map fields) { - const std::string name = required_field(fields, "Package"); - const triplet target_triplet = triplet::from_canonical_name(required_field(fields, "Architecture")); + const std::string name = details::remove_required_field(&fields, BinaryParagraphRequiredField::PACKAGE); + const std::string architecture = details::remove_required_field(&fields, BinaryParagraphRequiredField::ARCHITECTURE); + const triplet target_triplet = triplet::from_canonical_name(architecture); + this->spec = package_spec::from_name_and_triplet(name, target_triplet).get_or_throw(); + this->version = details::remove_required_field(&fields, BinaryParagraphRequiredField::VERSION); - { - std::string multi_arch = required_field(fields, "Multi-Arch"); - Checks::check_throw(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch); - } + this->description = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DESCRIPTION); + this->maintainer = details::remove_optional_field(&fields, BinaryParagraphOptionalField::MAINTAINER); + + std::string multi_arch = details::remove_required_field(&fields, BinaryParagraphRequiredField::MULTI_ARCH); + Checks::check_exit(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch); - std::string deps = optional_field(fields, "Depends"); - this->depends = parse_depends(deps); + std::string deps = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DEPENDS); + this->depends = details::parse_depends(deps); } BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet) -- cgit v1.2.3 From 11c9a523f7cd8cc324606c543311de1edcaee6cb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 18:52:44 -0700 Subject: [SourceParagraph] Make function static --- toolsrc/src/SourceParagraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index f46a9c2af..6f25dbded 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -19,7 +19,7 @@ namespace vcpkg static const std::string BUILD_DEPENDS = "Build-Depends"; } - const std::vector& SourceParagraph::get_list_of_valid_fields() + static const std::vector& get_list_of_valid_fields() { static const std::vector valid_fields = { -- cgit v1.2.3 From d5d997bd7dbf7f1de5c5b72a7e89bf63a5925ad6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 3 Nov 2016 18:55:32 -0700 Subject: [StatusParagraph] Minor refactor --- toolsrc/src/StatusParagraph.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/StatusParagraph.cpp b/toolsrc/src/StatusParagraph.cpp index 5aa425969..bf12ae89a 100644 --- a/toolsrc/src/StatusParagraph.cpp +++ b/toolsrc/src/StatusParagraph.cpp @@ -5,6 +5,12 @@ using namespace vcpkg::details; namespace vcpkg { + // + namespace BinaryParagraphRequiredField + { + static const std::string STATUS = "Status"; + } + StatusParagraph::StatusParagraph() : want(want_t::error), state(install_state_t::error) { } @@ -19,7 +25,7 @@ namespace vcpkg StatusParagraph::StatusParagraph(const std::unordered_map& fields) : package(fields) { - std::string status_field = required_field(fields, "Status"); + std::string status_field = required_field(fields, BinaryParagraphRequiredField::STATUS); auto b = status_field.begin(); auto mark = b; -- cgit v1.2.3 From 7f336c746776daf2af95914ed25ff3d50a96b387 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sat, 5 Nov 2016 01:02:15 -0700 Subject: Enable qualified dependencies. Fix bug in internal 'build' command. Added capability for CONTROL files to specify qualified dependencies, which are substring searched inside triplet names. Fixed bug in internal 'build' command where if a package is already built, that built package's dependencies will be used to determine requirements for the build instead of the port directory's CONTROL file. --- toolsrc/src/BinaryParagraph.cpp | 4 +- toolsrc/src/SourceParagraph.cpp | 83 +++++++- toolsrc/src/commands_installation.cpp | 11 +- toolsrc/src/lib.cpp | 40 ++-- toolsrc/src/test.cpp | 347 -------------------------------- toolsrc/src/tests_dependencies.cpp | 39 ++++ toolsrc/src/tests_paragraph.cpp | 367 ++++++++++++++++++++++++++++++++++ toolsrc/src/vcpkg_Checks.cpp | 3 + toolsrc/src/vcpkg_Dependencies.cpp | 8 +- toolsrc/src/vcpkglib_helpers.cpp | 33 --- 10 files changed, 528 insertions(+), 407 deletions(-) delete mode 100644 toolsrc/src/test.cpp create mode 100644 toolsrc/src/tests_dependencies.cpp create mode 100644 toolsrc/src/tests_paragraph.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index 6dceb66d9..ad85a1f8a 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -56,7 +56,7 @@ namespace vcpkg Checks::check_exit(multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch); std::string deps = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DEPENDS); - this->depends = details::parse_depends(deps); + this->depends = parse_depends(deps); } BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const triplet& target_triplet) @@ -65,7 +65,7 @@ namespace vcpkg this->version = spgh.version; this->description = spgh.description; this->maintainer = spgh.maintainer; - this->depends = spgh.depends; + this->depends = filter_dependencies(spgh.depends, target_triplet); } std::string BinaryParagraph::displayname() const diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 6f25dbded..bdf15a737 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -2,6 +2,7 @@ #include "vcpkglib_helpers.h" #include "vcpkg_System.h" #include "vcpkg_Maps.h" +#include "triplet.h" namespace vcpkg { @@ -44,7 +45,7 @@ namespace vcpkg this->maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER); std::string deps = details::remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS); - this->depends = details::parse_depends(deps); + this->depends = expand_qualified_dependencies(parse_depends(deps)); if (!fields.empty()) { @@ -60,4 +61,84 @@ namespace vcpkg exit(EXIT_FAILURE); } } + + std::vector vcpkg::expand_qualified_dependencies(const std::vector& depends) + { + auto convert = [&](const std::string& depend_string) -> dependency { + auto pos = depend_string.find(' '); + 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, "" }; + } + dep.qualifier = depend_string.substr(pos + 2, depend_string.size() - pos - 3); + return dep; + }; + + std::vector ret; + + for (auto&& depend_string : depends) + { + ret.push_back(convert(depend_string)); + } + + return ret; + } + + std::vector parse_depends(const std::string& depends_string) + { + if (depends_string.empty()) + { + return{}; + } + + std::vector out; + + size_t cur = 0; + do + { + auto pos = depends_string.find(',', cur); + if (pos == std::string::npos) + { + out.push_back(depends_string.substr(cur)); + break; + } + out.push_back(depends_string.substr(cur, pos - cur)); + + // skip comma and space + ++pos; + if (depends_string[pos] == ' ') + { + ++pos; + } + + cur = pos; + } while (cur != std::string::npos); + + return out; + } + + std::vector filter_dependencies(const std::vector& deps, const triplet& t) + { + std::vector ret; + for (auto&& dep : deps) + { + if (dep.qualifier.empty() || t.canonical_name().find(dep.qualifier) != std::string::npos) + { + ret.push_back(dep.name); + } + } + return ret; + } + + std::ostream & operator<<(std::ostream & os, const dependency & p) + { + os << p.name; + return os; + } } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 022b87139..f6aeafa02 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -138,7 +138,16 @@ namespace vcpkg const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); Input::check_triplet(spec.target_triplet(), paths); - std::unordered_set unmet_dependencies = Dependencies::find_unmet_dependencies(paths, spec, status_db); + + // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). + auto first_level_deps = get_unmet_package_build_dependencies(paths, spec, status_db); + std::vector first_level_deps_specs; + for (auto&& dep : first_level_deps) + { + first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); + } + + std::unordered_set unmet_dependencies = Dependencies::find_unmet_dependencies(paths, first_level_deps_specs, status_db); if (!unmet_dependencies.empty()) { System::println(System::color::error, "The build command requires all dependencies to be already installed."); diff --git a/toolsrc/src/lib.cpp b/toolsrc/src/lib.cpp index 45b73ee07..3c844ac3f 100644 --- a/toolsrc/src/lib.cpp +++ b/toolsrc/src/lib.cpp @@ -209,29 +209,33 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar // TODO: Refactoring between this function and install_package std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) { - std::vector> pghs; - { - const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; + const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; - auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) + auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = parse_paragraphs(*control_contents); + } + catch (std::runtime_error) { - try - { - pghs = parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); - return BinaryParagraph(pghs[0]).depends; } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); + return BinaryParagraph(pghs[0]).depends; } + return get_unmet_package_build_dependencies(paths, spec, status_db); +} + +std::vector vcpkg::get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) +{ const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); if (auto control_contents = control_contents_maybe.get()) { + std::vector> pghs; try { pghs = parse_paragraphs(*control_contents); @@ -240,7 +244,7 @@ std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths { } Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); - return SourceParagraph(pghs[0]).depends; + return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); } Checks::exit_with_message("Could not find package named %s", spec); @@ -252,11 +256,11 @@ void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& bin spgh.package = binary_paragraph; spgh.want = want_t::install; spgh.state = install_state_t::half_installed; - for (const std::string& dependency : spgh.package.depends) + for (auto&& dep : spgh.package.depends) { - if (status_db.find_installed(dependency, spgh.package.spec.target_triplet()) == status_db.end()) + if (status_db.find_installed(dep, spgh.package.spec.target_triplet()) == status_db.end()) { - std::abort(); + Checks::unreachable(); } } write_update(paths, spgh); diff --git a/toolsrc/src/test.cpp b/toolsrc/src/test.cpp deleted file mode 100644 index fc49b362d..000000000 --- a/toolsrc/src/test.cpp +++ /dev/null @@ -1,347 +0,0 @@ -#include "CppUnitTest.h" -#include "vcpkg.h" - -#pragma comment(lib,"version") -#pragma comment(lib,"winhttp") - -using namespace Microsoft::VisualStudio::CppUnitTestFramework; - -namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework -{ - template <> - inline std::wstring ToString(const vcpkg::package_spec_parse_result& t) - { - return ToString(static_cast(t)); - } -}}} - -namespace UnitTest1 -{ - TEST_CLASS(ControlParsing) - { - public: - TEST_METHOD(SourceParagraph_Construct_Minimum) - { - vcpkg::SourceParagraph pgh({ - {"Source", "zlib"}, - {"Version", "1.2.8"} - }); - - Assert::AreEqual("zlib", pgh.name.c_str()); - Assert::AreEqual("1.2.8", pgh.version.c_str()); - Assert::AreEqual("", pgh.maintainer.c_str()); - Assert::AreEqual("", pgh.description.c_str()); - Assert::AreEqual(size_t(0), pgh.depends.size()); - } - - TEST_METHOD(SourceParagraph_Construct_Maximum) - { - vcpkg::SourceParagraph pgh({ - {"Source", "s"}, - {"Version", "v"}, - {"Maintainer", "m"}, - {"Description", "d"}, - {"Build-Depends", "bd"} - }); - Assert::AreEqual("s", pgh.name.c_str()); - Assert::AreEqual("v", pgh.version.c_str()); - Assert::AreEqual("m", pgh.maintainer.c_str()); - Assert::AreEqual("d", pgh.description.c_str()); - Assert::AreEqual(size_t(1), pgh.depends.size()); - Assert::AreEqual("bd", pgh.depends[0].c_str()); - } - - TEST_METHOD(SourceParagraph_Two_Depends) - { - vcpkg::SourceParagraph pgh({ - {"Source", "zlib"}, - {"Version", "1.2.8"}, - {"Build-Depends", "z, openssl"} - }); - - Assert::AreEqual(size_t(2), pgh.depends.size()); - Assert::AreEqual("z", pgh.depends[0].c_str()); - Assert::AreEqual("openssl", pgh.depends[1].c_str()); - } - - TEST_METHOD(SourceParagraph_Three_Depends) - { - vcpkg::SourceParagraph pgh({ - {"Source", "zlib"}, - {"Version", "1.2.8"}, - {"Build-Depends", "z, openssl, xyz"} - }); - - Assert::AreEqual(size_t(3), pgh.depends.size()); - Assert::AreEqual("z", pgh.depends[0].c_str()); - Assert::AreEqual("openssl", pgh.depends[1].c_str()); - Assert::AreEqual("xyz", pgh.depends[2].c_str()); - } - - TEST_METHOD(BinaryParagraph_Construct_Minimum) - { - vcpkg::BinaryParagraph pgh({ - {"Package", "zlib"}, - {"Version", "1.2.8"}, - {"Architecture", "a"}, - {"Multi-Arch", "same"}, - }); - - Assert::AreEqual("zlib", pgh.spec.name().c_str()); - Assert::AreEqual("1.2.8", pgh.version.c_str()); - Assert::AreEqual("", pgh.maintainer.c_str()); - Assert::AreEqual("", pgh.description.c_str()); - Assert::AreEqual("a", pgh.spec.target_triplet().canonical_name().c_str()); - Assert::AreEqual(size_t(0), pgh.depends.size()); - } - - TEST_METHOD(BinaryParagraph_Construct_Maximum) - { - vcpkg::BinaryParagraph pgh({ - {"Package", "s"}, - {"Version", "v"}, - {"Architecture", "a"}, - {"Multi-Arch", "same"}, - {"Maintainer", "m"}, - {"Description", "d"}, - {"Depends", "bd"} - }); - Assert::AreEqual("s", pgh.spec.name().c_str()); - Assert::AreEqual("v", pgh.version.c_str()); - Assert::AreEqual("m", pgh.maintainer.c_str()); - Assert::AreEqual("d", pgh.description.c_str()); - Assert::AreEqual(size_t(1), pgh.depends.size()); - Assert::AreEqual("bd", pgh.depends[0].c_str()); - } - - TEST_METHOD(BinaryParagraph_Three_Depends) - { - vcpkg::BinaryParagraph pgh({ - {"Package", "zlib"}, - {"Version", "1.2.8"}, - {"Architecture", "a"}, - {"Multi-Arch", "same"}, - {"Depends", "a, b, c"}, - }); - - Assert::AreEqual(size_t(3), pgh.depends.size()); - Assert::AreEqual("a", pgh.depends[0].c_str()); - Assert::AreEqual("b", pgh.depends[1].c_str()); - Assert::AreEqual("c", pgh.depends[2].c_str()); - } - - TEST_METHOD(parse_paragraphs_empty) - { - const char* str = ""; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::IsTrue(pghs.empty()); - } - - TEST_METHOD(parse_paragraphs_one_field) - { - const char* str = "f1: v1"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(1), pghs[0].size()); - Assert::AreEqual("v1", pghs[0]["f1"].c_str()); - } - - TEST_METHOD(parse_paragraphs_one_pgh) - { - const char* str = - "f1: v1\n" - "f2: v2"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(2), pghs[0].size()); - Assert::AreEqual("v1", pghs[0]["f1"].c_str()); - Assert::AreEqual("v2", pghs[0]["f2"].c_str()); - } - - TEST_METHOD(parse_paragraphs_two_pgh) - { - const char* str = - "f1: v1\n" - "f2: v2\n" - "\n" - "f3: v3\n" - "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(2), pghs.size()); - Assert::AreEqual(size_t(2), pghs[0].size()); - Assert::AreEqual("v1", pghs[0]["f1"].c_str()); - Assert::AreEqual("v2", pghs[0]["f2"].c_str()); - Assert::AreEqual(size_t(2), pghs[1].size()); - Assert::AreEqual("v3", pghs[1]["f3"].c_str()); - Assert::AreEqual("v4", pghs[1]["f4"].c_str()); - } - - TEST_METHOD(parse_paragraphs_field_names) - { - const char* str = - "1:\n" - "f:\n" - "F:\n" - "0:\n" - "F-2:\n"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(5), pghs[0].size()); - } - - TEST_METHOD(parse_paragraphs_multiple_blank_lines) - { - const char* str = - "f1: v1\n" - "f2: v2\n" - "\n" - "\n" - "f3: v3\n" - "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(2), pghs.size()); - } - - TEST_METHOD(parse_paragraphs_empty_fields) - { - const char* str = - "f1:\n" - "f2: "; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(2), pghs[0].size()); - Assert::AreEqual("", pghs[0]["f1"].c_str()); - Assert::AreEqual("", pghs[0]["f2"].c_str()); - Assert::AreEqual(size_t(2), pghs[0].size()); - } - - TEST_METHOD(parse_paragraphs_multiline_fields) - { - const char* str = - "f1: simple\n" - " f1\r\n" - "f2:\r\n" - " f2\r\n" - " continue\r\n"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual("simple\n f1", pghs[0]["f1"].c_str()); - Assert::AreEqual("\n f2\n continue", pghs[0]["f2"].c_str()); - } - - TEST_METHOD(parse_paragraphs_crlfs) - { - const char* str = - "f1: v1\r\n" - "f2: v2\r\n" - "\r\n" - "f3: v3\r\n" - "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); - Assert::AreEqual(size_t(2), pghs.size()); - Assert::AreEqual(size_t(2), pghs[0].size()); - Assert::AreEqual("v1", pghs[0]["f1"].c_str()); - Assert::AreEqual("v2", pghs[0]["f2"].c_str()); - Assert::AreEqual(size_t(2), pghs[1].size()); - Assert::AreEqual("v3", pghs[1]["f3"].c_str()); - Assert::AreEqual("v4", pghs[1]["f4"].c_str()); - } - - TEST_METHOD(BinaryParagraph_serialize_min) - { - std::stringstream ss; - vcpkg::BinaryParagraph pgh({ - {"Package", "zlib"}, - {"Version", "1.2.8"}, - {"Architecture", "a"}, - {"Multi-Arch", "same"}, - }); - ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(4), pghs[0].size()); - Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); - Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str()); - Assert::AreEqual("a", pghs[0]["Architecture"].c_str()); - Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str()); - } - - TEST_METHOD(BinaryParagraph_serialize_max) - { - std::stringstream ss; - vcpkg::BinaryParagraph pgh({ - {"Package", "zlib"}, - {"Version", "1.2.8"}, - {"Architecture", "a"}, - {"Description", "first line\n second line"}, - {"Maintainer", "abc "}, - {"Depends", "dep"}, - {"Multi-Arch", "same"}, - }); - ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual(size_t(7), pghs[0].size()); - Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); - Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str()); - Assert::AreEqual("a", pghs[0]["Architecture"].c_str()); - Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str()); - Assert::AreEqual("first line\n second line", pghs[0]["Description"].c_str()); - Assert::AreEqual("dep", pghs[0]["Depends"].c_str()); - } - - TEST_METHOD(BinaryParagraph_serialize_multiple_deps) - { - std::stringstream ss; - vcpkg::BinaryParagraph pgh({ - {"Package", "zlib"}, - {"Version", "1.2.8"}, - {"Architecture", "a"}, - {"Multi-Arch", "same"}, - {"Depends", "a, b, c"}, - }); - ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); - Assert::AreEqual(size_t(1), pghs.size()); - Assert::AreEqual("a, b, c", pghs[0]["Depends"].c_str()); - } - - TEST_METHOD(package_spec_parse) - { - vcpkg::expected spec = vcpkg::package_spec::from_string("zlib", vcpkg::triplet::X86_WINDOWS); - Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code())); - Assert::AreEqual("zlib", spec.get()->name().c_str()); - Assert::AreEqual(vcpkg::triplet::X86_WINDOWS.canonical_name(), spec.get()->target_triplet().canonical_name()); - } - - TEST_METHOD(package_spec_parse_with_arch) - { - vcpkg::expected spec = vcpkg::package_spec::from_string("zlib:x64-uwp", vcpkg::triplet::X86_WINDOWS); - Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code())); - Assert::AreEqual("zlib", spec.get()->name().c_str()); - Assert::AreEqual(vcpkg::triplet::X64_UWP.canonical_name(), spec.get()->target_triplet().canonical_name()); - } - - TEST_METHOD(package_spec_parse_with_multiple_colon) - { - auto ec = vcpkg::package_spec::from_string("zlib:x86-uwp:", vcpkg::triplet::X86_WINDOWS).error_code(); - Assert::AreEqual(vcpkg::package_spec_parse_result::TOO_MANY_COLONS, vcpkg::to_package_spec_parse_result(ec)); - } - - TEST_METHOD(utf8_to_utf16) - { - auto str = vcpkg::Strings::utf8_to_utf16("abc"); - Assert::AreEqual(L"abc", str.c_str()); - } - - TEST_METHOD(utf8_to_utf16_with_whitespace) - { - auto str = vcpkg::Strings::utf8_to_utf16("abc -x86-windows"); - Assert::AreEqual(L"abc -x86-windows", str.c_str()); - } - }; - - TEST_CLASS(Metrics) - { - }; -} diff --git a/toolsrc/src/tests_dependencies.cpp b/toolsrc/src/tests_dependencies.cpp new file mode 100644 index 000000000..bce1cab0e --- /dev/null +++ b/toolsrc/src/tests_dependencies.cpp @@ -0,0 +1,39 @@ +#include "CppUnitTest.h" +#include "SourceParagraph.h" +#include "triplet.h" + +#pragma comment(lib,"version") +#pragma comment(lib,"winhttp") + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +using namespace vcpkg; + +namespace UnitTest1 +{ + TEST_CLASS(DependencyTests) + { + public: + TEST_METHOD(parse_depends_one) + { + auto v = expand_qualified_dependencies(parse_depends("libA [windows]")); + Assert::AreEqual(size_t(1), v.size()); + Assert::AreEqual("libA", v[0].name.c_str()); + Assert::AreEqual("windows", v[0].qualifier.c_str()); + } + + TEST_METHOD(filter_depends) + { + auto deps = expand_qualified_dependencies(parse_depends("libA [windows], libB, libC [uwp]")); + auto v = filter_dependencies(deps, triplet::X64_WINDOWS); + Assert::AreEqual(size_t(2), v.size()); + Assert::AreEqual("libA", v[0].c_str()); + Assert::AreEqual("libB", v[1].c_str()); + + auto v2 = filter_dependencies(deps, triplet::ARM_UWP); + Assert::AreEqual(size_t(2), v.size()); + Assert::AreEqual("libB", v2[0].c_str()); + Assert::AreEqual("libC", v2[1].c_str()); + } + }; +} diff --git a/toolsrc/src/tests_paragraph.cpp b/toolsrc/src/tests_paragraph.cpp new file mode 100644 index 000000000..b06359b90 --- /dev/null +++ b/toolsrc/src/tests_paragraph.cpp @@ -0,0 +1,367 @@ +#include "CppUnitTest.h" +#include "vcpkg.h" + +#pragma comment(lib,"version") +#pragma comment(lib,"winhttp") + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework +{ + template <> + inline std::wstring ToString(const vcpkg::package_spec_parse_result& t) + { + return ToString(static_cast(t)); + } +}}} + +namespace UnitTest1 +{ + TEST_CLASS(ControlParsing) + { + public: + TEST_METHOD(SourceParagraph_Construct_Minimum) + { + vcpkg::SourceParagraph pgh({ + {"Source", "zlib"}, + {"Version", "1.2.8"} + }); + + Assert::AreEqual("zlib", pgh.name.c_str()); + Assert::AreEqual("1.2.8", pgh.version.c_str()); + Assert::AreEqual("", pgh.maintainer.c_str()); + Assert::AreEqual("", pgh.description.c_str()); + Assert::AreEqual(size_t(0), pgh.depends.size()); + } + + TEST_METHOD(SourceParagraph_Construct_Maximum) + { + vcpkg::SourceParagraph pgh({ + {"Source", "s"}, + {"Version", "v"}, + {"Maintainer", "m"}, + {"Description", "d"}, + {"Build-Depends", "bd"} + }); + Assert::AreEqual("s", pgh.name.c_str()); + Assert::AreEqual("v", pgh.version.c_str()); + Assert::AreEqual("m", pgh.maintainer.c_str()); + Assert::AreEqual("d", pgh.description.c_str()); + Assert::AreEqual(size_t(1), pgh.depends.size()); + Assert::AreEqual("bd", pgh.depends[0].name.c_str()); + } + + TEST_METHOD(SourceParagraph_Two_Depends) + { + vcpkg::SourceParagraph pgh({ + {"Source", "zlib"}, + {"Version", "1.2.8"}, + {"Build-Depends", "z, openssl"} + }); + + Assert::AreEqual(size_t(2), pgh.depends.size()); + Assert::AreEqual("z", pgh.depends[0].name.c_str()); + Assert::AreEqual("openssl", pgh.depends[1].name.c_str()); + } + + TEST_METHOD(SourceParagraph_Three_Depends) + { + vcpkg::SourceParagraph pgh({ + {"Source", "zlib"}, + {"Version", "1.2.8"}, + {"Build-Depends", "z, openssl, xyz"} + }); + + Assert::AreEqual(size_t(3), pgh.depends.size()); + Assert::AreEqual("z", pgh.depends[0].name.c_str()); + Assert::AreEqual("openssl", pgh.depends[1].name.c_str()); + Assert::AreEqual("xyz", pgh.depends[2].name.c_str()); + } + + TEST_METHOD(SourceParagraph_Construct_Qualified_Depends) + { + vcpkg::SourceParagraph pgh({ + { "Source", "zlib" }, + { "Version", "1.2.8" }, + { "Build-Depends", "libA [windows], libB [uwp]" } + }); + + Assert::AreEqual("zlib", pgh.name.c_str()); + Assert::AreEqual("1.2.8", pgh.version.c_str()); + Assert::AreEqual("", pgh.maintainer.c_str()); + Assert::AreEqual("", pgh.description.c_str()); + Assert::AreEqual(size_t(2), pgh.depends.size()); + Assert::AreEqual("libA", pgh.depends[0].name.c_str()); + Assert::AreEqual("windows", pgh.depends[0].qualifier.c_str()); + Assert::AreEqual("libB", pgh.depends[1].name.c_str()); + Assert::AreEqual("uwp", pgh.depends[1].qualifier.c_str()); + } + + + TEST_METHOD(BinaryParagraph_Construct_Minimum) + { + vcpkg::BinaryParagraph pgh({ + {"Package", "zlib"}, + {"Version", "1.2.8"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + }); + + Assert::AreEqual("zlib", pgh.spec.name().c_str()); + Assert::AreEqual("1.2.8", pgh.version.c_str()); + Assert::AreEqual("", pgh.maintainer.c_str()); + Assert::AreEqual("", pgh.description.c_str()); + Assert::AreEqual("x86-windows", pgh.spec.target_triplet().canonical_name().c_str()); + Assert::AreEqual(size_t(0), pgh.depends.size()); + } + + TEST_METHOD(BinaryParagraph_Construct_Maximum) + { + vcpkg::BinaryParagraph pgh({ + {"Package", "s"}, + {"Version", "v"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Maintainer", "m"}, + {"Description", "d"}, + {"Depends", "bd"} + }); + Assert::AreEqual("s", pgh.spec.name().c_str()); + Assert::AreEqual("v", pgh.version.c_str()); + Assert::AreEqual("m", pgh.maintainer.c_str()); + Assert::AreEqual("d", pgh.description.c_str()); + Assert::AreEqual(size_t(1), pgh.depends.size()); + Assert::AreEqual("bd", pgh.depends[0].c_str()); + } + + TEST_METHOD(BinaryParagraph_Three_Depends) + { + vcpkg::BinaryParagraph pgh({ + {"Package", "zlib"}, + {"Version", "1.2.8"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", "a, b, c"}, + }); + + Assert::AreEqual(size_t(3), pgh.depends.size()); + Assert::AreEqual("a", pgh.depends[0].c_str()); + Assert::AreEqual("b", pgh.depends[1].c_str()); + Assert::AreEqual("c", pgh.depends[2].c_str()); + } + + TEST_METHOD(parse_paragraphs_empty) + { + const char* str = ""; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::IsTrue(pghs.empty()); + } + + TEST_METHOD(parse_paragraphs_one_field) + { + const char* str = "f1: v1"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(1), pghs[0].size()); + Assert::AreEqual("v1", pghs[0]["f1"].c_str()); + } + + TEST_METHOD(parse_paragraphs_one_pgh) + { + const char* str = + "f1: v1\n" + "f2: v2"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(2), pghs[0].size()); + Assert::AreEqual("v1", pghs[0]["f1"].c_str()); + Assert::AreEqual("v2", pghs[0]["f2"].c_str()); + } + + TEST_METHOD(parse_paragraphs_two_pgh) + { + const char* str = + "f1: v1\n" + "f2: v2\n" + "\n" + "f3: v3\n" + "f4: v4"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(2), pghs.size()); + Assert::AreEqual(size_t(2), pghs[0].size()); + Assert::AreEqual("v1", pghs[0]["f1"].c_str()); + Assert::AreEqual("v2", pghs[0]["f2"].c_str()); + Assert::AreEqual(size_t(2), pghs[1].size()); + Assert::AreEqual("v3", pghs[1]["f3"].c_str()); + Assert::AreEqual("v4", pghs[1]["f4"].c_str()); + } + + TEST_METHOD(parse_paragraphs_field_names) + { + const char* str = + "1:\n" + "f:\n" + "F:\n" + "0:\n" + "F-2:\n"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(5), pghs[0].size()); + } + + TEST_METHOD(parse_paragraphs_multiple_blank_lines) + { + const char* str = + "f1: v1\n" + "f2: v2\n" + "\n" + "\n" + "f3: v3\n" + "f4: v4"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(2), pghs.size()); + } + + TEST_METHOD(parse_paragraphs_empty_fields) + { + const char* str = + "f1:\n" + "f2: "; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(2), pghs[0].size()); + Assert::AreEqual("", pghs[0]["f1"].c_str()); + Assert::AreEqual("", pghs[0]["f2"].c_str()); + Assert::AreEqual(size_t(2), pghs[0].size()); + } + + TEST_METHOD(parse_paragraphs_multiline_fields) + { + const char* str = + "f1: simple\n" + " f1\r\n" + "f2:\r\n" + " f2\r\n" + " continue\r\n"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual("simple\n f1", pghs[0]["f1"].c_str()); + Assert::AreEqual("\n f2\n continue", pghs[0]["f2"].c_str()); + } + + TEST_METHOD(parse_paragraphs_crlfs) + { + const char* str = + "f1: v1\r\n" + "f2: v2\r\n" + "\r\n" + "f3: v3\r\n" + "f4: v4"; + auto pghs = vcpkg::parse_paragraphs(str); + Assert::AreEqual(size_t(2), pghs.size()); + Assert::AreEqual(size_t(2), pghs[0].size()); + Assert::AreEqual("v1", pghs[0]["f1"].c_str()); + Assert::AreEqual("v2", pghs[0]["f2"].c_str()); + Assert::AreEqual(size_t(2), pghs[1].size()); + Assert::AreEqual("v3", pghs[1]["f3"].c_str()); + Assert::AreEqual("v4", pghs[1]["f4"].c_str()); + } + + TEST_METHOD(BinaryParagraph_serialize_min) + { + std::stringstream ss; + vcpkg::BinaryParagraph pgh({ + {"Package", "zlib"}, + {"Version", "1.2.8"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + }); + ss << pgh; + auto pghs = vcpkg::parse_paragraphs(ss.str()); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(4), pghs[0].size()); + Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); + Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str()); + Assert::AreEqual("x86-windows", pghs[0]["Architecture"].c_str()); + Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str()); + } + + TEST_METHOD(BinaryParagraph_serialize_max) + { + std::stringstream ss; + vcpkg::BinaryParagraph pgh({ + {"Package", "zlib"}, + {"Version", "1.2.8"}, + {"Architecture", "x86-windows"}, + {"Description", "first line\n second line"}, + {"Maintainer", "abc "}, + {"Depends", "dep"}, + {"Multi-Arch", "same"}, + }); + ss << pgh; + auto pghs = vcpkg::parse_paragraphs(ss.str()); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual(size_t(7), pghs[0].size()); + Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); + Assert::AreEqual("1.2.8", pghs[0]["Version"].c_str()); + Assert::AreEqual("x86-windows", pghs[0]["Architecture"].c_str()); + Assert::AreEqual("same", pghs[0]["Multi-Arch"].c_str()); + Assert::AreEqual("first line\n second line", pghs[0]["Description"].c_str()); + Assert::AreEqual("dep", pghs[0]["Depends"].c_str()); + } + + TEST_METHOD(BinaryParagraph_serialize_multiple_deps) + { + std::stringstream ss; + vcpkg::BinaryParagraph pgh({ + {"Package", "zlib"}, + {"Version", "1.2.8"}, + {"Architecture", "x86-windows"}, + {"Multi-Arch", "same"}, + {"Depends", "a, b, c"}, + }); + ss << pgh; + auto pghs = vcpkg::parse_paragraphs(ss.str()); + Assert::AreEqual(size_t(1), pghs.size()); + Assert::AreEqual("a, b, c", pghs[0]["Depends"].c_str()); + } + + TEST_METHOD(package_spec_parse) + { + vcpkg::expected spec = vcpkg::package_spec::from_string("zlib", vcpkg::triplet::X86_WINDOWS); + Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code())); + Assert::AreEqual("zlib", spec.get()->name().c_str()); + Assert::AreEqual(vcpkg::triplet::X86_WINDOWS.canonical_name(), spec.get()->target_triplet().canonical_name()); + } + + TEST_METHOD(package_spec_parse_with_arch) + { + vcpkg::expected spec = vcpkg::package_spec::from_string("zlib:x64-uwp", vcpkg::triplet::X86_WINDOWS); + Assert::AreEqual(vcpkg::package_spec_parse_result::SUCCESS, vcpkg::to_package_spec_parse_result(spec.error_code())); + Assert::AreEqual("zlib", spec.get()->name().c_str()); + Assert::AreEqual(vcpkg::triplet::X64_UWP.canonical_name(), spec.get()->target_triplet().canonical_name()); + } + + TEST_METHOD(package_spec_parse_with_multiple_colon) + { + auto ec = vcpkg::package_spec::from_string("zlib:x86-uwp:", vcpkg::triplet::X86_WINDOWS).error_code(); + Assert::AreEqual(vcpkg::package_spec_parse_result::TOO_MANY_COLONS, vcpkg::to_package_spec_parse_result(ec)); + } + + TEST_METHOD(utf8_to_utf16) + { + auto str = vcpkg::Strings::utf8_to_utf16("abc"); + Assert::AreEqual(L"abc", str.c_str()); + } + + TEST_METHOD(utf8_to_utf16_with_whitespace) + { + auto str = vcpkg::Strings::utf8_to_utf16("abc -x86-windows"); + Assert::AreEqual(L"abc -x86-windows", str.c_str()); + } + }; + + TEST_CLASS(Metrics) + { + }; +} diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index db6c03480..453ba81fd 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -8,6 +8,9 @@ namespace vcpkg {namespace Checks void unreachable() { System::println(System::color::error, "Error: Unreachable code was reached"); +#ifndef NDEBUG + std::abort(); +#endif exit(EXIT_FAILURE); } diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 54b37cd11..0e45b28dd 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -57,11 +57,9 @@ namespace vcpkg { namespace Dependencies return build_dependency_graph(paths, specs, status_db).find_topological_sort(); } - std::unordered_set find_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + std::unordered_set find_unmet_dependencies(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { - const Graphs::Graph dependency_graph = build_dependency_graph(paths, {spec}, status_db); - std::unordered_set key_set = Maps::extract_key_set(dependency_graph.adjacency_list()); - key_set.erase(spec); - return key_set; + const Graphs::Graph dependency_graph = build_dependency_graph(paths, specs, status_db); + return Maps::extract_key_set(dependency_graph.adjacency_list()); } }} diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 3d14d4b06..61dc4f4cc 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -45,37 +45,4 @@ namespace vcpkg {namespace details return value; } - std::vector parse_depends(const std::string& depends_string) - { - if (depends_string.empty()) - { - return {}; - } - - std::vector out; - - size_t cur = 0; - do - { - auto pos = depends_string.find(',', cur); - if (pos == std::string::npos) - { - out.push_back(depends_string.substr(cur)); - break; - } - out.push_back(depends_string.substr(cur, pos - cur)); - - // skip comma and space - ++pos; - if (depends_string[pos] == ' ') - { - ++pos; - } - - cur = pos; - } - while (cur != std::string::npos); - - return out; - } }} -- cgit v1.2.3 From a6821438bc63a35efc79b53588149271652ec5e3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 6 Nov 2016 20:12:21 -0800 Subject: Make parameter const --- toolsrc/src/commands_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index c90538e86..771b43507 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -51,7 +51,7 @@ namespace vcpkg } // At this point there is 1 argument - do_print(paths, [&](std::string& port_name) -> bool + do_print(paths, [&](const std::string& port_name) -> bool { return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); }); -- cgit v1.2.3 From e4cab414aee77b03140d0198ce8c0756c46b5c0a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Sun, 6 Nov 2016 20:12:54 -0800 Subject: Add new command: portsdiff --- toolsrc/src/commands_other.cpp | 1 + toolsrc/src/commands_portsdiff.cpp | 155 +++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 toolsrc/src/commands_portsdiff.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 148673afe..894beae27 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -86,6 +86,7 @@ namespace vcpkg {"import", import_command}, {"cache", cache_command}, {"internal_test", internal_test_command}, + {"portsdiff", portsdiff_command} }; return t; } diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp new file mode 100644 index 000000000..e15db3567 --- /dev/null +++ b/toolsrc/src/commands_portsdiff.cpp @@ -0,0 +1,155 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" +#include "vcpkg.h" +#include +#include +#include "vcpkg_Maps.h" +#include +#include +#include + +namespace vcpkg +{ + static void do_print_name_and_version(const std::vector& ports_to_print, const std::map& names_and_versions) + { + for (const std::string& name : ports_to_print) + { + const std::string& version = names_and_versions.at(name); + std::cout << std::left + << std::setw(20) << name << ' ' + << std::setw(16) << version << ' ' + << '\n'; + } + } + + static void do_print_name_and_previous_version_and_current_version(const std::vector& ports_to_print, + const std::map& previous_names_and_versions, + const std::map& current_names_and_versions) + { + for (const std::string& name : ports_to_print) + { + if (name == "") + { + continue; + } + + const std::string& previous_version = previous_names_and_versions.at(name); + const std::string& current_version = current_names_and_versions.at(name); + std::cout << std::left + << std::setw(20) << name << ' ' + << std::setw(16) << previous_version << " -> " << current_version + << '\n'; + } + } + + static std::map read_all_ports(const fs::path& ports_folder_path) + { + std::map names_and_versions; + + for (auto it = fs::directory_iterator(ports_folder_path); it != fs::directory_iterator(); ++it) + { + const fs::path& path = it->path(); + + try + { + auto pghs = get_paragraphs(path / "CONTROL"); + if (pghs.empty()) + continue; + auto srcpgh = SourceParagraph(pghs[0]); + names_and_versions.emplace(srcpgh.name, srcpgh.version); + } + catch (std::runtime_error const&) + { + } + } + + return names_and_versions; + } + + static std::map read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id) + { + 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); + fs::create_directory(temp_checkout_path); + 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"(git --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & git reset >NUL)", + dot_git_dir.native(), + temp_checkout_path.native(), + git_commit_id, + checkout_this_dir, + L".vcpkg-root"); + System::cmd_execute(cmd); + std::map names_and_versions = read_all_ports(temp_checkout_path / ports_dir_name_as_string); + fs::remove_all(temp_checkout_path); + return names_and_versions; + } + + void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + { + static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", create_example_string("portsdiff mybranchname")); + args.check_min_arg_count(1, example.c_str()); + args.check_max_arg_count(2, example.c_str()); + 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::map current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot); + const std::map 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 current_ports = Maps::extract_keys(current_names_and_versions); + std::vector previous_ports = Maps::extract_keys(previous_names_and_versions); + + std::vector added_ports; + std::set_difference( + current_ports.cbegin(), current_ports.cend(), + previous_ports.cbegin(), previous_ports.cend(), + std::back_inserter(added_ports)); + + if (!added_ports.empty()) + { + System::println("\nThe following %d ports were added:\n", added_ports.size()); + do_print_name_and_version(added_ports, current_names_and_versions); + } + + std::vector removed_ports; + std::set_difference( + previous_ports.cbegin(), previous_ports.cend(), + current_ports.cbegin(), current_ports.cend(), + std::back_inserter(removed_ports)); + + if (!removed_ports.empty()) + { + System::println("\nThe following %d ports were removed:\n", removed_ports.size()); + do_print_name_and_version(removed_ports, previous_names_and_versions); + } + + std::vector potentially_updated_ports; + std::set_intersection( + current_ports.cbegin(), current_ports.cend(), + previous_ports.cbegin(), previous_ports.cend(), + std::back_inserter(potentially_updated_ports)); + + std::vector updated_ports; + std::copy_if(potentially_updated_ports.cbegin(), potentially_updated_ports.cend(), std::back_inserter(updated_ports), + [&](const std::string& port) -> bool + { + return current_names_and_versions.at(port) != previous_names_and_versions.at(port); + } + ); + + if (!updated_ports.empty()) + { + System::println("\nThe following %d ports were updated:\n", updated_ports.size()); + do_print_name_and_previous_version_and_current_version(updated_ports, previous_names_and_versions, current_names_and_versions); + } + + if (added_ports.empty() && removed_ports.empty() && updated_ports.empty()) + { + System::println("There were no changes in the ports between the two commits."); + } + + exit(EXIT_SUCCESS); + } +} -- cgit v1.2.3 From 331ac16736b9698c0fed9e5cbd38ef9322b9a824 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 13:43:36 -0800 Subject: Make lambda arg const --- toolsrc/src/commands_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 771b43507..2eb35b223 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -43,7 +43,7 @@ namespace vcpkg if (args.command_arguments.size() == 0) { - do_print(paths, [](std::string&) -> bool + do_print(paths, [](const std::string&) -> bool { return true; }); -- cgit v1.2.3 From 8f162188ddef5841f50250ef92bf629eac512650 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 13:44:20 -0800 Subject: Add simple substring filtering to `vcpkg cache`, like `vcpkg search` --- toolsrc/src/commands_cache.cpp | 61 +++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 0d70f0f29..53518264e 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -5,34 +5,65 @@ namespace vcpkg { - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + template + static void do_print(const vcpkg_paths& paths, Pred predicate) { - args.check_exact_arg_count(0); - - auto begin_it = fs::directory_iterator(paths.packages); - auto end_it = fs::directory_iterator(); + auto it = fs::directory_iterator(paths.packages); + const fs::directory_iterator end_it = fs::directory_iterator(); - if (begin_it == end_it) + if (it == end_it) { System::println("No packages are cached."); exit(EXIT_SUCCESS); } - for (; begin_it != end_it; ++begin_it) + for (; it != end_it; ++it) { - const auto& path = begin_it->path(); + const fs::path& path = it->path(); - auto file_contents = Files::get_contents(path / "CONTROL"); - if (auto text = file_contents.get()) + try { - auto pghs = parse_paragraphs(*text); - if (pghs.size() != 1) - continue; + auto file_contents = Files::get_contents(path / "CONTROL"); + if (auto text = file_contents.get()) + { + auto pghs = parse_paragraphs(*text); + if (pghs.size() != 1) + continue; - auto src = BinaryParagraph(pghs[0]); - System::println(src.displayname().c_str()); + const BinaryParagraph src = BinaryParagraph(pghs[0]); + const std::string displayname = src.displayname(); + if (predicate(displayname)) + { + System::println(displayname.c_str()); + } + } + } + catch (std::runtime_error const&) + { } } + } + + void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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", create_example_string("cache png")); + args.check_max_arg_count(1, example.c_str()); + + if (args.command_arguments.size() == 0) + { + do_print(paths, [](const std::string&) -> bool + { + return true; + }); + exit(EXIT_SUCCESS); + } + + // At this point there is 1 argument + do_print(paths, [&](const std::string& port_name) -> bool + { + return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); + }); exit(EXIT_SUCCESS); } -- cgit v1.2.3 From c2a6ed412bd6cfa95a263a9ed42dd352d3a8551c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 13:57:52 -0800 Subject: Rework `vcpkg search` implementation --- toolsrc/src/commands_search.cpp | 54 ++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 2eb35b223..267f9a3d4 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -8,9 +8,9 @@ namespace fs = std::tr2::sys; namespace vcpkg { - template - static void do_print(const vcpkg_paths& paths, Pred predicate) + static std::vector read_all_source_paragraphs(const vcpkg_paths& paths) { + std::vector output; for (auto it = fs::directory_iterator(paths.ports); it != fs::directory_iterator(); ++it) { const fs::path& path = it->path(); @@ -19,21 +19,27 @@ namespace vcpkg { auto pghs = get_paragraphs(path / "CONTROL"); if (pghs.empty()) - continue; - auto srcpgh = SourceParagraph(pghs[0]); - - if (predicate(srcpgh.name)) { - std::cout << std::left - << std::setw(20) << srcpgh.name << ' ' - << std::setw(16) << srcpgh.version << ' ' - << shorten_description(srcpgh.description) << '\n'; + continue; } + + auto srcpgh = SourceParagraph(pghs[0]); + output.push_back(srcpgh); } catch (std::runtime_error const&) { } } + + return output; + } + + static void do_print(const SourceParagraph& source_paragraph) + { + std::cout << std::left + << std::setw(20) << source_paragraph.name << ' ' + << std::setw(16) << source_paragraph.version << ' ' + << shorten_description(source_paragraph.description) << '\n'; } void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) @@ -41,20 +47,28 @@ namespace vcpkg 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", create_example_string("search png")); args.check_max_arg_count(1, example.c_str()); + const std::vector source_paragraphs = read_all_source_paragraphs(paths); + if (args.command_arguments.size() == 0) { - do_print(paths, [](const std::string&) -> bool - { - return true; - }); - exit(EXIT_SUCCESS); + for (const SourceParagraph& source_paragraph : source_paragraphs) + { + do_print(source_paragraph); + } } + else + { + // 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()) + { + continue; + } - // At this point there is 1 argument - do_print(paths, [&](const std::string& port_name) -> bool - { - return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); - }); + do_print(source_paragraph); + } + } System::println("\nIf your library is not listed, please open an issue at:\n" " https://github.com/Microsoft/vcpkg/issues"); -- cgit v1.2.3 From 7e05c53628e686e5e2aa39e185789c2b6146f35b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 14:06:51 -0800 Subject: Rework `vcpkg cache` implementation --- toolsrc/src/commands_cache.cpp | 60 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 53518264e..5e20a39af 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -5,19 +5,10 @@ namespace vcpkg { - template - static void do_print(const vcpkg_paths& paths, Pred predicate) + static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { - auto it = fs::directory_iterator(paths.packages); - const fs::directory_iterator end_it = fs::directory_iterator(); - - if (it == end_it) - { - System::println("No packages are cached."); - exit(EXIT_SUCCESS); - } - - for (; it != end_it; ++it) + std::vector output; + for (auto it = fs::directory_iterator(paths.packages); it != fs::directory_iterator(); ++it) { const fs::path& path = it->path(); @@ -30,18 +21,16 @@ namespace vcpkg if (pghs.size() != 1) continue; - const BinaryParagraph src = BinaryParagraph(pghs[0]); - const std::string displayname = src.displayname(); - if (predicate(displayname)) - { - System::println(displayname.c_str()); - } + const BinaryParagraph binary_paragraph = BinaryParagraph(pghs[0]); + output.push_back(binary_paragraph); } } catch (std::runtime_error const&) { } } + + return output; } void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) @@ -50,20 +39,35 @@ namespace vcpkg "The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", create_example_string("cache png")); args.check_max_arg_count(1, example.c_str()); - if (args.command_arguments.size() == 0) + const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); + if (binary_paragraphs.empty()) { - do_print(paths, [](const std::string&) -> bool - { - return true; - }); + System::println("No packages are cached."); exit(EXIT_SUCCESS); } - // At this point there is 1 argument - do_print(paths, [&](const std::string& port_name) -> bool - { - return Strings::case_insensitive_ascii_find(port_name, args.command_arguments[0]) != port_name.end(); - }); + if (args.command_arguments.size() == 0) + { + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) + { + const std::string displayname = binary_paragraph.displayname(); + System::println(displayname.c_str()); + } + } + else + { + // At this point there is 1 argument + for (const BinaryParagraph& binary_paragraph : binary_paragraphs) + { + const std::string displayname = binary_paragraph.displayname(); + if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) + { + continue; + } + + System::println(displayname.c_str()); + } + } exit(EXIT_SUCCESS); } -- cgit v1.2.3 From 45eee10708a97a90566af8ab7d781e89b255055b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 14:39:52 -0800 Subject: Add simple substring filtering to `vcpkg list` --- toolsrc/src/commands_list.cpp | 58 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 194e4b435..87aad1991 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -4,29 +4,63 @@ namespace vcpkg { + static void do_print(const StatusParagraph& pgh) + { + System::println("%-27s %-16s %s", + pgh.package.displayname(), + pgh.package.version, + shorten_description(pgh.package.description)); + } + void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - args.check_exact_arg_count(0); + 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", create_example_string("list png")); + args.check_max_arg_count(1, example.c_str()); - std::vector packages_output; - for (auto&& pgh : database_load_check(paths)) + const StatusParagraphs status_paragraphs = database_load_check(paths); + std::vector installed_packages; + for (auto&& pgh : status_paragraphs) { if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) continue; - packages_output.push_back(Strings::format("%-27s %-16s %s", - pgh->package.displayname(), - pgh->package.version, - shorten_description(pgh->package.description))); + installed_packages.push_back(*pgh); + } + + if (installed_packages.empty()) + { + System::println("No packages are installed. Did you mean `search`?"); + exit(EXIT_SUCCESS); } - std::sort(packages_output.begin(), packages_output.end()); - for (auto&& package : packages_output) + + std::sort(installed_packages.begin(), installed_packages.end(), + [ ]( const StatusParagraph& lhs, const StatusParagraph& rhs ) -> bool + { + return lhs.package.displayname() < rhs.package.displayname(); + }); + + if (args.command_arguments.size() == 0) { - System::println(package.c_str()); + for (const StatusParagraph& status_paragraph : installed_packages) + { + do_print(status_paragraph); + } } - if (packages_output.empty()) + else { - System::println("No packages are installed. Did you mean `search`?"); + // At this point there is 1 argument + for (const StatusParagraph& status_paragraph : installed_packages) + { + const std::string displayname = status_paragraph.package.displayname(); + if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end()) + { + continue; + } + + do_print(status_paragraph); + } } + exit(EXIT_SUCCESS); } } -- cgit v1.2.3 From b81d1910dbd731326ce2d31db134820c14acdc76 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 14:42:25 -0800 Subject: [vcpkg search] Use System::println() instead of iostream + iomanip --- toolsrc/src/commands_search.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 267f9a3d4..d59a338ac 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,8 +1,6 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg.h" -#include -#include namespace fs = std::tr2::sys; @@ -36,10 +34,10 @@ namespace vcpkg static void do_print(const SourceParagraph& source_paragraph) { - std::cout << std::left - << std::setw(20) << source_paragraph.name << ' ' - << std::setw(16) << source_paragraph.version << ' ' - << shorten_description(source_paragraph.description) << '\n'; + System::println("%-20s %-16s %s", + source_paragraph.name, + source_paragraph.version, + shorten_description(source_paragraph.description)); } void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) -- cgit v1.2.3 From a721db2c1fbfc1b87065b0b43e32249117e53242 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:06:36 -0800 Subject: Refactor: create new Paragraphs.h/cpp --- toolsrc/src/Paragraphs.cpp | 163 +++++++++++++++++++++++++++++++++ toolsrc/src/commands_cache.cpp | 3 +- toolsrc/src/commands_import.cpp | 3 +- toolsrc/src/commands_installation.cpp | 5 +- toolsrc/src/commands_portsdiff.cpp | 3 +- toolsrc/src/commands_search.cpp | 3 +- toolsrc/src/commands_update.cpp | 3 +- toolsrc/src/lib.cpp | 9 +- toolsrc/src/main.cpp | 3 +- toolsrc/src/tests_paragraph.cpp | 32 +++---- toolsrc/src/vcpkg.cpp | 165 ---------------------------------- 11 files changed, 199 insertions(+), 193 deletions(-) create mode 100644 toolsrc/src/Paragraphs.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp new file mode 100644 index 000000000..5efa9a7b3 --- /dev/null +++ b/toolsrc/src/Paragraphs.cpp @@ -0,0 +1,163 @@ +#include "Paragraphs.h" +#include "vcpkg_Files.h" + +namespace vcpkg { namespace Paragraphs +{ + struct Parser + { + Parser(const char* c, const char* e) : cur(c), end(e) + { + } + + private: + const char* cur; + const char* const end; + + void peek(char& ch) const + { + if (cur == end) + ch = 0; + else + ch = *cur; + } + + void next(char& ch) + { + if (cur == end) + ch = 0; + else + { + ++cur; + peek(ch); + } + } + + void skip_spaces(char& ch) + { + while (ch == ' ' || ch == '\t') + next(ch); + } + + static bool is_alphanum(char ch) + { + return (ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || (ch >= '0' && ch <= '9'); + } + + static bool is_lineend(char ch) + { + return ch == '\r' || ch == '\n' || ch == 0; + } + + void get_fieldvalue(char& ch, std::string& fieldvalue) + { + fieldvalue.clear(); + + auto beginning_of_line = cur; + do + { + // scan to end of current line (it is part of the field value) + while (!is_lineend(ch)) + next(ch); + + fieldvalue.append(beginning_of_line, cur); + + if (ch == '\r') + next(ch); + if (ch == '\n') + next(ch); + + if (is_alphanum(ch)) + { + // Line begins a new field. + return; + } + + beginning_of_line = cur; + + // Line may continue the current field with data or terminate the paragraph, + // depending on first nonspace character. + skip_spaces(ch); + + if (is_lineend(ch)) + { + // Line was whitespace or empty. + // This terminates the field and the paragraph. + // We leave the blank line's whitespace consumed, because it doesn't matter. + return; + } + + // 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); + } + + void get_fieldname(char& ch, std::string& fieldname) + { + auto begin_fieldname = cur; + while (is_alphanum(ch) || ch == '-') + next(ch); + Checks::check_throw(ch == ':', "Expected ':'"); + fieldname = std::string(begin_fieldname, cur); + + // skip ': ' + next(ch); + skip_spaces(ch); + } + + void get_paragraph(char& ch, std::unordered_map& fields) + { + fields.clear(); + std::string fieldname; + std::string fieldvalue; + do + { + get_fieldname(ch, fieldname); + + auto it = fields.find(fieldname); + Checks::check_throw(it == fields.end(), "Duplicate field"); + + get_fieldvalue(ch, fieldvalue); + + fields.emplace(fieldname, fieldvalue); + } + while (!is_lineend(ch)); + } + + public: + std::vector> get_paragraphs() + { + std::vector> paragraphs; + + char ch; + peek(ch); + + while (ch != 0) + { + if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') + { + next(ch); + continue; + } + + paragraphs.emplace_back(); + get_paragraph(ch, paragraphs.back()); + } + + return paragraphs; + } + }; + + std::vector> get_paragraphs(const fs::path& control_path) + { + return parse_paragraphs(Files::get_contents(control_path).get_or_throw()); + } + + std::vector> parse_paragraphs(const std::string& str) + { + return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); + } +}} diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 5e20a39af..634a72a64 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -2,6 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" #include "vcpkg.h" +#include "Paragraphs.h" namespace vcpkg { @@ -17,7 +18,7 @@ namespace vcpkg auto file_contents = Files::get_contents(path / "CONTROL"); if (auto text = file_contents.get()) { - auto pghs = parse_paragraphs(*text); + auto pghs = Paragraphs::parse_paragraphs(*text); if (pghs.size() != 1) continue; diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 9cfc53d6c..7a6139085 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -1,5 +1,6 @@ #include "vcpkg_Commands.h" #include "vcpkg.h" +#include "Paragraphs.h" namespace vcpkg { @@ -12,7 +13,7 @@ namespace vcpkg const fs::path include_directory(args.command_arguments[1]); const fs::path project_directory(args.command_arguments[2]); - auto pghs = get_paragraphs(control_file_path); + auto pghs = Paragraphs::get_paragraphs(control_file_path); Checks::check_throw(pghs.size() == 1, "Invalid control file for package"); StatusParagraph spgh; diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index f6aeafa02..b5f4e1a5d 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -9,6 +9,7 @@ #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" #include "vcpkg_Maps.h" +#include "Paragraphs.h" namespace vcpkg { @@ -21,7 +22,7 @@ namespace vcpkg static void build_internal(const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { - auto pghs = get_paragraphs(port_dir / "CONTROL"); + auto pghs = Paragraphs::get_paragraphs(port_dir / "CONTROL"); Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); SourceParagraph source_paragraph(pghs[0]); @@ -111,7 +112,7 @@ namespace vcpkg } } - auto pghs = parse_paragraphs(file_contents.get_or_throw()); + auto pghs = Paragraphs::parse_paragraphs(file_contents.get_or_throw()); Checks::check_throw(pghs.size() == 1, "multiple paragraphs in control file"); install_package(paths, BinaryParagraph(pghs[0]), status_db); System::println(System::color::success, "Package %s is installed", spec); diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index e15db3567..fdbaec0ac 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "Paragraphs.h" namespace vcpkg { @@ -52,7 +53,7 @@ namespace vcpkg try { - auto pghs = get_paragraphs(path / "CONTROL"); + auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); if (pghs.empty()) continue; auto srcpgh = SourceParagraph(pghs[0]); diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index d59a338ac..399709cf3 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,6 +1,7 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg.h" +#include "Paragraphs.h" namespace fs = std::tr2::sys; @@ -15,7 +16,7 @@ namespace vcpkg try { - auto pghs = get_paragraphs(path / "CONTROL"); + auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); if (pghs.empty()) { continue; diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 5d531ef39..b448091f7 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -2,6 +2,7 @@ #include "vcpkg.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" +#include "Paragraphs.h" namespace vcpkg { @@ -21,7 +22,7 @@ namespace vcpkg const auto& path = begin_it->path(); try { - auto pghs = get_paragraphs(path / "CONTROL"); + auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); if (pghs.empty()) continue; auto srcpgh = SourceParagraph(pghs[0]); diff --git a/toolsrc/src/lib.cpp b/toolsrc/src/lib.cpp index 3c844ac3f..5de9f9639 100644 --- a/toolsrc/src/lib.cpp +++ b/toolsrc/src/lib.cpp @@ -11,6 +11,7 @@ #include #include "vcpkg_Files.h" #include "vcpkg_System.h" +#include "Paragraphs.h" using namespace vcpkg; @@ -51,7 +52,7 @@ static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_f } auto text = Files::get_contents(vcpkg_dir_status_file).get_or_throw(); - auto pghs = parse_paragraphs(text); + auto pghs = Paragraphs::parse_paragraphs(text); std::vector> status_pghs; for (auto&& p : pghs) @@ -94,7 +95,7 @@ StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) continue; auto text = Files::get_contents(b->path()).get_or_throw(); - auto pghs = parse_paragraphs(text); + auto pghs = Paragraphs::parse_paragraphs(text); for (auto&& p : pghs) { current_status_db.insert(std::make_unique(p)); @@ -217,7 +218,7 @@ std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths std::vector> pghs; try { - pghs = parse_paragraphs(*control_contents); + pghs = Paragraphs::parse_paragraphs(*control_contents); } catch (std::runtime_error) { @@ -238,7 +239,7 @@ std::vector vcpkg::get_unmet_package_build_dependencies(const vcpkg std::vector> pghs; try { - pghs = parse_paragraphs(*control_contents); + pghs = Paragraphs::parse_paragraphs(*control_contents); } catch (std::runtime_error) { diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 2200cd105..22c45e5ab 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -12,6 +12,7 @@ #include "vcpkg_Files.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" +#include "Paragraphs.h" using namespace vcpkg; @@ -115,7 +116,7 @@ static void loadConfig() std::string config_contents = Files::get_contents(localappdata / "vcpkg" / "config").get_or_throw(); std::unordered_map keys; - auto pghs = parse_paragraphs(config_contents); + auto pghs = Paragraphs::parse_paragraphs(config_contents); if (pghs.size() > 0) keys = pghs[0]; diff --git a/toolsrc/src/tests_paragraph.cpp b/toolsrc/src/tests_paragraph.cpp index b06359b90..28309fd31 100644 --- a/toolsrc/src/tests_paragraph.cpp +++ b/toolsrc/src/tests_paragraph.cpp @@ -1,5 +1,6 @@ #include "CppUnitTest.h" #include "vcpkg.h" +#include "Paragraphs.h" #pragma comment(lib,"version") #pragma comment(lib,"winhttp") @@ -81,9 +82,9 @@ namespace UnitTest1 TEST_METHOD(SourceParagraph_Construct_Qualified_Depends) { vcpkg::SourceParagraph pgh({ - { "Source", "zlib" }, - { "Version", "1.2.8" }, - { "Build-Depends", "libA [windows], libB [uwp]" } + {"Source", "zlib"}, + {"Version", "1.2.8"}, + {"Build-Depends", "libA [windows], libB [uwp]"} }); Assert::AreEqual("zlib", pgh.name.c_str()); @@ -97,7 +98,6 @@ namespace UnitTest1 Assert::AreEqual("uwp", pgh.depends[1].qualifier.c_str()); } - TEST_METHOD(BinaryParagraph_Construct_Minimum) { vcpkg::BinaryParagraph pgh({ @@ -153,14 +153,14 @@ namespace UnitTest1 TEST_METHOD(parse_paragraphs_empty) { const char* str = ""; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::IsTrue(pghs.empty()); } TEST_METHOD(parse_paragraphs_one_field) { const char* str = "f1: v1"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(1), pghs[0].size()); Assert::AreEqual("v1", pghs[0]["f1"].c_str()); @@ -171,7 +171,7 @@ namespace UnitTest1 const char* str = "f1: v1\n" "f2: v2"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(2), pghs[0].size()); Assert::AreEqual("v1", pghs[0]["f1"].c_str()); @@ -186,7 +186,7 @@ namespace UnitTest1 "\n" "f3: v3\n" "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(2), pghs.size()); Assert::AreEqual(size_t(2), pghs[0].size()); Assert::AreEqual("v1", pghs[0]["f1"].c_str()); @@ -204,7 +204,7 @@ namespace UnitTest1 "F:\n" "0:\n" "F-2:\n"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(5), pghs[0].size()); } @@ -218,7 +218,7 @@ namespace UnitTest1 "\n" "f3: v3\n" "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(2), pghs.size()); } @@ -227,7 +227,7 @@ namespace UnitTest1 const char* str = "f1:\n" "f2: "; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(2), pghs[0].size()); Assert::AreEqual("", pghs[0]["f1"].c_str()); @@ -243,7 +243,7 @@ namespace UnitTest1 "f2:\r\n" " f2\r\n" " continue\r\n"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual("simple\n f1", pghs[0]["f1"].c_str()); Assert::AreEqual("\n f2\n continue", pghs[0]["f2"].c_str()); @@ -257,7 +257,7 @@ namespace UnitTest1 "\r\n" "f3: v3\r\n" "f4: v4"; - auto pghs = vcpkg::parse_paragraphs(str); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(str); Assert::AreEqual(size_t(2), pghs.size()); Assert::AreEqual(size_t(2), pghs[0].size()); Assert::AreEqual("v1", pghs[0]["f1"].c_str()); @@ -277,7 +277,7 @@ namespace UnitTest1 {"Multi-Arch", "same"}, }); ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(4), pghs[0].size()); Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); @@ -299,7 +299,7 @@ namespace UnitTest1 {"Multi-Arch", "same"}, }); ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual(size_t(7), pghs[0].size()); Assert::AreEqual("zlib", pghs[0]["Package"].c_str()); @@ -321,7 +321,7 @@ namespace UnitTest1 {"Depends", "a, b, c"}, }); ss << pgh; - auto pghs = vcpkg::parse_paragraphs(ss.str()); + auto pghs = vcpkg::Paragraphs::parse_paragraphs(ss.str()); Assert::AreEqual(size_t(1), pghs.size()); Assert::AreEqual("a, b, c", pghs[0]["Depends"].c_str()); } diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index f705858cc..a9ef963e7 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -1,160 +1,5 @@ #include "vcpkg.h" #include -#include "vcpkg_Files.h" -#include "vcpkglib_helpers.h" - -namespace -{ - using namespace vcpkg; - - struct Parser - { - Parser(const char* c, const char* e) : cur(c), end(e) - { - } - - private: - const char* cur; - const char* const end; - - void peek(char& ch) const - { - if (cur == end) - ch = 0; - else - ch = *cur; - } - - void next(char& ch) - { - if (cur == end) - ch = 0; - else - { - ++cur; - peek(ch); - } - } - - void skip_spaces(char& ch) - { - while (ch == ' ' || ch == '\t') - next(ch); - } - - static bool is_alphanum(char ch) - { - return (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z') - || (ch >= '0' && ch <= '9'); - } - - static bool is_lineend(char ch) - { - return ch == '\r' || ch == '\n' || ch == 0; - } - - void get_fieldvalue(char& ch, std::string& fieldvalue) - { - fieldvalue.clear(); - - auto beginning_of_line = cur; - do - { - // scan to end of current line (it is part of the field value) - while (!is_lineend(ch)) - next(ch); - - fieldvalue.append(beginning_of_line, cur); - - if (ch == '\r') - next(ch); - if (ch == '\n') - next(ch); - - if (is_alphanum(ch)) - { - // Line begins a new field. - return; - } - - beginning_of_line = cur; - - // Line may continue the current field with data or terminate the paragraph, - // depending on first nonspace character. - skip_spaces(ch); - - if (is_lineend(ch)) - { - // Line was whitespace or empty. - // This terminates the field and the paragraph. - // We leave the blank line's whitespace consumed, because it doesn't matter. - return; - } - - // 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); - } - - void get_fieldname(char& ch, std::string& fieldname) - { - auto begin_fieldname = cur; - while (is_alphanum(ch) || ch == '-') - next(ch); - Checks::check_throw(ch == ':', "Expected ':'"); - fieldname = std::string(begin_fieldname, cur); - - // skip ': ' - next(ch); - skip_spaces(ch); - } - - void get_paragraph(char& ch, std::unordered_map& fields) - { - fields.clear(); - std::string fieldname; - std::string fieldvalue; - do - { - get_fieldname(ch, fieldname); - - auto it = fields.find(fieldname); - Checks::check_throw(it == fields.end(), "Duplicate field"); - - get_fieldvalue(ch, fieldvalue); - - fields.emplace(fieldname, fieldvalue); - } - while (!is_lineend(ch)); - } - - public: - std::vector> get_paragraphs() - { - std::vector> paragraphs; - - char ch; - peek(ch); - - while (ch != 0) - { - if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') - { - next(ch); - continue; - } - - paragraphs.emplace_back(); - get_paragraph(ch, paragraphs.back()); - } - - return paragraphs; - } - }; -} namespace vcpkg { @@ -165,14 +10,4 @@ namespace vcpkg simple_desc.append("..."); return simple_desc; } - - std::vector> get_paragraphs(const fs::path& control_path) - { - return parse_paragraphs(Files::get_contents(control_path).get_or_throw()); - } - - std::vector> parse_paragraphs(const std::string& str) - { - return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); - } } -- cgit v1.2.3 From 058cbaf459e48b395cf170a9589f36b75a95c7bd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:10:41 -0800 Subject: Merge lib.cpp and vcpkg.cpp -> vcpkg.cpp --- toolsrc/src/lib.cpp | 516 ------------------------------------------------- toolsrc/src/vcpkg.cpp | 524 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 518 insertions(+), 522 deletions(-) delete mode 100644 toolsrc/src/lib.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/lib.cpp b/toolsrc/src/lib.cpp deleted file mode 100644 index 5de9f9639..000000000 --- a/toolsrc/src/lib.cpp +++ /dev/null @@ -1,516 +0,0 @@ -#include "vcpkg.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vcpkg_Files.h" -#include "vcpkg_System.h" -#include "Paragraphs.h" - -using namespace vcpkg; - -bool vcpkg::g_do_dry_run = false; - -namespace -{ - template - auto find_or_default(const M& map, const K& key, const V& val) - { - auto it = map.find(key); - if (it == map.end()) - return decltype(it->second)(val); - else - return it->second; - } -} - -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)) - { - if (!fs::exists(vcpkg_dir_status_file_old)) - { - // no status file, use empty db - return StatusParagraphs(); - } - - fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); - } - - auto text = Files::get_contents(vcpkg_dir_status_file).get_or_throw(); - auto pghs = Paragraphs::parse_paragraphs(text); - - std::vector> status_pghs; - for (auto&& p : pghs) - { - status_pghs.push_back(std::make_unique(p)); - } - - return StatusParagraphs(std::move(status_pghs)); -} - -StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) -{ - auto updates_dir = paths.vcpkg_dir_updates; - - std::error_code ec; - fs::create_directory(paths.installed, ec); - fs::create_directory(paths.vcpkg_dir, ec); - fs::create_directory(paths.vcpkg_dir_info, ec); - fs::create_directory(updates_dir, ec); - - const fs::path& status_file = paths.vcpkg_dir_status_file; - const fs::path status_file_old = status_file.parent_path() / "status-old"; - const fs::path status_file_new = status_file.parent_path() / "status-new"; - - StatusParagraphs current_status_db = load_current_database(status_file, status_file_old); - - auto b = fs::directory_iterator(updates_dir); - auto e = fs::directory_iterator(); - if (b == e) - { - // updates directory is empty, control file is up-to-date. - return current_status_db; - } - - for (; b != e; ++b) - { - if (!fs::is_regular_file(b->status())) - continue; - if (b->path().filename() == "incomplete") - continue; - - auto text = Files::get_contents(b->path()).get_or_throw(); - auto pghs = Paragraphs::parse_paragraphs(text); - for (auto&& p : pghs) - { - current_status_db.insert(std::make_unique(p)); - } - } - - std::fstream(status_file_new, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc) << current_status_db; - - if (fs::exists(status_file_old)) - fs::remove(status_file_old); - if (fs::exists(status_file)) - fs::rename(status_file, status_file_old); - fs::rename(status_file_new, status_file); - fs::remove(status_file_old); - - b = fs::directory_iterator(updates_dir); - for (; b != e; ++b) - { - if (!fs::is_regular_file(b->status())) - continue; - fs::remove(b->path()); - } - - return current_status_db; -} - -static fs::path listfile_path(const vcpkg_paths& paths, const BinaryParagraph& pgh) -{ - return paths.vcpkg_dir_info / (pgh.fullstem() + ".list"); -} - -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; -} - -static void write_update(const vcpkg_paths& paths, const StatusParagraph& p) -{ - static int update_id = 0; - auto my_update_id = update_id++; - auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete"; - auto update_filename = paths.vcpkg_dir_updates / std::to_string(my_update_id); - std::fstream fs(tmp_update_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); - fs << p; - fs.close(); - fs::rename(tmp_update_filename, update_filename); -} - -static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) -{ - std::fstream listfile(listfile_path(paths, 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 auto& filename = it->path().filename(); - if (fs::is_regular_file(it->status()) && (filename == "CONTROL" || filename == "control")) - { - // 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(); -} - -// TODO: Refactoring between this function and install_package -std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) -{ - const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; - - auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); - return BinaryParagraph(pghs[0]).depends; - } - - return get_unmet_package_build_dependencies(paths, spec, status_db); -} - -std::vector vcpkg::get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) -{ - const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; - auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); - return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); - } - - Checks::exit_with_message("Could not find package named %s", spec); -} - -void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) -{ - 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(listfile_path(paths, 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(listfile_path(paths, 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 vcpkg::search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) -{ - std::string line; - - for (auto&& pgh : status_db) - { - if (pgh->state != install_state_t::installed) - continue; - - std::fstream listfile(listfile_path(paths, pgh->package)); - while (std::getline(listfile, line)) - { - if (line.empty()) - { - continue; - } - - if (line.find(file_substr) != std::string::npos) - { - System::println("%s: %s", pgh->package.displayname(), line); - } - } - } -} - -namespace -{ - struct Binaries - { - std::vector dlls; - std::vector libs; - }; - - Binaries detect_files_in_directory_ending_with(const fs::path& path) - { - Files::check_is_directory(path); - - Binaries binaries; - - for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); ++it) - { - fs::path file = *it; - // Skip if directory ????? - if (file.extension() == ".dll") - { - binaries.dlls.push_back(file); - } - else if (file.extension() == ".lib") - { - binaries.libs.push_back(file); - } - } - - return binaries; - } - - void copy_files_into_directory(const std::vector& files, const fs::path& destination_folder) - { - fs::create_directory(destination_folder); - - for (auto const& src_path : files) - { - fs::path dest_path = destination_folder / src_path.filename(); - fs::copy(src_path, dest_path, fs::copy_options::overwrite_existing); - } - } - - void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) - { - Files::check_is_directory(include_directory); - Files::check_is_directory(project_directory); - Files::check_is_directory(destination_path); - Binaries debug_binaries = detect_files_in_directory_ending_with(project_directory / "Debug"); - Binaries release_binaries = detect_files_in_directory_ending_with(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); - - copy_files_into_directory(release_binaries.dlls, destination_path / "bin"); - copy_files_into_directory(release_binaries.libs, destination_path / "lib"); - - fs::create_directory(destination_path / "debug"); - copy_files_into_directory(debug_binaries.dlls, destination_path / "debug" / "bin"); - copy_files_into_directory(debug_binaries.libs, destination_path / "debug" / "lib"); - } -} - -void vcpkg::binary_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) -{ - fs::path library_destination_path = paths.package_dir(control_file_data.spec); - fs::create_directory(library_destination_path); - place_library_files_in(include_directory, project_directory, library_destination_path); - - fs::path control_file_path = library_destination_path / "CONTROL"; - std::ofstream(control_file_path) << control_file_data; -} diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index a9ef963e7..560df8dcb 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -1,13 +1,525 @@ #include "vcpkg.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vcpkg_Files.h" +#include "vcpkg_System.h" +#include "Paragraphs.h" #include -namespace vcpkg +using namespace vcpkg; + +bool vcpkg::g_do_dry_run = false; + +namespace +{ + template + auto find_or_default(const M& map, const K& key, const V& val) + { + auto it = map.find(key); + if (it == map.end()) + return decltype(it->second)(val); + else + return it->second; + } +} + +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)) + { + if (!fs::exists(vcpkg_dir_status_file_old)) + { + // no status file, use empty db + return StatusParagraphs(); + } + + fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); + } + + auto text = Files::get_contents(vcpkg_dir_status_file).get_or_throw(); + auto pghs = Paragraphs::parse_paragraphs(text); + + std::vector> status_pghs; + for (auto&& p : pghs) + { + status_pghs.push_back(std::make_unique(p)); + } + + return StatusParagraphs(std::move(status_pghs)); +} + +std::string vcpkg::shorten_description(const std::string& desc) +{ + auto simple_desc = std::regex_replace(desc.substr(0, 49), std::regex("\\n( |\\t)?"), ""); + if (desc.size() > 49) + simple_desc.append("..."); + return simple_desc; +} + +StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) { - std::string shorten_description(const std::string& desc) + auto updates_dir = paths.vcpkg_dir_updates; + + std::error_code ec; + fs::create_directory(paths.installed, ec); + fs::create_directory(paths.vcpkg_dir, ec); + fs::create_directory(paths.vcpkg_dir_info, ec); + fs::create_directory(updates_dir, ec); + + const fs::path& status_file = paths.vcpkg_dir_status_file; + const fs::path status_file_old = status_file.parent_path() / "status-old"; + const fs::path status_file_new = status_file.parent_path() / "status-new"; + + StatusParagraphs current_status_db = load_current_database(status_file, status_file_old); + + auto b = fs::directory_iterator(updates_dir); + auto e = fs::directory_iterator(); + if (b == e) { - auto simple_desc = std::regex_replace(desc.substr(0, 49), std::regex("\\n( |\\t)?"), ""); - if (desc.size() > 49) - simple_desc.append("..."); - return simple_desc; + // updates directory is empty, control file is up-to-date. + return current_status_db; + } + + for (; b != e; ++b) + { + if (!fs::is_regular_file(b->status())) + continue; + if (b->path().filename() == "incomplete") + continue; + + auto text = Files::get_contents(b->path()).get_or_throw(); + auto pghs = Paragraphs::parse_paragraphs(text); + for (auto&& p : pghs) + { + current_status_db.insert(std::make_unique(p)); + } } + + std::fstream(status_file_new, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc) << current_status_db; + + if (fs::exists(status_file_old)) + fs::remove(status_file_old); + if (fs::exists(status_file)) + fs::rename(status_file, status_file_old); + fs::rename(status_file_new, status_file); + fs::remove(status_file_old); + + b = fs::directory_iterator(updates_dir); + for (; b != e; ++b) + { + if (!fs::is_regular_file(b->status())) + continue; + fs::remove(b->path()); + } + + return current_status_db; +} + +static fs::path listfile_path(const vcpkg_paths& paths, const BinaryParagraph& pgh) +{ + return paths.vcpkg_dir_info / (pgh.fullstem() + ".list"); +} + +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; +} + +static void write_update(const vcpkg_paths& paths, const StatusParagraph& p) +{ + static int update_id = 0; + auto my_update_id = update_id++; + auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete"; + auto update_filename = paths.vcpkg_dir_updates / std::to_string(my_update_id); + std::fstream fs(tmp_update_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + fs << p; + fs.close(); + fs::rename(tmp_update_filename, update_filename); +} + +static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) +{ + std::fstream listfile(listfile_path(paths, 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 auto& filename = it->path().filename(); + if (fs::is_regular_file(it->status()) && (filename == "CONTROL" || filename == "control")) + { + // 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(); +} + +// TODO: Refactoring between this function and install_package +std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) +{ + const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); + return BinaryParagraph(pghs[0]).depends; + } + + return get_unmet_package_build_dependencies(paths, spec, status_db); +} + +std::vector vcpkg::get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) +{ + const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; + auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); + return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); + } + + Checks::exit_with_message("Could not find package named %s", spec); +} + +void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) +{ + 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(listfile_path(paths, 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(listfile_path(paths, 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 vcpkg::search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) +{ + std::string line; + + for (auto&& pgh : status_db) + { + if (pgh->state != install_state_t::installed) + continue; + + std::fstream listfile(listfile_path(paths, pgh->package)); + while (std::getline(listfile, line)) + { + if (line.empty()) + { + continue; + } + + if (line.find(file_substr) != std::string::npos) + { + System::println("%s: %s", pgh->package.displayname(), line); + } + } + } +} + +namespace +{ + struct Binaries + { + std::vector dlls; + std::vector libs; + }; + + Binaries detect_files_in_directory_ending_with(const fs::path& path) + { + Files::check_is_directory(path); + + Binaries binaries; + + for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); ++it) + { + fs::path file = *it; + // Skip if directory ????? + if (file.extension() == ".dll") + { + binaries.dlls.push_back(file); + } + else if (file.extension() == ".lib") + { + binaries.libs.push_back(file); + } + } + + return binaries; + } + + void copy_files_into_directory(const std::vector& files, const fs::path& destination_folder) + { + fs::create_directory(destination_folder); + + for (auto const& src_path : files) + { + fs::path dest_path = destination_folder / src_path.filename(); + fs::copy(src_path, dest_path, fs::copy_options::overwrite_existing); + } + } + + void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) + { + Files::check_is_directory(include_directory); + Files::check_is_directory(project_directory); + Files::check_is_directory(destination_path); + Binaries debug_binaries = detect_files_in_directory_ending_with(project_directory / "Debug"); + Binaries release_binaries = detect_files_in_directory_ending_with(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); + + copy_files_into_directory(release_binaries.dlls, destination_path / "bin"); + copy_files_into_directory(release_binaries.libs, destination_path / "lib"); + + fs::create_directory(destination_path / "debug"); + copy_files_into_directory(debug_binaries.dlls, destination_path / "debug" / "bin"); + copy_files_into_directory(debug_binaries.libs, destination_path / "debug" / "lib"); + } +} + +void vcpkg::binary_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) +{ + fs::path library_destination_path = paths.package_dir(control_file_data.spec); + fs::create_directory(library_destination_path); + place_library_files_in(include_directory, project_directory, library_destination_path); + + fs::path control_file_path = library_destination_path / "CONTROL"; + std::ofstream(control_file_path) << control_file_data; } -- cgit v1.2.3 From d65e78f6f5005c08832668a8f713d1f678c49b7c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:17:34 -0800 Subject: Move functions that are only used by `import` out of vcpkg.h/cpp --- toolsrc/src/commands_import.cpp | 75 +++++++++++++++++++++++++++++++++++++++-- toolsrc/src/vcpkg.cpp | 72 --------------------------------------- 2 files changed, 73 insertions(+), 74 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 7a6139085..e5e731799 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -1,9 +1,80 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" #include "Paragraphs.h" +#include "StatusParagraph.h" +#include "vcpkg_Files.h" +#include namespace vcpkg { + struct Binaries + { + std::vector dlls; + std::vector libs; + }; + + static Binaries detect_files_in_directory_ending_with(const fs::path& path) + { + Files::check_is_directory(path); + + Binaries binaries; + + for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); ++it) + { + fs::path file = *it; + // Skip if directory ????? + if (file.extension() == ".dll") + { + binaries.dlls.push_back(file); + } + else if (file.extension() == ".lib") + { + binaries.libs.push_back(file); + } + } + + return binaries; + } + + static void copy_files_into_directory(const std::vector& files, const fs::path& destination_folder) + { + fs::create_directory(destination_folder); + + for (auto const& src_path : files) + { + fs::path dest_path = destination_folder / src_path.filename(); + fs::copy(src_path, dest_path, fs::copy_options::overwrite_existing); + } + } + + static void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) + { + Files::check_is_directory(include_directory); + Files::check_is_directory(project_directory); + Files::check_is_directory(destination_path); + Binaries debug_binaries = detect_files_in_directory_ending_with(project_directory / "Debug"); + Binaries release_binaries = detect_files_in_directory_ending_with(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); + + copy_files_into_directory(release_binaries.dlls, destination_path / "bin"); + copy_files_into_directory(release_binaries.libs, destination_path / "lib"); + + fs::create_directory(destination_path / "debug"); + copy_files_into_directory(debug_binaries.dlls, destination_path / "debug" / "bin"); + copy_files_into_directory(debug_binaries.libs, destination_path / "debug" / "lib"); + } + + static void do_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) + { + fs::path library_destination_path = paths.package_dir(control_file_data.spec); + fs::create_directory(library_destination_path); + place_library_files_in(include_directory, project_directory, library_destination_path); + + fs::path control_file_path = library_destination_path / "CONTROL"; + std::ofstream(control_file_path) << control_file_data; + } + void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); @@ -20,7 +91,7 @@ namespace vcpkg spgh.package = BinaryParagraph(pghs[0]); auto& control_file_data = spgh.package; - vcpkg::binary_import(paths, include_directory, project_directory, control_file_data); + do_import(paths, include_directory, project_directory, control_file_data); exit(EXIT_SUCCESS); } } diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 560df8dcb..3e1f16179 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -451,75 +451,3 @@ void vcpkg::search_file(const vcpkg_paths& paths, const std::string& file_substr } } } - -namespace -{ - struct Binaries - { - std::vector dlls; - std::vector libs; - }; - - Binaries detect_files_in_directory_ending_with(const fs::path& path) - { - Files::check_is_directory(path); - - Binaries binaries; - - for (auto it = fs::recursive_directory_iterator(path); it != fs::recursive_directory_iterator(); ++it) - { - fs::path file = *it; - // Skip if directory ????? - if (file.extension() == ".dll") - { - binaries.dlls.push_back(file); - } - else if (file.extension() == ".lib") - { - binaries.libs.push_back(file); - } - } - - return binaries; - } - - void copy_files_into_directory(const std::vector& files, const fs::path& destination_folder) - { - fs::create_directory(destination_folder); - - for (auto const& src_path : files) - { - fs::path dest_path = destination_folder / src_path.filename(); - fs::copy(src_path, dest_path, fs::copy_options::overwrite_existing); - } - } - - void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) - { - Files::check_is_directory(include_directory); - Files::check_is_directory(project_directory); - Files::check_is_directory(destination_path); - Binaries debug_binaries = detect_files_in_directory_ending_with(project_directory / "Debug"); - Binaries release_binaries = detect_files_in_directory_ending_with(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); - - copy_files_into_directory(release_binaries.dlls, destination_path / "bin"); - copy_files_into_directory(release_binaries.libs, destination_path / "lib"); - - fs::create_directory(destination_path / "debug"); - copy_files_into_directory(debug_binaries.dlls, destination_path / "debug" / "bin"); - copy_files_into_directory(debug_binaries.libs, destination_path / "debug" / "lib"); - } -} - -void vcpkg::binary_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) -{ - fs::path library_destination_path = paths.package_dir(control_file_data.spec); - fs::create_directory(library_destination_path); - place_library_files_in(include_directory, project_directory, library_destination_path); - - fs::path control_file_path = library_destination_path / "CONTROL"; - std::ofstream(control_file_path) << control_file_data; -} -- cgit v1.2.3 From f13b9cd24af72f4865ccfa0a64a1a43770da4833 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:20:32 -0800 Subject: Don't #include vcpkg.h in portsdiff.cpp --- toolsrc/src/commands_portsdiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index fdbaec0ac..3789e3b42 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -1,6 +1,5 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" #include #include #include "vcpkg_Maps.h" @@ -8,6 +7,7 @@ #include #include #include "Paragraphs.h" +#include "SourceParagraph.h" namespace vcpkg { -- cgit v1.2.3 From 5c769e462b377ce06ad46998794a189f3a1b55bc Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:33:08 -0800 Subject: Remove unused #include --- toolsrc/src/vcpkg_Dependencies.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 0e45b28dd..28c5e291f 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -7,7 +7,6 @@ #include #include "vcpkg.h" #include "vcpkg_Maps.h" -#include "vcpkg_Sets.h" namespace vcpkg { namespace Dependencies { -- cgit v1.2.3 From 8be5e7c123d241cd4a71d03acdf43ceccf57ded2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 16:38:49 -0800 Subject: Move Dependency-related functions from vcpkg.h to vcpkg_Dependencies.h --- toolsrc/src/commands_installation.cpp | 2 +- toolsrc/src/vcpkg.cpp | 44 --------------------------------- toolsrc/src/vcpkg_Dependencies.cpp | 46 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 45 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index b5f4e1a5d..d8ac974b3 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -141,7 +141,7 @@ namespace vcpkg Input::check_triplet(spec.target_triplet(), paths); // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). - auto first_level_deps = get_unmet_package_build_dependencies(paths, spec, status_db); + auto first_level_deps = Dependencies::get_unmet_package_build_dependencies(paths, spec, status_db); std::vector first_level_deps_specs; for (auto&& dep : first_level_deps) { diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 3e1f16179..bd02f5424 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -216,50 +216,6 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar listfile.close(); } -// TODO: Refactoring between this function and install_package -std::vector vcpkg::get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) -{ - const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; - - auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); - return BinaryParagraph(pghs[0]).depends; - } - - return get_unmet_package_build_dependencies(paths, spec, status_db); -} - -std::vector vcpkg::get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) -{ - const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; - auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); - return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); - } - - Checks::exit_with_message("Could not find package named %s", spec); -} - void vcpkg::install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) { StatusParagraph spgh; diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 28c5e291f..2e79a2499 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -7,6 +7,8 @@ #include #include "vcpkg.h" #include "vcpkg_Maps.h" +#include "vcpkg_Files.h" +#include "Paragraphs.h" namespace vcpkg { namespace Dependencies { @@ -61,4 +63,48 @@ namespace vcpkg { namespace Dependencies const Graphs::Graph dependency_graph = build_dependency_graph(paths, specs, status_db); return Maps::extract_key_set(dependency_graph.adjacency_list()); } + + // TODO: Refactoring between this function and install_package + std::vector get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + { + const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); + return BinaryParagraph(pghs[0]).depends; + } + + return get_unmet_package_build_dependencies(paths, spec, status_db); + } + + std::vector get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + { + const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; + auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); + return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); + } + + Checks::exit_with_message("Could not find package named %s", spec); + } }} -- cgit v1.2.3 From d85e169c054c0702ec6cd2deedff58eaf49dcfab Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:05:32 -0800 Subject: [Dependencies] Make function static --- toolsrc/src/vcpkg_Dependencies.cpp | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 2e79a2499..953bd9925 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -12,6 +12,29 @@ namespace vcpkg { namespace Dependencies { + // TODO: Refactoring between this function and install_package + static std::vector get_single_level_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + { + const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); + return BinaryParagraph(pghs[0]).depends; + } + + return get_unmet_package_build_dependencies(paths, spec, status_db); + } + static Graphs::Graph build_dependency_graph(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { std::vector examine_stack(specs); @@ -29,7 +52,7 @@ namespace vcpkg { namespace Dependencies continue; } - std::vector dependencies_as_string = get_unmet_package_dependencies(paths, spec, status_db); + std::vector dependencies_as_string = get_single_level_unmet_dependencies(paths, spec, status_db); for (const std::string& dep_as_string : dependencies_as_string) { @@ -64,29 +87,6 @@ namespace vcpkg { namespace Dependencies return Maps::extract_key_set(dependency_graph.adjacency_list()); } - // TODO: Refactoring between this function and install_package - std::vector get_unmet_package_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) - { - const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; - - auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); - return BinaryParagraph(pghs[0]).depends; - } - - return get_unmet_package_build_dependencies(paths, spec, status_db); - } - std::vector get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) { const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; -- cgit v1.2.3 From 21f69a44bead8c4ffe6719131172512519afe3aa Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:06:46 -0800 Subject: [Dependencies] Function rename --- toolsrc/src/commands_installation.cpp | 2 +- toolsrc/src/vcpkg_Dependencies.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index d8ac974b3..917b4a219 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -148,7 +148,7 @@ namespace vcpkg first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); } - std::unordered_set unmet_dependencies = Dependencies::find_unmet_dependencies(paths, first_level_deps_specs, status_db); + std::unordered_set unmet_dependencies = Dependencies::get_unmet_dependencies(paths, first_level_deps_specs, status_db); if (!unmet_dependencies.empty()) { System::println(System::color::error, "The build command requires all dependencies to be already installed."); diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 953bd9925..d3b9dbb7b 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -81,7 +81,7 @@ namespace vcpkg { namespace Dependencies return build_dependency_graph(paths, specs, status_db).find_topological_sort(); } - std::unordered_set find_unmet_dependencies(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) + std::unordered_set get_unmet_dependencies(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { const Graphs::Graph dependency_graph = build_dependency_graph(paths, specs, status_db); return Maps::extract_key_set(dependency_graph.adjacency_list()); -- cgit v1.2.3 From 7a1bc07142577cce32ee88c8d8ef60b386d19b6a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:09:07 -0800 Subject: [Dependencies] Remove unused parameter --- toolsrc/src/commands_installation.cpp | 2 +- toolsrc/src/vcpkg_Dependencies.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 917b4a219..3f40ba023 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -141,7 +141,7 @@ namespace vcpkg Input::check_triplet(spec.target_triplet(), paths); // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). - auto first_level_deps = Dependencies::get_unmet_package_build_dependencies(paths, spec, status_db); + auto first_level_deps = Dependencies::get_unmet_package_build_dependencies(paths, spec); std::vector first_level_deps_specs; for (auto&& dep : first_level_deps) { diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index d3b9dbb7b..10c3ce56f 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -13,7 +13,7 @@ namespace vcpkg { namespace Dependencies { // TODO: Refactoring between this function and install_package - static std::vector get_single_level_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + static std::vector get_single_level_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec) { const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; @@ -32,7 +32,7 @@ namespace vcpkg { namespace Dependencies return BinaryParagraph(pghs[0]).depends; } - return get_unmet_package_build_dependencies(paths, spec, status_db); + return get_unmet_package_build_dependencies(paths, spec); } static Graphs::Graph build_dependency_graph(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) @@ -52,7 +52,7 @@ namespace vcpkg { namespace Dependencies continue; } - std::vector dependencies_as_string = get_single_level_unmet_dependencies(paths, spec, status_db); + std::vector dependencies_as_string = get_single_level_unmet_dependencies(paths, spec); for (const std::string& dep_as_string : dependencies_as_string) { @@ -87,7 +87,7 @@ namespace vcpkg { namespace Dependencies return Maps::extract_key_set(dependency_graph.adjacency_list()); } - std::vector get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec, const StatusParagraphs& status_db) + std::vector get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec) { const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); -- cgit v1.2.3 From c91d8e41b60653b652b11c641f7a5b3d3eab7f6b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:31:41 -0800 Subject: Introduce vcpkg_info.h/cpp --- toolsrc/src/commands_help.cpp | 6 +++--- toolsrc/src/commands_installation.cpp | 3 ++- toolsrc/src/commands_update.cpp | 3 ++- toolsrc/src/main.cpp | 7 ++++--- toolsrc/src/vcpkg_info.cpp | 34 ++++++++++++++++++++++++++++++++++ toolsrc/src/vcpkg_version.cpp | 25 ------------------------- 6 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 toolsrc/src/vcpkg_info.cpp delete mode 100644 toolsrc/src/vcpkg_version.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index 194e809b1..fd02d948e 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,6 +1,6 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" #include "vcpkg_System.h" +#include "vcpkg_info.h" namespace vcpkg { @@ -9,7 +9,7 @@ namespace vcpkg args.check_exact_arg_count(0); System::println("Vcpkg package management program version %s\n" "\n" - "See LICENSE.txt for license information.", vcpkg::version() + "See LICENSE.txt for license information.", Info::version() ); exit(EXIT_SUCCESS); } @@ -39,7 +39,7 @@ namespace vcpkg void contact_command(const vcpkg_cmd_arguments& args) { args.check_exact_arg_count(0); - System::println("Send an email to vcpkg@microsoft.com with any feedback."); + System::println("Send an email to %s with any feedback.", Info::email()); exit(EXIT_SUCCESS); } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 3f40ba023..460fa1818 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -10,6 +10,7 @@ #include "vcpkg_Input.h" #include "vcpkg_Maps.h" #include "Paragraphs.h" +#include "vcpkg_info.h" namespace vcpkg { @@ -50,7 +51,7 @@ namespace vcpkg " Vcpkg version: %s\n" "\n" "Additionally, attach any relevant sections from the log files above." - , to_string(spec), version()); + , to_string(spec), Info::version()); TrackProperty("error", "build failed"); TrackProperty("build_error", to_string(spec)); exit(EXIT_FAILURE); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index b448091f7..2d7444392 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -3,6 +3,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" #include "Paragraphs.h" +#include "vcpkg_info.h" namespace vcpkg { @@ -77,7 +78,7 @@ namespace vcpkg 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); + auto num2 = sscanf_s(Info::version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2); if (num1 == 3 && num2 == 3) { diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 22c45e5ab..70527ca1d 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -13,6 +13,7 @@ #include "vcpkg_System.h" #include "vcpkg_Input.h" #include "Paragraphs.h" +#include "vcpkg_info.h" using namespace vcpkg; @@ -192,7 +193,7 @@ int wmain(const int argc, const wchar_t* const* const argv) Flush(); }); - TrackProperty("version", version()); + TrackProperty("version", Info::version()); const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); TrackProperty("cmdline", trimmed_command_line); @@ -234,10 +235,10 @@ int wmain(const int argc, const wchar_t* const* const argv) std::cerr << "vcpkg.exe has crashed.\n" << "Please send an email to:\n" - << " vcpkg@microsoft.com\n" + << " " << Info::email() << "\n" << "containing a brief summary of what you were trying to do and the following data blob:\n" << "\n" - << "Version=" << version() << "\n" + << "Version=" << Info::version() << "\n" << "EXCEPTION='" << exc_msg << "'\n" << "CMD=\n"; for (int x = 0; x < argc; ++x) diff --git a/toolsrc/src/vcpkg_info.cpp b/toolsrc/src/vcpkg_info.cpp new file mode 100644 index 000000000..25c09d6da --- /dev/null +++ b/toolsrc/src/vcpkg_info.cpp @@ -0,0 +1,34 @@ +#include "vcpkg_info.h" +#include "metrics.h" + +#define STRINGIFY(X) #X +#define MACRO_TO_STRING(X) STRINGIFY(X) + +#define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)"" // Double quotes needed at the end to prevent blank token + +namespace vcpkg { namespace Info +{ + const std::string& version() + { + static const std::string s_version = +#include "../VERSION.txt" + + +#pragma warning( push ) +#pragma warning( disable : 4003) + // VCPKG_VERSION can be defined but have no value, which yields C4003. + + std::string(VCPKG_VERSION_AS_STRING) +#pragma warning( pop ) +#ifndef NDEBUG + + std::string("-debug") +#endif + + std::string(GetCompiledMetricsEnabled() ? "" : "-external"); + return s_version; + } + + const std::string& email() + { + static const std::string s_email = R"(vcpkg@microsoft.com)"; + return s_email; + } +}} diff --git a/toolsrc/src/vcpkg_version.cpp b/toolsrc/src/vcpkg_version.cpp deleted file mode 100644 index da52b7cab..000000000 --- a/toolsrc/src/vcpkg_version.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "vcpkg.h" -#include "metrics.h" - -#define STRINGIFY(X) #X -#define MACRO_TO_STRING(X) STRINGIFY(X) - -#define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)"" // Double quotes needed at the end to prevent blank token - -const std::string& vcpkg::version() -{ - static const std::string s_version = -#include "../VERSION.txt" - - -#pragma warning( push ) -#pragma warning( disable : 4003) - // VCPKG_VERSION can be defined but have no value, which yields C4003. - + std::string(VCPKG_VERSION_AS_STRING) -#pragma warning( pop ) -#ifndef NDEBUG - + std::string("-debug") -#endif - + std::string(GetCompiledMetricsEnabled() ? "" : "-external"); - return s_version; -} -- cgit v1.2.3 From 8adaaea6fc7f2aa99f1ec8d894ad7036805bf76a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:32:27 -0800 Subject: [cache] Don't #include "vcpkg.h" --- toolsrc/src/commands_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 634a72a64..19c762caf 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,8 +1,8 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" -#include "vcpkg.h" #include "Paragraphs.h" +#include "BinaryParagraph.h" namespace vcpkg { -- cgit v1.2.3 From 6071014cf94478ade2f2d4cd95d26d00e4cac19d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:33:23 -0800 Subject: Remove unused #includes --- toolsrc/src/commands_integration.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integration.cpp index 6a11d6ec4..cd303c649 100644 --- a/toolsrc/src/commands_integration.cpp +++ b/toolsrc/src/commands_integration.cpp @@ -2,9 +2,7 @@ #include #include #include "vcpkg_Commands.h" -#include "vcpkg.h" #include -#include #include #include #include "vcpkg_Environment.h" -- cgit v1.2.3 From e7c6f90adc58382d200159ada063204d462937d0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:34:22 -0800 Subject: Remove unused #include --- toolsrc/src/commands_other.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 894beae27..5f4128bb1 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -1,6 +1,5 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" namespace vcpkg { -- cgit v1.2.3 From d78c1a974f1eabe8caf5df36bbd5b55b2dcd701d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:37:08 -0800 Subject: Move shorten_description to vcpkglib_helpers --- toolsrc/src/commands_list.cpp | 3 ++- toolsrc/src/commands_search.cpp | 3 ++- toolsrc/src/vcpkg.cpp | 8 -------- toolsrc/src/vcpkglib_helpers.cpp | 8 ++++++++ 4 files changed, 12 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 87aad1991..2d6b42008 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -1,6 +1,7 @@ #include "vcpkg_Commands.h" #include "vcpkg.h" #include "vcpkg_System.h" +#include "vcpkglib_helpers.h" namespace vcpkg { @@ -9,7 +10,7 @@ namespace vcpkg System::println("%-27s %-16s %s", pgh.package.displayname(), pgh.package.version, - shorten_description(pgh.package.description)); + details::shorten_description(pgh.package.description)); } void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 399709cf3..38c257f87 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -2,6 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg.h" #include "Paragraphs.h" +#include "vcpkglib_helpers.h" namespace fs = std::tr2::sys; @@ -38,7 +39,7 @@ namespace vcpkg System::println("%-20s %-16s %s", source_paragraph.name, source_paragraph.version, - shorten_description(source_paragraph.description)); + details::shorten_description(source_paragraph.description)); } void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index bd02f5424..d9956e789 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -64,14 +64,6 @@ static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_f return StatusParagraphs(std::move(status_pghs)); } -std::string vcpkg::shorten_description(const std::string& desc) -{ - auto simple_desc = std::regex_replace(desc.substr(0, 49), std::regex("\\n( |\\t)?"), ""); - if (desc.size() > 49) - simple_desc.append("..."); - return simple_desc; -} - StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) { auto updates_dir = paths.vcpkg_dir_updates; diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index 61dc4f4cc..d104bb19d 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -1,6 +1,7 @@ #include "vcpkg_Checks.h" #include "vcpkglib_helpers.h" #include +#include namespace vcpkg {namespace details { @@ -45,4 +46,11 @@ namespace vcpkg {namespace details return value; } + std::string shorten_description(const std::string& desc) + { + auto simple_desc = std::regex_replace(desc.substr(0, 49), std::regex("\\n( |\\t)?"), ""); + if (desc.size() > 49) + simple_desc.append("..."); + return simple_desc; + } }} -- cgit v1.2.3 From 97df2162fddb5e37c92ded2e8f6beebf68d534da Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:37:31 -0800 Subject: [search] Don't #include "vcpkg.h" --- toolsrc/src/commands_search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 38c257f87..923368252 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,8 +1,8 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" #include "Paragraphs.h" #include "vcpkglib_helpers.h" +#include "SourceParagraph.h" namespace fs = std::tr2::sys; -- cgit v1.2.3 From a1d9478103cfc88b1a3ea3960bdd7a75dea8d0d6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:38:39 -0800 Subject: Don't #include "vcpkg.h" --- toolsrc/src/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 70527ca1d..f937be7f1 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include "vcpkg.h" #include "vcpkg_Commands.h" #include "metrics.h" #include -- cgit v1.2.3 From 7e7078285c6ebcbbedee6b3ca6ce21e3a8aaf0d6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:39:11 -0800 Subject: Remove unused #includes --- toolsrc/src/vcpkg_cmd_arguments.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index a286ba9b7..d61e420ab 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -2,10 +2,8 @@ #include #include "vcpkg_cmd_arguments.h" #include "vcpkg_Commands.h" -#include "vcpkg_Graphs.h" #include #include "metrics.h" -#include "vcpkg.h" #include "vcpkg_System.h" namespace vcpkg -- cgit v1.2.3 From 42f4d9645548a5b7c31c051b88eb0f83c84d60e6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:39:43 -0800 Subject: [Dependencies] Don't #include "vcpkg.h" --- toolsrc/src/vcpkg_Dependencies.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 10c3ce56f..c054ec913 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -5,7 +5,6 @@ #include "package_spec.h" #include "StatusParagraphs.h" #include -#include "vcpkg.h" #include "vcpkg_Maps.h" #include "vcpkg_Files.h" #include "Paragraphs.h" -- cgit v1.2.3 From 7cbf4930414682ef252b9bc53ef0d113d427c69f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:40:29 -0800 Subject: [tests_paragraph] Don't #include "vcpkg.h" --- toolsrc/src/tests_paragraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/tests_paragraph.cpp b/toolsrc/src/tests_paragraph.cpp index 28309fd31..6d9e46fcf 100644 --- a/toolsrc/src/tests_paragraph.cpp +++ b/toolsrc/src/tests_paragraph.cpp @@ -1,6 +1,6 @@ #include "CppUnitTest.h" -#include "vcpkg.h" #include "Paragraphs.h" +#include "BinaryParagraph.h" #pragma comment(lib,"version") #pragma comment(lib,"winhttp") -- cgit v1.2.3 From 8c47be55e2c9bb8acb4dd7075b682982a928d0b1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:40:58 -0800 Subject: [Environment] Dont' #include "vcpkg.h" --- toolsrc/src/vcpkg_Environment.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index d98b0f220..ed70e6881 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -2,7 +2,6 @@ #include #include "vcpkg_Environment.h" #include "vcpkg_Commands.h" -#include "vcpkg.h" #include "metrics.h" #include "vcpkg_System.h" -- cgit v1.2.3 From d799762ea7a8e6790d06bfc64297f9896e12c3b4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:54:23 -0800 Subject: Move listfile_path() to vcpkg_paths.h --- toolsrc/src/vcpkg.cpp | 13 ++++--------- toolsrc/src/vcpkg_paths.cpp | 5 +++++ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index d9956e789..729a0c8d5 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -123,11 +123,6 @@ StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) return current_status_db; } -static fs::path listfile_path(const vcpkg_paths& paths, const BinaryParagraph& pgh) -{ - return paths.vcpkg_dir_info / (pgh.fullstem() + ".list"); -} - static std::string get_fullpkgname_from_listfile(const fs::path& path) { auto ret = path.stem().generic_u8string(); @@ -149,7 +144,7 @@ static void write_update(const vcpkg_paths& paths, const StatusParagraph& p) static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) { - std::fstream listfile(listfile_path(paths, bpgh), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + 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(); @@ -308,7 +303,7 @@ void vcpkg::deinstall_package(const vcpkg_paths& paths, const package_spec& spec pkg.state = install_state_t::half_installed; write_update(paths, pkg); - std::fstream listfile(listfile_path(paths, pkg.package), std::ios_base::in | std::ios_base::binary); + std::fstream listfile(paths.listfile_path(pkg.package), std::ios_base::in | std::ios_base::binary); if (listfile) { std::vector dirs_touched; @@ -367,7 +362,7 @@ void vcpkg::deinstall_package(const vcpkg_paths& paths, const package_spec& spec } listfile.close(); - fs::remove(listfile_path(paths, pkg.package)); + fs::remove(paths.listfile_path(pkg.package)); } pkg.state = install_state_t::not_installed; @@ -384,7 +379,7 @@ void vcpkg::search_file(const vcpkg_paths& paths, const std::string& file_substr if (pgh->state != install_state_t::installed) continue; - std::fstream listfile(listfile_path(paths, pgh->package)); + std::fstream listfile(paths.listfile_path(pgh->package)); while (std::getline(listfile, line)) { if (line.empty()) diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 1f9eb0bc5..28ab22ec3 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -55,6 +55,11 @@ namespace vcpkg return this->ports / spec.name(); } + fs::path vcpkg_paths::listfile_path(const BinaryParagraph& pgh) const + { + return this->vcpkg_dir_info / (pgh.fullstem() + ".list"); + } + bool vcpkg_paths::is_valid_triplet(const triplet& t) const { auto it = fs::directory_iterator(this->triplets); -- cgit v1.2.3 From 1a1507a6039ce44220447d2b1ab723d631515b07 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 7 Nov 2016 17:56:40 -0800 Subject: Move search_file() to commands_own.cpp --- toolsrc/src/commands_owns.cpp | 26 ++++++++++++++++++++++++++ toolsrc/src/vcpkg.cpp | 25 ------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index b3dab2e44..e5599ce01 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -1,9 +1,35 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg.h" +#include namespace vcpkg { + static void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) + { + std::string line; + + for (auto&& pgh : status_db) + { + if (pgh->state != install_state_t::installed) + continue; + + std::fstream listfile(paths.listfile_path(pgh->package)); + while (std::getline(listfile, line)) + { + if (line.empty()) + { + continue; + } + + if (line.find(file_substr) != std::string::npos) + { + System::println("%s: %s", pgh->package.displayname(), line); + } + } + } + } + void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = Strings::format("The argument should be a pattern to search for. %s", create_example_string("owns zlib.dll")); diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 729a0c8d5..00aea1e2e 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -369,28 +369,3 @@ void vcpkg::deinstall_package(const vcpkg_paths& paths, const package_spec& spec write_update(paths, pkg); System::println(System::color::success, "Package %s was successfully removed", pkg.package.displayname()); } - -void vcpkg::search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) -{ - std::string line; - - for (auto&& pgh : status_db) - { - if (pgh->state != install_state_t::installed) - continue; - - std::fstream listfile(paths.listfile_path(pgh->package)); - while (std::getline(listfile, line)) - { - if (line.empty()) - { - continue; - } - - if (line.find(file_substr) != std::string::npos) - { - System::println("%s: %s", pgh->package.displayname(), line); - } - } - } -} -- cgit v1.2.3 From 6e9d17f73c01c3ad07875ca79196ed2f5e2d3896 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 8 Nov 2016 14:12:49 -0800 Subject: Introduce BUILD_INFO file. Significant change in the way static/dynamic is handled --- toolsrc/src/BuildInfo.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ toolsrc/src/post_build_lint.cpp | 18 +++++++++++----- toolsrc/src/triplet.cpp | 10 --------- toolsrc/src/vcpkg_paths.cpp | 5 +++++ 4 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 toolsrc/src/BuildInfo.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp new file mode 100644 index 000000000..dc8d90e2e --- /dev/null +++ b/toolsrc/src/BuildInfo.cpp @@ -0,0 +1,46 @@ +#include "BuildInfo.h" +#include "vcpkg_Checks.h" +#include "vcpkglib_helpers.h" + +namespace vcpkg +{ + // + namespace BuildInfoRequiredField + { + static const std::string CRT_LINKAGE = "CRTLinkage"; + static const std::string LIBRARY_LINKAGE = "LibraryLinkage"; + } + + BuildInfo BuildInfo::create(const std::unordered_map& pgh) + { + BuildInfo build_info; + build_info.crt_linkage = details::required_field(pgh, BuildInfoRequiredField::CRT_LINKAGE); + build_info.library_linkage = details::required_field(pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); + + return build_info; + } + + LinkageType linkage_type_value_of(const std::string& as_string) + + { + if (as_string == "dynamic") + { + return LinkageType::DYNAMIC; + } + + if (as_string == "static") + { + return LinkageType::STATIC; + } + + return LinkageType::UNKNOWN; + } + + 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"); + + return BuildInfo::create(pghs[0]); + } +} diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 8301e74cc..4b784952a 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -5,6 +5,7 @@ #include #include "vcpkg_System.h" #include "coff_file_reader.h" +#include "BuildInfo.h" namespace fs = std::tr2::sys; @@ -495,6 +496,9 @@ namespace vcpkg void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) { System::println("-- Performing post-build validation"); + + BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); + size_t error_count = 0; error_count += check_for_files_in_include_directory(spec, paths); error_count += check_for_files_in_debug_include_directory(spec, paths); @@ -506,10 +510,9 @@ namespace vcpkg error_count += check_for_copyright_file(spec, paths); error_count += check_for_exes(spec, paths); - triplet::BuildType build_type = spec.target_triplet().build_type(); - switch (build_type) + switch (linkage_type_value_of(build_info.library_linkage)) { - case triplet::BuildType::DYNAMIC: + case LinkageType::DYNAMIC: { const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll"); const std::vector release_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll"); @@ -525,7 +528,7 @@ namespace vcpkg error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); break; } - case triplet::BuildType::STATIC: + case LinkageType::STATIC: { std::vector dlls; recursive_find_files_with_extension_in_dir(paths.packages / spec.dir(), ".dll", &dlls); @@ -534,7 +537,12 @@ namespace vcpkg error_count += check_bin_folders_are_not_present_in_static_build(spec, paths); break; } - + case LinkageType::UNKNOWN: + { + error_count += 1; + System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); + break; + } default: Checks::unreachable(); } diff --git a/toolsrc/src/triplet.cpp b/toolsrc/src/triplet.cpp index af2ca2a72..a6816b445 100644 --- a/toolsrc/src/triplet.cpp +++ b/toolsrc/src/triplet.cpp @@ -64,14 +64,4 @@ namespace vcpkg auto it = std::find(this->m_canonical_name.cbegin(), this->m_canonical_name.cend(), '-'); return std::string(it + 1, this->m_canonical_name.cend()); } - - triplet::BuildType triplet::build_type() const - { - if (this->m_canonical_name.find("static") != std::string::npos) - { - return BuildType::STATIC; - } - - return BuildType::DYNAMIC; - } } diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 28ab22ec3..5347b79d8 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -55,6 +55,11 @@ namespace vcpkg return this->ports / spec.name(); } + fs::path vcpkg_paths::build_info_file_path(const package_spec& spec) const + { + return this->package_dir(spec) / "BUILD_INFO"; + } + fs::path vcpkg_paths::listfile_path(const BinaryParagraph& pgh) const { return this->vcpkg_dir_info / (pgh.fullstem() + ".list"); -- cgit v1.2.3 From 218cae4503749134f4827b3e71fbf22a956d4dc3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 8 Nov 2016 15:08:42 -0800 Subject: Skip BUILD_INFO file on install --- toolsrc/src/vcpkg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 00aea1e2e..6e47df2c8 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -158,7 +158,7 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) { const auto& filename = it->path().filename(); - if (fs::is_regular_file(it->status()) && (filename == "CONTROL" || filename == "control")) + if (fs::is_regular_file(it->status()) && (_stricmp(filename.generic_string().c_str(), "CONTROL") == 0 || _stricmp(filename.generic_string().c_str(), "BUILD_INFO") == 0)) { // Do not copy the control file continue; -- cgit v1.2.3 From a9d732f206936c82d07f8d4b5ef0aaa461bb2073 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 8 Nov 2016 19:33:50 -0800 Subject: Reorder post-build checks related to lib files --- toolsrc/src/post_build_lint.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 4b784952a..634e85c05 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -510,6 +510,17 @@ namespace vcpkg error_count += check_for_copyright_file(spec, paths); error_count += check_for_exes(spec, paths); + const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); + const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); + + error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); + + std::vector libs; + libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); + libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); + + error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); + switch (linkage_type_value_of(build_info.library_linkage)) { case LinkageType::DYNAMIC: @@ -550,16 +561,6 @@ namespace vcpkg error_count += check_no_subdirectories(paths.packages / spec.dir() / "lib"); error_count += check_no_subdirectories(paths.packages / spec.dir() / "debug" / "lib"); #endif - const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); - const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); - - error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); - - std::vector libs; - libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); - libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); - - error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); error_count += check_no_empty_folders(paths.packages / spec.dir()); -- cgit v1.2.3 From 89447c156d3b99ba63499aa4b8f23b985ccd6474 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 9 Nov 2016 01:27:49 -0800 Subject: Add checks for crt linkage (currently disabled) --- toolsrc/src/BuildInfo.cpp | 72 +++++++++++++++++++++++++ toolsrc/src/post_build_lint.cpp | 116 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index dc8d90e2e..2e74eefc3 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -4,6 +4,21 @@ namespace vcpkg { + std::string BuildType::toString() const + { + return Strings::format("[%s,%s]", to_string(config), to_string(linkage)); + } + + bool operator==(const BuildType& lhs, const BuildType& rhs) + { + return lhs.config == rhs.config && lhs.linkage == rhs.linkage; + } + + bool operator!=(const BuildType& lhs, const BuildType& rhs) + { + return !(lhs == rhs); + } + // namespace BuildInfoRequiredField { @@ -20,6 +35,11 @@ namespace vcpkg return build_info; } + const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC); + const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC); + const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC); + const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC); + LinkageType linkage_type_value_of(const std::string& as_string) { @@ -36,6 +56,58 @@ namespace vcpkg return LinkageType::UNKNOWN; } + std::string to_string(const LinkageType& build_info) + { + switch (build_info) + { + case LinkageType::STATIC: + return "static"; + case LinkageType::DYNAMIC: + return "dynamic"; + default: + Checks::unreachable(); + } + } + + std::string to_string(const ConfigurationType& conf) + + { + switch (conf) + { + case ConfigurationType::DEBUG: + return "Debug"; + case ConfigurationType::RELEASE: + return "Release"; + default: + Checks::unreachable(); + } + } + + BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) + { + if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) + { + return DEBUG_STATIC; + } + + if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) + { + return DEBUG_DYNAMIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) + { + return RELEASE_STATIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) + { + return RELEASE_DYNAMIC; + } + + Checks::unreachable(); + } + BuildInfo read_build_info(const fs::path& filepath) { const std::vector> pghs = Paragraphs::get_paragraphs(filepath); diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 634e85c05..9cd88bff1 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -6,6 +6,7 @@ #include "vcpkg_System.h" #include "coff_file_reader.h" #include "BuildInfo.h" +#include namespace fs = std::tr2::sys; @@ -488,6 +489,116 @@ namespace vcpkg return lint_status::SUCCESS; } + struct BuildInfo_and_files + { + explicit BuildInfo_and_files(const BuildType& build_type) : build_type(build_type) + { + } + + BuildType build_type; + std::vector files; + }; + + static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs) + { + static const std::regex DEBUG_STATIC_CRT(R"(/DEFAULTLIB:LIBCMTD)"); + static const std::regex DEBUG_DYNAMIC_CRT(R"(/DEFAULTLIB:MSVCRTD)"); + + static const std::regex RELEASE_STATIC_CRT(R"(/DEFAULTLIB:LIBCMT[^D])"); + static const std::regex RELEASE_DYNAMIC_CRT(R"(/DEFAULTLIB:MSVCRT[^D])"); + + lint_status output_status = lint_status::SUCCESS; + + std::vector libs_with_no_crts; + std::vector libs_with_multiple_crts; + + BuildInfo_and_files libs_with_debug_static_crt(BuildType::DEBUG_STATIC); + BuildInfo_and_files libs_with_debug_dynamic_crt(BuildType::DEBUG_DYNAMIC); + BuildInfo_and_files libs_with_release_static_crt(BuildType::RELEASE_STATIC); + BuildInfo_and_files libs_with_release_dynamic_crt(BuildType::RELEASE_DYNAMIC); + + for (const fs::path& lib : libs) + { + const std::wstring cmd_line = Strings::wformat(LR"("%s" /directives "%s")", DUMPBIN_EXE.native(), lib.native()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + + bool found_debug_static_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), DEBUG_STATIC_CRT); + bool found_debug_dynamic_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), DEBUG_DYNAMIC_CRT); + bool found_release_static_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), RELEASE_STATIC_CRT); + bool found_release_dynamic_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), RELEASE_DYNAMIC_CRT); + + const size_t crts_found_count = found_debug_static_crt + found_debug_dynamic_crt + found_release_static_crt + found_release_dynamic_crt; + + if (crts_found_count == 0) + { + libs_with_no_crts.push_back(lib); + continue; + } + + if (crts_found_count > 1) + { + libs_with_multiple_crts.push_back(lib); + continue; + } + + // now we have exactly 1 crt + if (found_debug_static_crt) + { + libs_with_debug_static_crt.files.push_back(lib); + continue; + } + if (found_debug_dynamic_crt) + { + libs_with_debug_dynamic_crt.files.push_back(lib); + continue; + } + + if (found_release_static_crt) + { + libs_with_release_static_crt.files.push_back(lib); + continue; + } + + libs_with_release_dynamic_crt.files.push_back(lib); + } + + if (!libs_with_no_crts.empty()) + { + System::println(System::color::warning, "Could not detect the crt linkage in the following libs:"); + print_vector_of_files(libs_with_no_crts); + output_status = lint_status::ERROR_DETECTED; + } + + if (!libs_with_multiple_crts.empty()) + { + System::println(System::color::warning, "Detected multiple crt linkages for the following libs:"); + print_vector_of_files(libs_with_multiple_crts); + output_status = lint_status::ERROR_DETECTED; + } + + std::vector group_for_iteration = { + libs_with_debug_static_crt, libs_with_debug_dynamic_crt, + libs_with_release_static_crt, libs_with_release_dynamic_crt}; + + for (const BuildInfo_and_files& bif : group_for_iteration) + { + if (!bif.files.empty() && bif.build_type != expected_build_type) + { + System::println(System::color::warning, "Expected %s crt linkage, but the following libs had %s crt linkage:", expected_build_type.toString(), bif.build_type.toString()); + print_vector_of_files(bif.files); + output_status = lint_status::ERROR_DETECTED; + } + } + + if (output_status == lint_status::ERROR_DETECTED) + { + System::println(System::color::warning, "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); + } + + return output_status; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -546,6 +657,11 @@ namespace vcpkg error_count += check_no_dlls_present(dlls); error_count += check_bin_folders_are_not_present_in_static_build(spec, paths); + +#if 0 + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs); +#endif break; } case LinkageType::UNKNOWN: -- cgit v1.2.3 From e291ec68456f13af3df7b5616cf32d4674fb289d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 9 Nov 2016 16:42:46 -0800 Subject: [build-checks] Finding no crt is no longer an error --- toolsrc/src/post_build_lint.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 9cd88bff1..62f97b88e 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -509,7 +509,6 @@ namespace vcpkg lint_status output_status = lint_status::SUCCESS; - std::vector libs_with_no_crts; std::vector libs_with_multiple_crts; BuildInfo_and_files libs_with_debug_static_crt(BuildType::DEBUG_STATIC); @@ -532,7 +531,7 @@ namespace vcpkg if (crts_found_count == 0) { - libs_with_no_crts.push_back(lib); + // It can be valid for no crt to be detected. For example: openssl continue; } @@ -563,13 +562,6 @@ namespace vcpkg libs_with_release_dynamic_crt.files.push_back(lib); } - if (!libs_with_no_crts.empty()) - { - System::println(System::color::warning, "Could not detect the crt linkage in the following libs:"); - print_vector_of_files(libs_with_no_crts); - output_status = lint_status::ERROR_DETECTED; - } - if (!libs_with_multiple_crts.empty()) { System::println(System::color::warning, "Detected multiple crt linkages for the following libs:"); @@ -658,10 +650,8 @@ namespace vcpkg error_count += check_bin_folders_are_not_present_in_static_build(spec, paths); -#if 0 error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs); error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs); -#endif break; } case LinkageType::UNKNOWN: -- cgit v1.2.3 From 968fb2768d7ba8ab7c5c5f352cd63d18dcc3bde3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 9 Nov 2016 17:15:50 -0800 Subject: Rename struct --- toolsrc/src/post_build_lint.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 62f97b88e..1f1351ffd 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -489,9 +489,9 @@ namespace vcpkg return lint_status::SUCCESS; } - struct BuildInfo_and_files + struct BuildType_and_files { - explicit BuildInfo_and_files(const BuildType& build_type) : build_type(build_type) + explicit BuildType_and_files(const BuildType& build_type) : build_type(build_type) { } @@ -511,10 +511,10 @@ namespace vcpkg std::vector libs_with_multiple_crts; - BuildInfo_and_files libs_with_debug_static_crt(BuildType::DEBUG_STATIC); - BuildInfo_and_files libs_with_debug_dynamic_crt(BuildType::DEBUG_DYNAMIC); - BuildInfo_and_files libs_with_release_static_crt(BuildType::RELEASE_STATIC); - BuildInfo_and_files libs_with_release_dynamic_crt(BuildType::RELEASE_DYNAMIC); + BuildType_and_files libs_with_debug_static_crt(BuildType::DEBUG_STATIC); + BuildType_and_files libs_with_debug_dynamic_crt(BuildType::DEBUG_DYNAMIC); + BuildType_and_files libs_with_release_static_crt(BuildType::RELEASE_STATIC); + BuildType_and_files libs_with_release_dynamic_crt(BuildType::RELEASE_DYNAMIC); for (const fs::path& lib : libs) { @@ -569,11 +569,11 @@ namespace vcpkg output_status = lint_status::ERROR_DETECTED; } - std::vector group_for_iteration = { + std::vector group_for_iteration = { libs_with_debug_static_crt, libs_with_debug_dynamic_crt, libs_with_release_static_crt, libs_with_release_dynamic_crt}; - for (const BuildInfo_and_files& bif : group_for_iteration) + for (const BuildType_and_files& bif : group_for_iteration) { if (!bif.files.empty() && bif.build_type != expected_build_type) { -- cgit v1.2.3 From bf7978dcf962c8ff37b3319121e60eb1629be684 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 9 Nov 2016 18:44:11 -0800 Subject: [post-build-checks] Rework crt linkage checks --- toolsrc/src/BuildInfo.cpp | 31 +++++++++++--- toolsrc/src/post_build_lint.cpp | 94 +++++++++-------------------------------- 2 files changed, 43 insertions(+), 82 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 2e74eefc3..4b533ca8f 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -4,14 +4,31 @@ namespace vcpkg { - std::string BuildType::toString() const + const ConfigurationType& BuildType::config() const { - return Strings::format("[%s,%s]", to_string(config), to_string(linkage)); + return this->m_config; + } + + const LinkageType& BuildType::linkage() const + { + return this->m_linkage; + } + + const std::regex& BuildType::crt_regex() const + { + static const std::regex r(this->m_crt_regex_as_string); + return r; + } + + const std::string& BuildType::toString() const + { + static const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); + return s; } bool operator==(const BuildType& lhs, const BuildType& rhs) { - return lhs.config == rhs.config && lhs.linkage == rhs.linkage; + return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); } bool operator!=(const BuildType& lhs, const BuildType& rhs) @@ -35,10 +52,10 @@ namespace vcpkg return build_info; } - const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC); - const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC); - const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC); - const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC); + const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); + const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); + const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); + const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); LinkageType linkage_type_value_of(const std::string& as_string) diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 1f1351ffd..c7bdf7d21 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -489,32 +489,18 @@ namespace vcpkg return lint_status::SUCCESS; } - struct BuildType_and_files + struct BuildType_and_file { - explicit BuildType_and_files(const BuildType& build_type) : build_type(build_type) - { - } - + fs::path file; BuildType build_type; - std::vector files; }; static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs) { - static const std::regex DEBUG_STATIC_CRT(R"(/DEFAULTLIB:LIBCMTD)"); - static const std::regex DEBUG_DYNAMIC_CRT(R"(/DEFAULTLIB:MSVCRTD)"); - - static const std::regex RELEASE_STATIC_CRT(R"(/DEFAULTLIB:LIBCMT[^D])"); - static const std::regex RELEASE_DYNAMIC_CRT(R"(/DEFAULTLIB:MSVCRT[^D])"); + std::vector bad_build_types = BuildType::values(); + bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end()); - lint_status output_status = lint_status::SUCCESS; - - std::vector libs_with_multiple_crts; - - BuildType_and_files libs_with_debug_static_crt(BuildType::DEBUG_STATIC); - BuildType_and_files libs_with_debug_dynamic_crt(BuildType::DEBUG_DYNAMIC); - BuildType_and_files libs_with_release_static_crt(BuildType::RELEASE_STATIC); - BuildType_and_files libs_with_release_dynamic_crt(BuildType::RELEASE_DYNAMIC); + std::vector libs_with_invalid_crt; for (const fs::path& lib : libs) { @@ -522,73 +508,31 @@ namespace vcpkg System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); - bool found_debug_static_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), DEBUG_STATIC_CRT); - bool found_debug_dynamic_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), DEBUG_DYNAMIC_CRT); - bool found_release_static_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), RELEASE_STATIC_CRT); - bool found_release_dynamic_crt = std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), RELEASE_DYNAMIC_CRT); - - const size_t crts_found_count = found_debug_static_crt + found_debug_dynamic_crt + found_release_static_crt + found_release_dynamic_crt; - - if (crts_found_count == 0) - { - // It can be valid for no crt to be detected. For example: openssl - continue; - } - - if (crts_found_count > 1) - { - libs_with_multiple_crts.push_back(lib); - continue; - } - - // now we have exactly 1 crt - if (found_debug_static_crt) - { - libs_with_debug_static_crt.files.push_back(lib); - continue; - } - if (found_debug_dynamic_crt) + for (const BuildType& bad_build_type : bad_build_types) { - libs_with_debug_dynamic_crt.files.push_back(lib); - continue; - } - - if (found_release_static_crt) - { - libs_with_release_static_crt.files.push_back(lib); - continue; + if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex())) + { + libs_with_invalid_crt.push_back({lib, bad_build_type}); + break; + } } - - libs_with_release_dynamic_crt.files.push_back(lib); } - if (!libs_with_multiple_crts.empty()) + if (!libs_with_invalid_crt.empty()) { - System::println(System::color::warning, "Detected multiple crt linkages for the following libs:"); - print_vector_of_files(libs_with_multiple_crts); - output_status = lint_status::ERROR_DETECTED; - } - - std::vector group_for_iteration = { - libs_with_debug_static_crt, libs_with_debug_dynamic_crt, - libs_with_release_static_crt, libs_with_release_dynamic_crt}; - - for (const BuildType_and_files& bif : group_for_iteration) - { - if (!bif.files.empty() && bif.build_type != expected_build_type) + System::println(System::color::warning, "Expected %s crt linkage, but the following libs had invalid crt linkage:", expected_build_type.toString()); + System::println(""); + for (const BuildType_and_file btf : libs_with_invalid_crt) { - System::println(System::color::warning, "Expected %s crt linkage, but the following libs had %s crt linkage:", expected_build_type.toString(), bif.build_type.toString()); - print_vector_of_files(bif.files); - output_status = lint_status::ERROR_DETECTED; + System::println(" %s: %s", btf.file.generic_string(), btf.build_type.toString()); } - } + System::println(""); - if (output_status == lint_status::ERROR_DETECTED) - { System::println(System::color::warning, "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); + return lint_status::ERROR_DETECTED; } - return output_status; + return lint_status::SUCCESS; } static void operator +=(size_t& left, const lint_status& right) -- cgit v1.2.3 From 22f681c82d584a9962a0133ef086326f41df9cc1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 10 Nov 2016 00:04:44 -0800 Subject: Make crt search case insensitive --- 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 4b533ca8f..5fcf8ac09 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -16,7 +16,7 @@ namespace vcpkg const std::regex& BuildType::crt_regex() const { - static const std::regex r(this->m_crt_regex_as_string); + static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; } -- cgit v1.2.3 From eb7ca47d4839a6bf8cea36cba8507750cd5d7746 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 10 Nov 2016 11:04:33 -0800 Subject: Add checks for outdated crts --- toolsrc/src/BuildInfo.cpp | 21 +++++++++++++++++- toolsrc/src/post_build_lint.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 5fcf8ac09..f262df56f 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -87,7 +87,6 @@ namespace vcpkg } std::string to_string(const ConfigurationType& conf) - { switch (conf) { @@ -132,4 +131,24 @@ namespace vcpkg return BuildInfo::create(pghs[0]); } + + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; + + const std::regex& OutdatedDynamicCrt::crt_regex() const + { + static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + const std::string& OutdatedDynamicCrt::toString() const + { + return this->m_dll_name; + } } diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index c7bdf7d21..1a5f22f0a 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -535,6 +535,51 @@ namespace vcpkg return lint_status::SUCCESS; } + struct OutdatedDynamicCrt_and_file + { + fs::path file; + OutdatedDynamicCrt outdated_crt; + }; + + static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls) + { + const std::vector outdated_crts = OutdatedDynamicCrt::values(); + + std::vector dlls_with_outdated_crt; + + for (const fs::path& dll : dlls) + { + const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", DUMPBIN_EXE.native(), dll.native()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + + for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) + { + if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.crt_regex())) + { + dlls_with_outdated_crt.push_back({dll, outdated_crt}); + break; + } + } + } + + if (!dlls_with_outdated_crt.empty()) + { + System::println(System::color::warning, "Detected outdated dynamic CRT in the following files:"); + System::println(""); + for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt) + { + System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.toString()); + } + System::println(""); + + System::println(System::color::warning, "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -584,6 +629,8 @@ namespace vcpkg error_count += check_exports_of_dlls(dlls); error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls); error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); + + error_count += check_outdated_crt_linkage_of_dlls(dlls); break; } case LinkageType::STATIC: -- cgit v1.2.3 From 7220f54e302ce4792868c4ff59b8146c54d2e88c Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Thu, 10 Nov 2016 11:48:36 -0800 Subject: [vcpkg] Correct unsigned/signed mismatch '<' --- toolsrc/src/vcpkg_Strings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index c53cba1fc..19ba8595f 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -77,7 +77,7 @@ namespace vcpkg {namespace Strings output.append(v.at(0)); - for (int i = 1; i < size; ++i) + for (size_t i = 1; i < size; ++i) { output.append(delimiter); output.append(v.at(i)); -- cgit v1.2.3 From d852d3b6f230a55878d7be26fba210cfc67689d1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 10 Nov 2016 16:28:10 -0800 Subject: Add more blacklisted outdated crts --- toolsrc/src/BuildInfo.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index f262df56f..1f802869f 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -141,6 +141,16 @@ namespace vcpkg const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; + const std::regex& OutdatedDynamicCrt::crt_regex() const { static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); -- cgit v1.2.3 From 2584f3e3def7f09bc373117985013ac019aa76d6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 11:56:46 -0800 Subject: Major refactor/rework of dependency resolution --- toolsrc/src/commands_installation.cpp | 100 ++++++++++++++++--------------- toolsrc/src/vcpkg.cpp | 36 +++++++++++ toolsrc/src/vcpkg_Dependencies.cpp | 110 ++++++++++++---------------------- 3 files changed, 127 insertions(+), 119 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 460fa1818..b900b56c8 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -9,7 +9,6 @@ #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" #include "vcpkg_Maps.h" -#include "Paragraphs.h" #include "vcpkg_info.h" namespace vcpkg @@ -21,17 +20,15 @@ namespace vcpkg std::ofstream(binary_control_file) << bpgh; } - static void build_internal(const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) + static void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { - auto pghs = Paragraphs::get_paragraphs(port_dir / "CONTROL"); - Checks::check_exit(pghs.size() == 1, "Error: invalid control file"); - SourceParagraph source_paragraph(pghs[0]); + Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); + auto&& target_triplet = spec.target_triplet(); const fs::path ports_cmake_script_path = paths.ports_cmake; - auto&& target_triplet = spec.target_triplet(); const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", Strings::utf8_to_utf16(target_triplet.architecture()), - Strings::utf8_to_utf16(spec.name()), + Strings::utf8_to_utf16(source_paragraph.name), Strings::utf8_to_utf16(target_triplet.canonical_name()), port_dir.generic_wstring(), ports_cmake_script_path.generic_wstring()); @@ -65,11 +62,6 @@ namespace vcpkg // delete_directory(port_buildtrees_dir); } - static void build_internal(const package_spec& spec, const vcpkg_paths& paths) - { - return build_internal(spec, paths, paths.ports / spec.name()); - } - 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"); @@ -78,49 +70,47 @@ namespace vcpkg std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); Input::check_triplets(specs, paths); - std::vector install_plan = Dependencies::create_dependency_ordered_install_plan(paths, specs, status_db); + auto install_plan = Dependencies::create_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); - std::string specs_string = to_string(install_plan[0]); + + std::string specs_string = to_string(install_plan[0].first); for (size_t i = 1; i < install_plan.size(); ++i) { specs_string.push_back(','); - specs_string.append(to_string(install_plan[i])); + specs_string.append(to_string(install_plan[i].first)); } TrackProperty("installplan", specs_string); Environment::ensure_utilities_on_path(paths); - for (const package_spec& spec : install_plan) + for (const auto& action : install_plan) { - if (status_db.find_installed(spec.name(), spec.target_triplet()) != status_db.end()) - { - System::println(System::color::success, "Package %s is already installed", spec); - continue; - } - - fs::path package_path = paths.package_dir(spec); - - expected file_contents = Files::get_contents(package_path / "CONTROL"); - try { - if (file_contents.error_code()) + if (action.second.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED) { - build_internal(spec, paths); - file_contents = Files::get_contents(package_path / "CONTROL"); - if (file_contents.error_code()) + if (std::find(specs.begin(), specs.end(), action.first) != specs.end()) { - file_contents.get_or_throw(); + System::println(System::color::success, "Package %s is already installed", action.first); } } - - auto pghs = Paragraphs::parse_paragraphs(file_contents.get_or_throw()); - Checks::check_throw(pghs.size() == 1, "multiple paragraphs in control file"); - install_package(paths, BinaryParagraph(pghs[0]), status_db); - System::println(System::color::success, "Package %s is installed", spec); + else if (action.second.plan == Dependencies::install_plan_kind::BUILD_AND_INSTALL) + { + build_internal(*action.second.spgh, action.first, paths, paths.port_dir(action.first)); + auto bpgh = try_load_cached_package(paths, action.first).get_or_throw(); + install_package(paths, bpgh, status_db); + System::println(System::color::success, "Package %s is installed", action.first); + } + else if (action.second.plan == Dependencies::install_plan_kind::INSTALL) + { + install_package(paths, *action.second.bpgh, status_db); + System::println(System::color::success, "Package %s is installed", action.first); + } + else + Checks::unreachable(); } catch (const std::exception& e) { - System::println(System::color::error, "Error: Could not install package %s: %s", spec, e.what()); + System::println(System::color::error, "Error: Could not install package %s: %s", action.first, e.what()); exit(EXIT_FAILURE); } } @@ -142,29 +132,41 @@ namespace vcpkg Input::check_triplet(spec.target_triplet(), paths); // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). - auto first_level_deps = Dependencies::get_unmet_package_build_dependencies(paths, spec); + auto maybe_spgh = try_load_port(paths, spec.name()); + Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); + auto& spgh = *maybe_spgh.get(); + + auto first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); + std::vector first_level_deps_specs; for (auto&& dep : first_level_deps) { first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); } - std::unordered_set unmet_dependencies = Dependencies::get_unmet_dependencies(paths, first_level_deps_specs, status_db); + auto unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); + unmet_dependencies.erase( + std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](auto& p) + { + return p.second.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED; + }), + unmet_dependencies.end()); + if (!unmet_dependencies.empty()) { 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 package_spec& p : unmet_dependencies) + for (const auto& p : unmet_dependencies) { - System::println(" %s", to_string(p)); + System::println(" %s", to_string(p.first)); } System::println(""); exit(EXIT_FAILURE); } Environment::ensure_utilities_on_path(paths); - build_internal(spec, paths); + build_internal(spgh, spec, paths, paths.port_dir(spec)); exit(EXIT_SUCCESS); } @@ -173,17 +175,21 @@ namespace vcpkg static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); args.check_exact_arg_count(2, example.c_str()); - expected current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); - if (auto spec = current_spec.get()) + expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); + if (auto spec = maybe_current_spec.get()) { Input::check_triplet(spec->target_triplet(), paths); Environment::ensure_utilities_on_path(paths); const fs::path port_dir = args.command_arguments.at(1); - build_internal(*spec, paths, port_dir); - exit(EXIT_SUCCESS); + auto maybe_spgh = try_load_port(port_dir); + if (auto spgh = maybe_spgh.get()) + { + build_internal(*spgh, *spec, paths, port_dir); + exit(EXIT_SUCCESS); + } } - System::println(System::color::error, "Error: %s: %s", current_spec.error_code().message(), args.command_arguments[0]); + System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); print_example(Strings::format("%s zlib:x64-windows", args.command).c_str()); exit(EXIT_FAILURE); } diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6e47df2c8..db85eee8f 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -369,3 +369,39 @@ void vcpkg::deinstall_package(const vcpkg_paths& paths, const package_spec& spec 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 + { + auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); + return SourceParagraph(pghs[0]); + } + catch (std::runtime_error const&) + { + } + + return std::errc::no_such_file_or_directory; +} + +expected vcpkg::try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec) +{ + const fs::path path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::get_contents(path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", path.string()); + return BinaryParagraph(pghs[0]); + } + return control_contents_maybe.error_code(); +} diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index c054ec913..3142b44ba 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -7,40 +7,17 @@ #include #include "vcpkg_Maps.h" #include "vcpkg_Files.h" -#include "Paragraphs.h" +#include "vcpkg.h" namespace vcpkg { namespace Dependencies { - // TODO: Refactoring between this function and install_package - static std::vector get_single_level_unmet_dependencies(const vcpkg_paths& paths, const package_spec& spec) + std::vector> create_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { - const fs::path packages_dir_control_file_path = paths.package_dir(spec) / "CONTROL"; - - auto control_contents_maybe = Files::get_contents(packages_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", packages_dir_control_file_path.string()); - return BinaryParagraph(pghs[0]).depends; - } - - return get_unmet_package_build_dependencies(paths, spec); - } - - static Graphs::Graph build_dependency_graph(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) - { - std::vector examine_stack(specs); - std::unordered_set was_examined; // Examine = we have checked its immediate (non-recursive) dependencies + std::unordered_map was_examined; // Examine = we have checked its immediate (non-recursive) dependencies Graphs::Graph graph; - graph.add_vertices(examine_stack); + graph.add_vertices(specs); + std::vector examine_stack(specs); while (!examine_stack.empty()) { const package_spec spec = examine_stack.back(); @@ -51,59 +28,48 @@ namespace vcpkg { namespace Dependencies continue; } - std::vector dependencies_as_string = get_single_level_unmet_dependencies(paths, spec); + auto process_dependencies = [&](const std::vector& dependencies_as_string) + { + for (const std::string& dep_as_string : dependencies_as_string) + { + const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw(); + graph.add_edge(spec, current_dep); + if (was_examined.find(current_dep) == was_examined.end()) + { + examine_stack.push_back(std::move(current_dep)); + } + } + }; - for (const std::string& dep_as_string : dependencies_as_string) + auto it = status_db.find(spec); + if (it != status_db.end() && (*it)->want == want_t::install) { - const package_spec current_dep = package_spec::from_name_and_triplet(dep_as_string, spec.target_triplet()).get_or_throw(); - auto it = status_db.find(current_dep.name(), current_dep.target_triplet()); - if (it != status_db.end() && (*it)->want == want_t::install) - { - continue; - } + was_examined.emplace(spec, install_plan_action{install_plan_kind::ALREADY_INSTALLED, nullptr, nullptr}); + continue; + } - graph.add_edge(spec, current_dep); - if (was_examined.find(current_dep) == was_examined.end()) - { - examine_stack.push_back(std::move(current_dep)); - } + expected maybe_bpgh = try_load_cached_package(paths, spec); + if (BinaryParagraph* bpgh = maybe_bpgh.get()) + { + process_dependencies(bpgh->depends); + was_examined.emplace(spec, install_plan_action{install_plan_kind::INSTALL, std::make_unique(std::move(*bpgh)), nullptr}); + continue; } - was_examined.insert(spec); + expected maybe_spgh = try_load_port(paths, spec.name()); + SourceParagraph* spgh = maybe_spgh.get(); + Checks::check_exit(spgh != nullptr, "Cannot find package"); + process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet())); + was_examined.emplace(spec, install_plan_action{install_plan_kind::BUILD_AND_INSTALL, nullptr, std::make_unique(std::move(*spgh))}); } - return graph; - } - - std::vector create_dependency_ordered_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) - { - return build_dependency_graph(paths, specs, status_db).find_topological_sort(); - } - - std::unordered_set get_unmet_dependencies(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) - { - const Graphs::Graph dependency_graph = build_dependency_graph(paths, specs, status_db); - return Maps::extract_key_set(dependency_graph.adjacency_list()); - } + std::vector> ret; - std::vector get_unmet_package_build_dependencies(const vcpkg_paths& paths, const package_spec& spec) - { - const fs::path ports_dir_control_file_path = paths.port_dir(spec) / "CONTROL"; - auto control_contents_maybe = Files::get_contents(ports_dir_control_file_path); - if (auto control_contents = control_contents_maybe.get()) + std::vector pkgs = graph.find_topological_sort(); + for (package_spec& pkg : pkgs) { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", ports_dir_control_file_path.string()); - return filter_dependencies(SourceParagraph(pghs[0]).depends, spec.target_triplet()); + ret.emplace_back(pkg, std::move(was_examined[pkg])); } - - Checks::exit_with_message("Could not find package named %s", spec); + return ret; } }} -- cgit v1.2.3 From 2b204e673914b20e662ed17f667c267690fd6b52 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 11:56:46 -0800 Subject: Use custom struct instead of std::pair --- toolsrc/src/commands_installation.cpp | 34 +++++++++++++++++----------------- toolsrc/src/vcpkg_Dependencies.cpp | 10 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index b900b56c8..4535484b6 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -73,11 +73,11 @@ namespace vcpkg auto install_plan = Dependencies::create_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); - std::string specs_string = to_string(install_plan[0].first); + std::string specs_string = to_string(install_plan[0].spec); for (size_t i = 1; i < install_plan.size(); ++i) { specs_string.push_back(','); - specs_string.append(to_string(install_plan[i].first)); + specs_string.append(to_string(install_plan[i].spec)); } TrackProperty("installplan", specs_string); Environment::ensure_utilities_on_path(paths); @@ -86,31 +86,31 @@ namespace vcpkg { try { - if (action.second.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED) + if (action.install_plan.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED) { - if (std::find(specs.begin(), specs.end(), action.first) != specs.end()) + if (std::find(specs.begin(), specs.end(), action.spec) != specs.end()) { - System::println(System::color::success, "Package %s is already installed", action.first); + System::println(System::color::success, "Package %s is already installed", action.spec); } } - else if (action.second.plan == Dependencies::install_plan_kind::BUILD_AND_INSTALL) + else if (action.install_plan.plan == Dependencies::install_plan_kind::BUILD_AND_INSTALL) { - build_internal(*action.second.spgh, action.first, paths, paths.port_dir(action.first)); - auto bpgh = try_load_cached_package(paths, action.first).get_or_throw(); + build_internal(*action.install_plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + auto bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); - System::println(System::color::success, "Package %s is installed", action.first); + System::println(System::color::success, "Package %s is installed", action.spec); } - else if (action.second.plan == Dependencies::install_plan_kind::INSTALL) + else if (action.install_plan.plan == Dependencies::install_plan_kind::INSTALL) { - install_package(paths, *action.second.bpgh, status_db); - System::println(System::color::success, "Package %s is installed", action.first); + install_package(paths, *action.install_plan.bpgh, status_db); + System::println(System::color::success, "Package %s is installed", action.spec); } else Checks::unreachable(); } catch (const std::exception& e) { - System::println(System::color::error, "Error: Could not install package %s: %s", action.first, e.what()); + System::println(System::color::error, "Error: Could not install package %s: %s", action.spec, e.what()); exit(EXIT_FAILURE); } } @@ -144,11 +144,11 @@ namespace vcpkg first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); } - auto unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); + std::vector unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); unmet_dependencies.erase( - std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](auto& p) + std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const Dependencies::package_spec_with_install_plan& p) { - return p.second.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED; + return p.install_plan.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED; }), unmet_dependencies.end()); @@ -159,7 +159,7 @@ namespace vcpkg System::println(""); for (const auto& p : unmet_dependencies) { - System::println(" %s", to_string(p.first)); + System::println(" %s", to_string(p.spec)); } System::println(""); exit(EXIT_FAILURE); diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 3142b44ba..2b7e132cc 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -11,7 +11,7 @@ namespace vcpkg { namespace Dependencies { - std::vector> create_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) + std::vector create_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { std::unordered_map was_examined; // Examine = we have checked its immediate (non-recursive) dependencies Graphs::Graph graph; @@ -63,12 +63,12 @@ namespace vcpkg { namespace Dependencies was_examined.emplace(spec, install_plan_action{install_plan_kind::BUILD_AND_INSTALL, nullptr, std::make_unique(std::move(*spgh))}); } - std::vector> ret; + std::vector ret; - std::vector pkgs = graph.find_topological_sort(); - for (package_spec& pkg : pkgs) + const std::vector pkgs = graph.find_topological_sort(); + for (const package_spec& pkg : pkgs) { - ret.emplace_back(pkg, std::move(was_examined[pkg])); + ret.push_back({ pkg, std::move(was_examined[pkg]) }); } return ret; } -- cgit v1.2.3 From b64b0cbc8a34e5761fbf7fda75fda49906f116ea Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 11:56:46 -0800 Subject: Renames and cleanup --- toolsrc/src/commands_installation.cpp | 41 +++++++++++++++++++---------------- toolsrc/src/vcpkg_Dependencies.cpp | 6 ++--- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 4535484b6..0f0cfc954 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -13,9 +13,12 @@ namespace vcpkg { + using Dependencies::package_spec_with_install_plan; + using Dependencies::install_plan_type; + static void create_binary_control_file(const vcpkg_paths& paths, const SourceParagraph& source_paragraph, const triplet& target_triplet) { - auto bpgh = BinaryParagraph(source_paragraph, target_triplet); + const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, target_triplet); const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL"; std::ofstream(binary_control_file) << bpgh; } @@ -23,7 +26,7 @@ namespace vcpkg static void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); - auto&& target_triplet = spec.target_triplet(); + const triplet& target_triplet = spec.target_triplet(); const fs::path ports_cmake_script_path = paths.ports_cmake; const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", @@ -70,7 +73,7 @@ namespace vcpkg std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); Input::check_triplets(specs, paths); - auto install_plan = Dependencies::create_install_plan(paths, specs, status_db); + std::vector install_plan = Dependencies::create_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); std::string specs_string = to_string(install_plan[0].spec); @@ -82,27 +85,27 @@ namespace vcpkg TrackProperty("installplan", specs_string); Environment::ensure_utilities_on_path(paths); - for (const auto& action : install_plan) + for (const package_spec_with_install_plan& action : install_plan) { try { - if (action.install_plan.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED) + if (action.plan.type == install_plan_type::ALREADY_INSTALLED) { if (std::find(specs.begin(), specs.end(), action.spec) != specs.end()) { System::println(System::color::success, "Package %s is already installed", action.spec); } } - else if (action.install_plan.plan == Dependencies::install_plan_kind::BUILD_AND_INSTALL) + else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) { - build_internal(*action.install_plan.spgh, action.spec, paths, paths.port_dir(action.spec)); - auto bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); + build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); } - else if (action.install_plan.plan == Dependencies::install_plan_kind::INSTALL) + else if (action.plan.type == install_plan_type::INSTALL) { - install_package(paths, *action.install_plan.bpgh, status_db); + install_package(paths, *action.plan.bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); } else @@ -132,23 +135,23 @@ namespace vcpkg Input::check_triplet(spec.target_triplet(), paths); // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). - auto maybe_spgh = try_load_port(paths, spec.name()); + const expected maybe_spgh = try_load_port(paths, spec.name()); Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); - auto& spgh = *maybe_spgh.get(); + const SourceParagraph& spgh = *maybe_spgh.get(); - auto first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); + const std::vector first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); std::vector first_level_deps_specs; - for (auto&& dep : first_level_deps) + for (const std::string& dep : first_level_deps) { first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); } - std::vector unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); + std::vector unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); unmet_dependencies.erase( - std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const Dependencies::package_spec_with_install_plan& p) + std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const package_spec_with_install_plan& p) { - return p.install_plan.plan == Dependencies::install_plan_kind::ALREADY_INSTALLED; + return p.plan.type == install_plan_type::ALREADY_INSTALLED; }), unmet_dependencies.end()); @@ -157,7 +160,7 @@ namespace vcpkg 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 : unmet_dependencies) + for (const package_spec_with_install_plan& p : unmet_dependencies) { System::println(" %s", to_string(p.spec)); } @@ -181,7 +184,7 @@ namespace vcpkg Input::check_triplet(spec->target_triplet(), paths); Environment::ensure_utilities_on_path(paths); const fs::path port_dir = args.command_arguments.at(1); - auto maybe_spgh = try_load_port(port_dir); + const expected maybe_spgh = try_load_port(port_dir); if (auto spgh = maybe_spgh.get()) { build_internal(*spgh, *spec, paths, port_dir); diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 2b7e132cc..41172ba0f 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -44,7 +44,7 @@ namespace vcpkg { namespace Dependencies auto it = status_db.find(spec); if (it != status_db.end() && (*it)->want == want_t::install) { - was_examined.emplace(spec, install_plan_action{install_plan_kind::ALREADY_INSTALLED, nullptr, nullptr}); + was_examined.emplace(spec, install_plan_action{install_plan_type::ALREADY_INSTALLED, nullptr, nullptr}); continue; } @@ -52,7 +52,7 @@ namespace vcpkg { namespace Dependencies if (BinaryParagraph* bpgh = maybe_bpgh.get()) { process_dependencies(bpgh->depends); - was_examined.emplace(spec, install_plan_action{install_plan_kind::INSTALL, std::make_unique(std::move(*bpgh)), nullptr}); + was_examined.emplace(spec, install_plan_action{install_plan_type::INSTALL, std::make_unique(std::move(*bpgh)), nullptr}); continue; } @@ -60,7 +60,7 @@ namespace vcpkg { namespace Dependencies SourceParagraph* spgh = maybe_spgh.get(); Checks::check_exit(spgh != nullptr, "Cannot find package"); process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet())); - was_examined.emplace(spec, install_plan_action{install_plan_kind::BUILD_AND_INSTALL, nullptr, std::make_unique(std::move(*spgh))}); + was_examined.emplace(spec, install_plan_action{install_plan_type::BUILD_AND_INSTALL, nullptr, std::make_unique(std::move(*spgh))}); } std::vector ret; -- cgit v1.2.3 From a882cfe14f28979e453e92786b1a3ff82a28904b Mon Sep 17 00:00:00 2001 From: Geert Van Laethem Date: Tue, 15 Nov 2016 15:26:16 +0100 Subject: possible fix for issue #223 --- toolsrc/src/coff_file_reader.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index f46150979..0b14abcc8 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -8,7 +8,7 @@ using namespace std; -namespace vcpkg {namespace COFFFileReader +namespace vcpkg { namespace COFFFileReader { template static T reinterpret_bytes(const char* data) @@ -36,7 +36,7 @@ namespace vcpkg {namespace COFFFileReader static void verify_equal_strings(const char* expected, const char* actual, int size, const char* label) { - Checks::check_exit(memcmp(expected, actual, size) == 0, "Incorrect string (%s) found. Expected: %s but found %s", label, expected, actual); + Checks::check_exit(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) @@ -113,8 +113,11 @@ namespace vcpkg {namespace COFFFileReader ret.data.resize(HEADER_SIZE); fs.read(&ret.data[0], HEADER_SIZE); - const std::string header_end = ret.data.substr(HEADER_END_OFFSET, HEADER_END_SIZE); - verify_equal_strings(HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); + if (ret.data[0] != '\0') + { + const std::string header_end = ret.data.substr(HEADER_END_OFFSET, HEADER_END_SIZE); + verify_equal_strings(HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); + } return ret; } @@ -251,10 +254,13 @@ namespace vcpkg {namespace COFFFileReader for (uint32_t i = 0; i < archive_member_count; i++) { const archive_member_header header = archive_member_header::read(fs); - const uint16_t first_two_bytes = peek_value_from_stream(fs); - const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; - const MachineType machine = isImportHeader ? import_header::peek(fs).machineType() : coff_file_header::peek(fs).machineType(); - machine_types.insert(machine); + if (header.data[0] != '\0') + { + const uint16_t first_two_bytes = peek_value_from_stream(fs); + const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; + const MachineType machine = isImportHeader ? import_header::peek(fs).machineType() : coff_file_header::peek(fs).machineType(); + machine_types.insert(machine); + } skip_archive_member(fs, header.member_size()); } -- cgit v1.2.3 From 45dbe92e9be6683a23e954a0106f54645377c191 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 17:06:00 -0800 Subject: Add comment about freeglut in coff_file_reader.cpp --- toolsrc/src/coff_file_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 0b14abcc8..5a53dcae6 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -113,7 +113,7 @@ namespace vcpkg { namespace COFFFileReader ret.data.resize(HEADER_SIZE); fs.read(&ret.data[0], HEADER_SIZE); - if (ret.data[0] != '\0') + 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(HEADER_END, header_end.c_str(), HEADER_END_SIZE, "LIB HEADER_END"); @@ -254,7 +254,7 @@ namespace vcpkg { namespace COFFFileReader for (uint32_t i = 0; i < archive_member_count; i++) { const archive_member_header header = archive_member_header::read(fs); - if (header.data[0] != '\0') + if (header.data[0] != '\0') // Due to freeglut. github issue #223 { const uint16_t first_two_bytes = peek_value_from_stream(fs); const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; -- cgit v1.2.3 From e969c5c8eb2429436de35eab3cbe34133566a380 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 17:41:31 -0800 Subject: Remove unused #includes --- toolsrc/src/coff_file_reader.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 5a53dcae6..db8524faa 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -1,7 +1,5 @@ #include "coff_file_reader.h" #include -#include -#include #include "vcpkg_Checks.h" #include #include -- cgit v1.2.3 From 31b8eee587c4a29894247833198d5e1e15ba9bba Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 17:42:42 -0800 Subject: Use the already loaded status_db --- toolsrc/src/commands_update.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 2d7444392..82e3b7e52 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -37,7 +37,7 @@ namespace vcpkg std::string packages_list; std::vector packages_output; - for (auto&& pgh : database_load_check(paths)) + for (auto&& pgh : status_db) { if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge) continue; -- cgit v1.2.3 From 42df44ca7bba06dfadb6ac7a0e2c7fe611cd6121 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 15 Nov 2016 17:54:44 -0800 Subject: Add #else to avoid warning --- toolsrc/src/vcpkg_Checks.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 453ba81fd..817ac9e96 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -10,8 +10,9 @@ namespace vcpkg {namespace Checks System::println(System::color::error, "Error: Unreachable code was reached"); #ifndef NDEBUG std::abort(); -#endif +#else exit(EXIT_FAILURE); +#endif } void exit_with_message(const char* errorMessage) -- cgit v1.2.3 From a9223bd8df10483c9e5497c55c99fdf26cd2a6c2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 15:20:18 -0800 Subject: [coff] Variable rename --- toolsrc/src/coff_file_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index db8524faa..c6bfc33d2 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -195,8 +195,8 @@ namespace vcpkg { namespace COFFFileReader { static const size_t ALIGNMENT_SIZE = 2; - const fpos_t new_offset = align_to(member_size, ALIGNMENT_SIZE); - fs.seekg(new_offset, ios_base::cur); + const fpos_t advance_by = align_to(member_size, ALIGNMENT_SIZE); + fs.seekg(advance_by, ios_base::cur); } static void read_and_verify_archive_file_signature(fstream& fs) -- cgit v1.2.3 From 6c2ce4981f7e463c8187aa62c461da564977cea3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 15:21:22 -0800 Subject: [coff] Function rename --- toolsrc/src/coff_file_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index c6bfc33d2..5dd32bcd5 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -54,7 +54,7 @@ namespace vcpkg { namespace COFFFileReader fs.seekg(offset_to_PE_signature + PE_SIGNATURE_SIZE, ios_base::beg); } - static fpos_t align_to(const fpos_t unaligned_offset, const int alignment_size) + static fpos_t align_offset_to_size(const fpos_t unaligned_offset, const int alignment_size) { fpos_t aligned_offset = unaligned_offset - 1; aligned_offset /= alignment_size; @@ -195,7 +195,7 @@ namespace vcpkg { namespace COFFFileReader { static const size_t ALIGNMENT_SIZE = 2; - const fpos_t advance_by = align_to(member_size, ALIGNMENT_SIZE); + const fpos_t advance_by = align_offset_to_size(member_size, ALIGNMENT_SIZE); fs.seekg(advance_by, ios_base::cur); } -- cgit v1.2.3 From c82847682397ed084aec0a69074a3985f7fb18f9 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 15:42:20 -0800 Subject: Add (undocumented) --checks-only option to the build command --- toolsrc/src/commands_installation.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 0f0cfc954..f7af2ef7c 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -13,9 +13,11 @@ namespace vcpkg { - using Dependencies::package_spec_with_install_plan; + using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; + static const std::string OPTION_CHECKS_ONLY = "--checks-only"; + static void create_binary_control_file(const vcpkg_paths& paths, const SourceParagraph& source_paragraph, const triplet& target_triplet) { const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, target_triplet); @@ -129,11 +131,19 @@ namespace vcpkg // Allowing only 1 package for now. args.check_exact_arg_count(1, example.c_str()); + StatusParagraphs status_db = database_load_check(paths); const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); Input::check_triplet(spec.target_triplet(), paths); + 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); + exit(EXIT_SUCCESS); + } + // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). const expected maybe_spgh = try_load_port(paths, spec.name()); Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); -- cgit v1.2.3 From 9ab1ea53313b7db5c6fc695643dc896b294238c9 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 15:43:47 -0800 Subject: [coff] member_size() now returns already aligned size --- toolsrc/src/coff_file_reader.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 5dd32bcd5..1766cf8e9 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -54,13 +54,13 @@ namespace vcpkg { namespace COFFFileReader fs.seekg(offset_to_PE_signature + PE_SIGNATURE_SIZE, ios_base::beg); } - static fpos_t align_offset_to_size(const fpos_t unaligned_offset, const int alignment_size) + static fpos_t align_to_size(const uint64_t unaligned, const uint64_t alignment_size) { - fpos_t aligned_offset = unaligned_offset - 1; - aligned_offset /= alignment_size; - aligned_offset += 1; - aligned_offset *= alignment_size; - return aligned_offset; + fpos_t aligned = unaligned - 1; + aligned /= alignment_size; + aligned += 1; + aligned *= alignment_size; + return aligned; } struct coff_file_header @@ -129,12 +129,16 @@ namespace vcpkg { namespace COFFFileReader uint64_t member_size() const { + static const size_t ALIGNMENT_SIZE = 2; + static const size_t HEADER_SIZE_OFFSET = 48; static const size_t HEADER_SIZE_FIELD_SIZE = 10; const std::string as_string = data.substr(HEADER_SIZE_OFFSET, HEADER_SIZE_FIELD_SIZE); // This is in ASCII decimal representation const uint64_t value = std::strtoull(as_string.c_str(), nullptr, 10); - return value; + + const uint64_t aligned = align_to_size(value, ALIGNMENT_SIZE); + return aligned; } std::string data; @@ -191,14 +195,6 @@ namespace vcpkg { namespace COFFFileReader std::string data; }; - static void skip_archive_member(fstream& fs, uint64_t member_size) - { - static const size_t ALIGNMENT_SIZE = 2; - - const fpos_t advance_by = align_offset_to_size(member_size, ALIGNMENT_SIZE); - fs.seekg(advance_by, ios_base::cur); - } - static void read_and_verify_archive_file_signature(fstream& fs) { static const char* FILE_START = "!\n"; @@ -232,19 +228,19 @@ namespace vcpkg { namespace COFFFileReader // First Linker Member const archive_member_header first_linker_member_header = archive_member_header::read(fs); Checks::check_exit(first_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper first linker member"); - skip_archive_member(fs, first_linker_member_header.member_size()); + fs.seekg(first_linker_member_header.member_size(), ios_base::cur); const archive_member_header second_linker_member_header = archive_member_header::read(fs); Checks::check_exit(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 = peek_value_from_stream(fs); - skip_archive_member(fs, second_linker_member_header.member_size()); + fs.seekg(second_linker_member_header.member_size(), ios_base::cur); bool hasLongnameMemberHeader = peek_value_from_stream(fs) == 0x2F2F; if (hasLongnameMemberHeader) { const archive_member_header longnames_member_header = archive_member_header::read(fs); - skip_archive_member(fs, longnames_member_header.member_size()); + fs.seekg(longnames_member_header.member_size(), ios_base::cur); } std::set machine_types; @@ -259,7 +255,7 @@ namespace vcpkg { namespace COFFFileReader const MachineType machine = isImportHeader ? import_header::peek(fs).machineType() : coff_file_header::peek(fs).machineType(); machine_types.insert(machine); } - skip_archive_member(fs, header.member_size()); + fs.seekg(header.member_size(), ios_base::cur); } return {std::vector(machine_types.cbegin(), machine_types.cend())}; -- cgit v1.2.3 From f0ef09c3fcd78936b8219a7530f17b21911cc8cd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 16:19:46 -0800 Subject: [coff] Introduce marker_t. Eliminate one of the peek functions --- toolsrc/src/coff_file_reader.cpp | 51 ++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 1766cf8e9..9ea79bf99 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -173,14 +173,6 @@ namespace vcpkg { namespace COFFFileReader return ret; } - static import_header peek(fstream& fs) - { - auto original_pos = fs.tellg().seekpos(); - import_header ret = read(fs); - fs.seekg(original_pos); - return ret; - } - MachineType machineType() const { static const size_t MACHINE_TYPE_OFFSET = 6; @@ -218,6 +210,27 @@ namespace vcpkg { namespace COFFFileReader return {machine}; } + struct marker_t + { + 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 advance_by(const uint64_t offset) + { + this->m_absolute_position += offset; + } + + private: + fpos_t m_absolute_position = 0; + }; + lib_info read_lib(const fs::path path) { std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate); @@ -225,23 +238,30 @@ namespace vcpkg { namespace COFFFileReader read_and_verify_archive_file_signature(fs); + marker_t marker; + marker.set_to_current_pos(fs); + // First Linker Member const archive_member_header first_linker_member_header = archive_member_header::read(fs); Checks::check_exit(first_linker_member_header.name().substr(0, 2) == "/ ", "Could not find proper first linker member"); - fs.seekg(first_linker_member_header.member_size(), ios_base::cur); + marker.advance_by(archive_member_header::HEADER_SIZE + first_linker_member_header.member_size()); + marker.seek_to_marker(fs); const archive_member_header second_linker_member_header = archive_member_header::read(fs); Checks::check_exit(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 = peek_value_from_stream(fs); - fs.seekg(second_linker_member_header.member_size(), ios_base::cur); + const uint32_t archive_member_count = read_value_from_stream(fs); + marker.advance_by(archive_member_header::HEADER_SIZE + second_linker_member_header.member_size()); + marker.seek_to_marker(fs); - bool hasLongnameMemberHeader = peek_value_from_stream(fs) == 0x2F2F; + bool hasLongnameMemberHeader = read_value_from_stream(fs) == 0x2F2F; if (hasLongnameMemberHeader) { + marker.seek_to_marker(fs); const archive_member_header longnames_member_header = archive_member_header::read(fs); - fs.seekg(longnames_member_header.member_size(), ios_base::cur); + marker.advance_by(archive_member_header::HEADER_SIZE + longnames_member_header.member_size()); } + marker.seek_to_marker(fs); std::set machine_types; // Next we have the obj and pseudo-object files @@ -252,10 +272,11 @@ namespace vcpkg { namespace COFFFileReader { const uint16_t first_two_bytes = peek_value_from_stream(fs); const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; - const MachineType machine = isImportHeader ? import_header::peek(fs).machineType() : coff_file_header::peek(fs).machineType(); + const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::peek(fs).machineType(); machine_types.insert(machine); } - fs.seekg(header.member_size(), ios_base::cur); + marker.advance_by(archive_member_header::HEADER_SIZE + header.member_size()); + marker.seek_to_marker(fs); } return {std::vector(machine_types.cbegin(), machine_types.cend())}; -- cgit v1.2.3 From c6ac0e5ca74a719a6990f6bba5002883900ad85c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 16:22:22 -0800 Subject: [coff] Eliminate another peek() function --- toolsrc/src/coff_file_reader.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 9ea79bf99..6a2a57159 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -75,14 +75,6 @@ namespace vcpkg { namespace COFFFileReader return ret; } - static coff_file_header peek(fstream& fs) - { - auto original_pos = fs.tellg().seekpos(); - coff_file_header ret = read(fs); - fs.seekg(original_pos); - return ret; - } - MachineType machineType() const { static const size_t MACHINE_TYPE_OFFSET = 0; @@ -272,7 +264,7 @@ namespace vcpkg { namespace COFFFileReader { const uint16_t first_two_bytes = peek_value_from_stream(fs); const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; - const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::peek(fs).machineType(); + const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::read(fs).machineType(); machine_types.insert(machine); } marker.advance_by(archive_member_header::HEADER_SIZE + header.member_size()); -- cgit v1.2.3 From 7805de1a5686f192bc4b174f3a98098505788d5b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 16:28:09 -0800 Subject: [coff] Use peek_value() --- toolsrc/src/coff_file_reader.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 6a2a57159..763443e6e 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -246,14 +246,13 @@ namespace vcpkg { namespace COFFFileReader marker.advance_by(archive_member_header::HEADER_SIZE + second_linker_member_header.member_size()); marker.seek_to_marker(fs); - bool hasLongnameMemberHeader = read_value_from_stream(fs) == 0x2F2F; + bool hasLongnameMemberHeader = peek_value_from_stream(fs) == 0x2F2F; if (hasLongnameMemberHeader) { - marker.seek_to_marker(fs); const archive_member_header longnames_member_header = archive_member_header::read(fs); marker.advance_by(archive_member_header::HEADER_SIZE + longnames_member_header.member_size()); + marker.seek_to_marker(fs); } - marker.seek_to_marker(fs); std::set machine_types; // Next we have the obj and pseudo-object files -- cgit v1.2.3 From ba28195eb8ead2724400c6d0cdf123dbfadadffb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 17 Nov 2016 17:36:30 -0800 Subject: [coff] Read the second linker offsets to deduce the real offset count Those that start with 0 are ignored --- toolsrc/src/coff_file_reader.cpp | 46 +++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 763443e6e..e8bb6089c 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -136,6 +136,38 @@ namespace vcpkg { namespace COFFFileReader std::string data; }; + struct offsets_array + { + static offsets_array read(fstream& fs, const uint32_t offset_count) + { + static const size_t OFFSET_WIDTH = 4; + + std::string raw_offsets; + const size_t raw_offset_size = offset_count * OFFSET_WIDTH; + raw_offsets.resize(raw_offset_size); + fs.read(&raw_offsets[0], raw_offset_size); + + offsets_array ret; + for (uint32_t i = 0; i < offset_count; ++i) + { + const std::string value_as_string = raw_offsets.substr(OFFSET_WIDTH * i, OFFSET_WIDTH * (i + 1)); + const uint32_t value = reinterpret_bytes(value_as_string.c_str()); + + // Ignore offsets that point to offset 0. See vcpkg github #223 #288 #292 + if (value != 0) + { + ret.data.push_back(value); + } + } + + // Sort the offsets, because it is possible for them to be unsorted. See vcpkg github #292 + std::sort(ret.data.begin(), ret.data.end()); + return ret; + } + + std::vector data; + }; + struct import_header { static const size_t HEADER_SIZE = 20; @@ -243,6 +275,7 @@ namespace vcpkg { namespace COFFFileReader Checks::check_exit(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(fs); + const offsets_array offsets = offsets_array::read(fs, archive_member_count); marker.advance_by(archive_member_header::HEADER_SIZE + second_linker_member_header.member_size()); marker.seek_to_marker(fs); @@ -256,16 +289,13 @@ namespace vcpkg { namespace COFFFileReader std::set machine_types; // Next we have the obj and pseudo-object files - for (uint32_t i = 0; i < archive_member_count; i++) + for (uint32_t i = 0; i < offsets.data.size(); i++) { const archive_member_header header = archive_member_header::read(fs); - if (header.data[0] != '\0') // Due to freeglut. github issue #223 - { - const uint16_t first_two_bytes = peek_value_from_stream(fs); - const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; - const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::read(fs).machineType(); - machine_types.insert(machine); - } + const uint16_t first_two_bytes = peek_value_from_stream(fs); + const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; + const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::read(fs).machineType(); + machine_types.insert(machine); marker.advance_by(archive_member_header::HEADER_SIZE + header.member_size()); marker.seek_to_marker(fs); } -- cgit v1.2.3 From 26a8ed58becf42c2c448aa9ee7621ed2c26319fc Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 18 Nov 2016 13:36:45 -0800 Subject: [coff] Use the offsets_array to go to archive members. Fixes #292 --- toolsrc/src/coff_file_reader.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index e8bb6089c..3bf7922f5 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -236,6 +236,11 @@ namespace vcpkg { namespace COFFFileReader struct marker_t { + 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(); @@ -289,15 +294,14 @@ namespace vcpkg { namespace COFFFileReader std::set machine_types; // Next we have the obj and pseudo-object files - for (uint32_t i = 0; i < offsets.data.size(); i++) + for (const uint32_t offset : offsets.data) { - const archive_member_header header = archive_member_header::read(fs); + marker.set_to_offset(offset + archive_member_header::HEADER_SIZE); // Skip the header, no need to read it. + marker.seek_to_marker(fs); const uint16_t first_two_bytes = peek_value_from_stream(fs); const bool isImportHeader = getMachineType(first_two_bytes) == MachineType::UNKNOWN; const MachineType machine = isImportHeader ? import_header::read(fs).machineType() : coff_file_header::read(fs).machineType(); machine_types.insert(machine); - marker.advance_by(archive_member_header::HEADER_SIZE + header.member_size()); - marker.seek_to_marker(fs); } return {std::vector(machine_types.cbegin(), machine_types.cend())}; -- cgit v1.2.3 From 1b7f21a3e9cb6eb3ccd1a7c22a7813150466ed6c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 21 Nov 2016 12:50:23 -0800 Subject: [post-build-checks] Add check about no lib files --- toolsrc/src/post_build_lint.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 1a5f22f0a..1e7e87e6e 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -7,6 +7,9 @@ #include "coff_file_reader.h" #include "BuildInfo.h" #include +#include +#include +#include "vcpkg_Maps.h" namespace fs = std::tr2::sys; @@ -417,6 +420,17 @@ namespace vcpkg return lint_status::ERROR_DETECTED; } + static lint_status check_lib_files_are_available_if_dlls_are_available(const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) + { + if (lib_count == 0 && dll_count != 0) + { + System::println(System::color::warning, "Import libs were not present in %s", lib_dir.generic_string()); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + 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) @@ -602,8 +616,13 @@ namespace vcpkg error_count += check_for_copyright_file(spec, paths); error_count += check_for_exes(spec, paths); - const std::vector debug_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".lib"); - const std::vector release_libs = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".lib"); + const fs::path debug_lib_dir = paths.packages / spec.dir() / "debug" / "lib"; + const fs::path release_lib_dir = paths.packages / spec.dir() / "lib"; + const fs::path debug_bin_dir = paths.packages / spec.dir() / "debug" / "bin"; + const fs::path release_bin_dir = paths.packages / spec.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"); error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs); @@ -617,11 +636,14 @@ namespace vcpkg { case LinkageType::DYNAMIC: { - const std::vector debug_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".dll"); - const std::vector release_dlls = recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".dll"); + 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"); error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); + error_count += check_lib_files_are_available_if_dlls_are_available(debug_libs.size(), debug_dlls.size(), debug_lib_dir); + error_count += check_lib_files_are_available_if_dlls_are_available(release_libs.size(), release_dlls.size(), release_lib_dir); + std::vector dlls; dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); -- cgit v1.2.3 From 4e3269e7fcbcf20bb28f07ab9543fce7c336689d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 21 Nov 2016 12:57:39 -0800 Subject: Remove unused #includes --- toolsrc/src/post_build_lint.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 1e7e87e6e..9ae91748e 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -7,9 +7,6 @@ #include "coff_file_reader.h" #include "BuildInfo.h" #include -#include -#include -#include "vcpkg_Maps.h" namespace fs = std::tr2::sys; -- cgit v1.2.3 From cc7ee77d9031853580eeecd8c80ca195a8ae9bd6 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sat, 26 Nov 2016 02:49:42 -0800 Subject: [vcpkg] The static keyword at member function scope is not once-per-instance, it's once-per-function --- toolsrc/src/BuildInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 1f802869f..3fc56efc0 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -16,13 +16,13 @@ namespace vcpkg const std::regex& BuildType::crt_regex() const { - static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; } const std::string& BuildType::toString() const { - static const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); + const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); return s; } @@ -153,7 +153,7 @@ namespace vcpkg const std::regex& OutdatedDynamicCrt::crt_regex() const { - static const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; } -- cgit v1.2.3 From 692d95c865f271d0805a60fff63fb319c1985ad3 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sat, 26 Nov 2016 02:51:12 -0800 Subject: [vcpkg] Do not return references to locals --- toolsrc/src/BuildInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 3fc56efc0..8d46a0dba 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -14,13 +14,13 @@ namespace vcpkg return this->m_linkage; } - const std::regex& BuildType::crt_regex() const + const std::regex BuildType::crt_regex() const { const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; } - const std::string& BuildType::toString() const + const std::string BuildType::toString() const { const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); return s; @@ -151,7 +151,7 @@ namespace vcpkg const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; - const std::regex& OutdatedDynamicCrt::crt_regex() const + const std::regex OutdatedDynamicCrt::crt_regex() const { const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; -- cgit v1.2.3 From 0f5a833b81529362b290b2b62fe81ce07b98e766 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 28 Nov 2016 18:07:42 -0800 Subject: [vcpkg portsdiff] Add check that commit id exists --- toolsrc/src/commands_portsdiff.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 3789e3b42..b6b604e54 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -8,6 +8,7 @@ #include #include "Paragraphs.h" #include "SourceParagraph.h" +#include "vcpkg_Environment.h" namespace vcpkg { @@ -87,14 +88,28 @@ namespace vcpkg return names_and_versions; } + static void check_commit_exists(const std::wstring& git_commit_id) + { + static const std::string VALID_COMMIT_OUTPUT = "commit\n"; + + const std::wstring cmd = Strings::wformat(LR"(git cat-file -t %s 2>NUL)", git_commit_id); + const System::exit_code_and_output output = System::cmd_execute_and_capture_output(cmd); + Checks::check_exit(output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); + } + void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example.c_str()); args.check_max_arg_count(2, example.c_str()); + + Environment::ensure_git_on_path(paths); 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)); + check_commit_exists(git_commit_id_for_current_snapshot); + check_commit_exists(git_commit_id_for_previous_snapshot); + const std::map current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot); const std::map previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot); -- cgit v1.2.3 From 519c54250792cbd2a321f6b4292aeb4d4e3c1a2b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 11:33:32 -0800 Subject: Don't return by const value --- toolsrc/src/BuildInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index 8d46a0dba..44c7fdcf0 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -14,13 +14,13 @@ namespace vcpkg return this->m_linkage; } - const std::regex BuildType::crt_regex() const + std::regex BuildType::crt_regex() const { const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; } - const std::string BuildType::toString() const + std::string BuildType::toString() const { const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); return s; -- cgit v1.2.3 From 5e75a3dd0e891e6100fa9137fbf9d05ab750f24a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 13:06:27 -0800 Subject: Extract local variable --- toolsrc/src/vcpkg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index db85eee8f..acebd57b9 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -157,8 +157,8 @@ static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryPar for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) { - const auto& filename = it->path().filename(); - if (fs::is_regular_file(it->status()) && (_stricmp(filename.generic_string().c_str(), "CONTROL") == 0 || _stricmp(filename.generic_string().c_str(), "BUILD_INFO") == 0)) + 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; -- cgit v1.2.3 From b271355a5845ddfc235dd79c0e6e1389de3fb534 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 13:06:42 -0800 Subject: Extract local variable --- toolsrc/src/post_build_lint.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 9ae91748e..82a532f5f 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -613,10 +613,11 @@ namespace vcpkg error_count += check_for_copyright_file(spec, paths); error_count += check_for_exes(spec, paths); - const fs::path debug_lib_dir = paths.packages / spec.dir() / "debug" / "lib"; - const fs::path release_lib_dir = paths.packages / spec.dir() / "lib"; - const fs::path debug_bin_dir = paths.packages / spec.dir() / "debug" / "bin"; - const fs::path release_bin_dir = paths.packages / spec.dir() / "bin"; + const fs::path package_dir = paths.package_dir(spec); + 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"); -- cgit v1.2.3 From be71c433cc9902813e5a64be81fd058238c64fef Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 13:07:21 -0800 Subject: [post-build-checks] Add check for files in package dir and debug dir --- toolsrc/src/post_build_lint.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 82a532f5f..c3a6db184 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -32,6 +32,12 @@ namespace vcpkg 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) { @@ -591,6 +597,34 @@ namespace vcpkg return lint_status::SUCCESS; } + static lint_status check_no_files_in_package_dir_and_debug_dir(const fs::path& package_dir) + { + 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); + + + 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); + + 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); + System::println(System::color::warning, "Files cannot be present in those directories.\n"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + static void operator +=(size_t& left, const lint_status& right) { left += static_cast(right); @@ -680,6 +714,7 @@ namespace vcpkg #endif error_count += check_no_empty_folders(paths.packages / spec.dir()); + error_count += check_no_files_in_package_dir_and_debug_dir(package_dir); if (error_count != 0) { -- cgit v1.2.3 From 7a2e6f614d9366fb63f0abb1f02a3e65dbd64ddb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 13:14:20 -0800 Subject: Use extracted local variable --- toolsrc/src/post_build_lint.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index c3a6db184..866050edf 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -690,7 +690,7 @@ namespace vcpkg case LinkageType::STATIC: { std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir(), ".dll", &dlls); + 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(spec, paths); @@ -709,11 +709,11 @@ namespace vcpkg Checks::unreachable(); } #if 0 - error_count += check_no_subdirectories(paths.packages / spec.dir() / "lib"); - error_count += check_no_subdirectories(paths.packages / spec.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(paths.packages / spec.dir()); + error_count += check_no_empty_folders(package_dir); error_count += check_no_files_in_package_dir_and_debug_dir(package_dir); if (error_count != 0) -- cgit v1.2.3 From daa47668d00d1534a913e8f81ac26c349fe5d2f9 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 15:32:44 -0800 Subject: [post-build-checks] Refactor - pass around package_dir --- toolsrc/src/post_build_lint.cpp | 78 ++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 40 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 866050edf..d358cca45 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -68,9 +68,9 @@ namespace vcpkg } } - static lint_status check_for_files_in_include_directory(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_files_in_include_directory(const fs::path& package_dir) { - const fs::path include_dir = paths.packages / spec.dir() / "include"; + 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."); @@ -80,9 +80,9 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_for_files_in_debug_include_directory(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_files_in_debug_include_directory(const fs::path& package_dir) { - const fs::path debug_include_dir = paths.packages / spec.dir() / "debug" / "include"; + 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) @@ -101,9 +101,9 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_for_files_in_debug_share_directory(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_files_in_debug_share_directory(const fs::path& package_dir) { - const fs::path debug_share = paths.packages / spec.dir() / "debug" / "share"; + const fs::path debug_share = package_dir / "debug" / "share"; if (fs::exists(debug_share) && !fs::is_empty(debug_share)) { @@ -114,9 +114,9 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_folder_lib_cmake(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_folder_lib_cmake(const fs::path& package_dir) { - const fs::path lib_cmake = paths.packages / spec.dir() / "lib" / "cmake"; + 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 moved to just /cmake"); @@ -126,14 +126,13 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_for_misplaced_cmake_files(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_misplaced_cmake_files(const fs::path& package_dir, const package_spec& spec) { - const fs::path current_packages_dir = paths.packages / spec.dir(); std::vector misplaced_cmake_files; - recursive_find_files_with_extension_in_dir(current_packages_dir / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "lib" / "cmake", ".cmake", &misplaced_cmake_files); - recursive_find_files_with_extension_in_dir(current_packages_dir / "debug" / "lib" / "cmake", ".cmake", &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); if (!misplaced_cmake_files.empty()) { @@ -145,9 +144,9 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_folder_debug_lib_cmake(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_folder_debug_lib_cmake(const fs::path& package_dir) { - const fs::path lib_cmake_debug = paths.packages / spec.dir() / "debug" / "lib" / "cmake"; + 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 moved to just /debug/cmake"); @@ -157,11 +156,11 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_for_dlls_in_lib_dirs(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_dlls_in_lib_dirs(const fs::path& package_dir) { std::vector dlls; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "lib", ".dll", &dlls); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "lib", ".dll", &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); if (!dlls.empty()) { @@ -175,7 +174,8 @@ namespace vcpkg static lint_status check_for_copyright_file(const package_spec& spec, const vcpkg_paths& paths) { - const fs::path copyright_file = paths.packages / spec.dir() / "share" / spec.name() / "copyright"; + const fs::path packages_dir = paths.packages / spec.dir(); + const fs::path copyright_file = packages_dir / "share" / spec.name() / "copyright"; if (fs::exists(copyright_file)) { return lint_status::SUCCESS; @@ -216,17 +216,15 @@ namespace vcpkg print_vector_of_files(potential_copyright_files); } - const fs::path current_packages_dir = paths.packages / spec.dir(); - System::println(" %s/share/%s/copyright", current_packages_dir.generic_string(), spec.name()); - + System::println(" %s/share/%s/copyright", packages_dir.generic_string(), spec.name()); return lint_status::ERROR_DETECTED; } - static lint_status check_for_exes(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_for_exes(const fs::path& package_dir) { std::vector exes; - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "bin", ".exe", &exes); - recursive_find_files_with_extension_in_dir(paths.packages / spec.dir() / "debug" / "bin", ".exe", &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); if (!exes.empty()) { @@ -452,10 +450,10 @@ namespace vcpkg return lint_status::SUCCESS; } - static lint_status check_bin_folders_are_not_present_in_static_build(const package_spec& spec, const vcpkg_paths& paths) + static lint_status check_bin_folders_are_not_present_in_static_build(const fs::path& package_dir) { - const fs::path bin = paths.packages / spec.dir() / "bin"; - const fs::path debug_bin = paths.packages / spec.dir() / "debug" / "bin"; + const fs::path bin = package_dir / "bin"; + const fs::path debug_bin = package_dir / "debug" / "bin"; if (!fs::exists(bin) && !fs::exists(debug_bin)) { @@ -607,7 +605,6 @@ namespace vcpkg 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) { @@ -635,19 +632,20 @@ namespace vcpkg System::println("-- Performing post-build validation"); BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); + const fs::path package_dir = paths.package_dir(spec); size_t error_count = 0; - error_count += check_for_files_in_include_directory(spec, paths); - error_count += check_for_files_in_debug_include_directory(spec, paths); - error_count += check_for_files_in_debug_share_directory(spec, paths); - error_count += check_folder_lib_cmake(spec, paths); - error_count += check_for_misplaced_cmake_files(spec, paths); - error_count += check_folder_debug_lib_cmake(spec, paths); - error_count += check_for_dlls_in_lib_dirs(spec, paths); + error_count += check_for_files_in_include_directory(package_dir); + error_count += check_for_files_in_debug_include_directory(package_dir); + error_count += check_for_files_in_debug_share_directory(package_dir); + error_count += check_folder_lib_cmake(package_dir); + error_count += check_for_misplaced_cmake_files(package_dir, spec); + error_count += check_folder_debug_lib_cmake(package_dir); + error_count += check_for_dlls_in_lib_dirs(package_dir); error_count += check_for_copyright_file(spec, paths); - error_count += check_for_exes(spec, paths); + error_count += check_for_exes(package_dir); - const fs::path package_dir = paths.package_dir(spec); + 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"; @@ -693,7 +691,7 @@ namespace vcpkg 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(spec, paths); + error_count += check_bin_folders_are_not_present_in_static_build(package_dir); error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs); error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs); -- cgit v1.2.3 From c0564b6111a14f54e94ad64892ab40f9adb4a1b6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 29 Nov 2016 16:45:21 -0800 Subject: Remove unused function --- toolsrc/src/vcpkg.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index acebd57b9..b1fe76982 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -18,19 +18,6 @@ using namespace vcpkg; bool vcpkg::g_do_dry_run = false; -namespace -{ - template - auto find_or_default(const M& map, const K& key, const V& val) - { - auto it = map.find(key); - if (it == map.end()) - return decltype(it->second)(val); - else - return it->second; - } -} - 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) -- cgit v1.2.3 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 From 7c2abc755f58beaea36aa1cbc1c3b7f375e567a3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 15:36:39 -0800 Subject: Introduce function get_installed_files() --- toolsrc/src/vcpkg.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6c5224f56..57b2e7adb 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -109,6 +109,39 @@ void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) fs::rename(tmp_update_filename, update_filename); } +std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) +{ + std::vector installed_files; + + std::string line; + + for (const std::unique_ptr& pgh : status_db) + { + if (pgh->state != install_state_t::installed) + { + continue; + } + + std::fstream listfile(paths.listfile_path(pgh->package)); + + std::vector installed_files_of_current_pgh; + while (std::getline(listfile, line)) + { + if (line.empty()) + { + continue; + } + + installed_files_of_current_pgh.push_back(line); + } + + const StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; + installed_files.push_back(pgh_and_files); + } + + return installed_files; +} + expected vcpkg::try_load_port(const fs::path& path) { try -- cgit v1.2.3 From 4d298be260ecafef2c7c17145aafbd4ea8a952cb Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 15:37:08 -0800 Subject: [owns command] Use get_installed_files() --- toolsrc/src/commands_owns.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index e5599ce01..45f073304 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -1,30 +1,21 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg.h" -#include namespace vcpkg { static void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) { - std::string line; - - for (auto&& pgh : status_db) + const std::vector installed_files = get_installed_files(paths, status_db); + for (const StatusParagraph_and_associated_files& pgh_and_file : installed_files) { - if (pgh->state != install_state_t::installed) - continue; + const StatusParagraph& pgh = pgh_and_file.pgh; - std::fstream listfile(paths.listfile_path(pgh->package)); - while (std::getline(listfile, line)) + for (const std::string& file : pgh_and_file.files) { - if (line.empty()) - { - continue; - } - - if (line.find(file_substr) != std::string::npos) + if (file.find(file_substr) != std::string::npos) { - System::println("%s: %s", pgh->package.displayname(), line); + System::println("%s: %s", pgh.package.displayname(), file); } } } -- cgit v1.2.3 From a8c189c3f29dcb081ffe7c1bda53bdc82ac6dc92 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 17:22:20 -0800 Subject: [pre-install checks] Greatly improve the check for already isntalled files --- toolsrc/src/commands_installation.cpp | 74 +++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 23342070d..8bae0a182 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -128,53 +128,67 @@ namespace vcpkg listfile.close(); } - static std::map remove_first_n_chars_and_map(const std::vector absolute_paths, const size_t n) + static void remove_first_n_chars(std::vector* strings, const size_t n) { - std::map output; - - for (const fs::path& absolute_path : absolute_paths) + for (std::string& s : *strings) { - std::string suffix = absolute_path.generic_string(); - suffix.erase(0, n); - output.emplace(suffix, absolute_path); + s.erase(0, n); } + }; - return output; - } - - static void print_map_values(const std::vector keys, const std::map& map) + static std::vector extract_files_in_triplet(const std::vector& pgh_and_files, const triplet& triplet) { - System::println(""); - for (const std::string& key : keys) + std::vector output; + for (const StatusParagraph_and_associated_files& t : pgh_and_files) { - System::println(" %s", map.at(key).generic_string()); + if (t.pgh.package.spec.target_triplet() != triplet) + { + continue; + } + + output.insert(output.end(), t.files.cbegin(), t.files.cend()); } - System::println(""); + + std::sort(output.begin(), output.end()); + return output; } - static void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) + 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); + const std::vector package_file_paths = Files::recursive_find_all_files_in_dir(package_dir); + std::vector package_files; + const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash + std::transform(package_file_paths.cbegin(), package_file_paths.cend(), std::back_inserter(package_files), [package_remove_char_count](const fs::path& path) + { + return path.generic_string().erase(0, package_remove_char_count); + }); + std::sort(package_files.begin(), package_files.end()); + + const std::vector& pgh_and_files = get_installed_files(paths, status_db); + const triplet& triplet = binary_paragraph.spec.target_triplet(); + std::vector 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 + remove_first_n_chars(&installed_files, installed_remove_char_count); + std::sort(installed_files.begin(), installed_files.end()); std::vector intersection; - std::set_intersection(package_files_set.cbegin(), package_files_set.cend(), - installed_files_set.cbegin(), installed_files_set.cend(), + std::set_intersection(package_files.cbegin(), package_files.cend(), + installed_files.cbegin(), installed_files.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); + 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", + triplet_install_path.generic_string(), + binary_paragraph.spec); + System::println(""); + for (const std::string& s : intersection) + { + System::println(" %s", s); + } + System::println(""); exit(EXIT_FAILURE); } -- cgit v1.2.3 From a195dedf52e67b1aaac62f041cc767e0d12592b3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 1 Dec 2016 20:39:28 -0800 Subject: get_installed_files() now filters out the directories --- toolsrc/src/commands_installation.cpp | 2 +- toolsrc/src/vcpkg.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 8bae0a182..1abd16796 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -170,7 +170,7 @@ namespace vcpkg std::vector 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 remove_first_n_chars(&installed_files, installed_remove_char_count); - std::sort(installed_files.begin(), installed_files.end()); + std::sort(installed_files.begin(), installed_files.end()); // Should already be sorted std::vector intersection; std::set_intersection(package_files.cbegin(), package_files.cend(), diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 57b2e7adb..88b05b0a9 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -111,6 +111,8 @@ void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) { + static const std::string MARK_FOR_REMOVAL = ""; + std::vector installed_files; std::string line; @@ -135,6 +137,30 @@ std::vector vcpkg::get_installed_files(con installed_files_of_current_pgh.push_back(line); } + // Should already be sorted + std::sort(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end()); + + // Since the files are sorted, we can detect the entries that represent directories + // by comparing every element with the next one and checking if the next has a slash immediately after the current one's length + for (int i = 1; i < installed_files_of_current_pgh.size(); i++) + { + std::string& current_string = installed_files_of_current_pgh.at(i - 1); + const std::string& next_string = installed_files_of_current_pgh.at(i); + + const size_t potential_slash_char_index = current_string.length(); + // Make sure the index exists first + if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') + { + current_string = MARK_FOR_REMOVAL; + } + } + + installed_files_of_current_pgh.erase(std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) + { + return file == MARK_FOR_REMOVAL; + }), + installed_files_of_current_pgh.end()); + const StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; installed_files.push_back(pgh_and_files); } -- cgit v1.2.3 From 31c4de315a218117f2f88742b3be58f9df9b76ac Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 7 Dec 2016 13:14:10 -0800 Subject: Add "vcpkg /?" which is equivalent to "vcpkg help" --- toolsrc/src/commands_other.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 5f4128bb1..bb1768048 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -74,6 +74,7 @@ namespace vcpkg const std::vector>& get_available_commands_type_b() { static std::vector> t = { + {"/?", help_command}, {"help", help_command}, {"search", search_command}, {"list", list_command}, -- cgit v1.2.3 From 1310e9e052de50a8d53bc9b88696f8b6c61bece6 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Mon, 12 Dec 2016 14:03:13 -0800 Subject: Add SQM User Id to metrics --- toolsrc/src/main.cpp | 1 + toolsrc/src/metrics.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index f937be7f1..5e9dcf7ff 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -197,6 +197,7 @@ int wmain(const int argc, const wchar_t* const* const argv) const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); TrackProperty("cmdline", trimmed_command_line); loadConfig(); + TrackProperty("sqmuser", GetSQMUser()); const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index 23962bcfe..51c7179c8 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -235,6 +235,40 @@ true return DISABLE_METRICS == 0; } + std::wstring GetSQMUser() + { + LONG err = NULL; + + struct RAII_HKEY { + HKEY hkey = NULL; + ~RAII_HKEY() + { + if (hkey != NULL) + RegCloseKey(hkey); + } + } HKCU_SQMClient; + + err = RegOpenKeyExW(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", NULL, KEY_READ, &HKCU_SQMClient.hkey); + if (err != ERROR_SUCCESS) + { + return L"{}"; + } + + std::array buffer; + DWORD lType = 0; + DWORD dwBufferSize = static_cast(buffer.size() * sizeof(wchar_t)); + err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", NULL, &lType, reinterpret_cast(buffer.data()), &dwBufferSize); + if (err == ERROR_SUCCESS && lType == REG_SZ && dwBufferSize >= sizeof(wchar_t)) + { + size_t sz = dwBufferSize / sizeof(wchar_t); + if (buffer[sz - 1] == '\0') + --sz; + return std::wstring(buffer.begin(), buffer.begin() + sz); + } + + return L"{}"; + } + void SetUserInformation(const std::string& user_id, const std::string& first_use_time) { g_metricmessage.user_id = user_id; -- cgit v1.2.3 From b629cd904440c640b7e5b4c3fdf17df5aac90bad Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:03:36 -0800 Subject: [vcpkg_cmd_arguments] Use std::string instead of char* --- toolsrc/src/commands_cache.cpp | 2 +- toolsrc/src/commands_create.cpp | 4 ++-- toolsrc/src/commands_edit.cpp | 2 +- toolsrc/src/commands_hash.cpp | 4 ++-- toolsrc/src/commands_import.cpp | 2 +- toolsrc/src/commands_installation.cpp | 6 +++--- toolsrc/src/commands_integration.cpp | 2 +- toolsrc/src/commands_list.cpp | 2 +- toolsrc/src/commands_owns.cpp | 2 +- toolsrc/src/commands_portsdiff.cpp | 4 ++-- toolsrc/src/commands_remove.cpp | 2 +- toolsrc/src/commands_search.cpp | 2 +- toolsrc/src/vcpkg_cmd_arguments.cpp | 6 +++--- 13 files changed, 20 insertions(+), 20 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 19c762caf..f43b054a6 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -38,7 +38,7 @@ namespace vcpkg { 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", create_example_string("cache png")); - args.check_max_arg_count(1, example.c_str()); + args.check_max_arg_count(1, example); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); if (binary_paragraphs.empty()) diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index d1611eb5c..ad00cd676 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -9,8 +9,8 @@ namespace vcpkg void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###"); - args.check_max_arg_count(3, example.c_str()); - args.check_min_arg_count(2, example.c_str()); + args.check_max_arg_count(3, example); + args.check_min_arg_count(2, example); const std::string port_name = args.command_arguments.at(0); Environment::ensure_utilities_on_path(paths); diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index f07a15875..fbf4eab62 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -7,7 +7,7 @@ namespace vcpkg void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = create_example_string("edit zlib"); - args.check_exact_arg_count(1, example.c_str()); + args.check_exact_arg_count(1, example); const std::string port_name = args.command_arguments.at(0); const fs::path portpath = paths.ports / port_name; diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 17c191b78..42d1823fa 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -27,8 +27,8 @@ namespace vcpkg { static const std::string example = Strings::format( "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2")); - args.check_min_arg_count(1, example.c_str()); - args.check_max_arg_count(2, example.c_str()); + args.check_min_arg_count(1, example); + args.check_max_arg_count(2, example); if (args.command_arguments.size() == 1) { diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index e5e731799..3832f0e7b 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -78,7 +78,7 @@ namespace vcpkg void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); - args.check_exact_arg_count(3, example.c_str()); + args.check_exact_arg_count(3, example); const fs::path control_file_path(args.command_arguments[0]); const fs::path include_directory(args.command_arguments[1]); diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 1abd16796..c376d522f 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -216,7 +216,7 @@ namespace vcpkg 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"); - args.check_min_arg_count(1, example.c_str()); + args.check_min_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); @@ -276,7 +276,7 @@ namespace vcpkg // Installing multiple packages leads to unintuitive behavior if one of them depends on another. // Allowing only 1 package for now. - args.check_exact_arg_count(1, example.c_str()); + args.check_exact_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); @@ -332,7 +332,7 @@ namespace vcpkg void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); - args.check_exact_arg_count(2, example.c_str()); + args.check_exact_arg_count(2, example); expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); if (auto spec = maybe_current_spec.get()) diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integration.cpp index cd303c649..31f30f216 100644 --- a/toolsrc/src/commands_integration.cpp +++ b/toolsrc/src/commands_integration.cpp @@ -297,7 +297,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console { static const std::string example = Strings::format("Commands:\n" "%s", INTEGRATE_COMMAND_HELPSTRING); - args.check_exact_arg_count(1, example.c_str()); + args.check_exact_arg_count(1, example); if (args.command_arguments[0] == "install") { diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 2d6b42008..cc51232e9 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -17,7 +17,7 @@ namespace vcpkg { 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", create_example_string("list png")); - args.check_max_arg_count(1, example.c_str()); + args.check_max_arg_count(1, example); const StatusParagraphs status_paragraphs = database_load_check(paths); std::vector installed_packages; diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index 45f073304..62dac57eb 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -24,7 +24,7 @@ namespace vcpkg void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = Strings::format("The argument should be a pattern to search for. %s", create_example_string("owns zlib.dll")); - args.check_exact_arg_count(1, example.c_str()); + args.check_exact_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); search_file(paths, args.command_arguments[0], status_db); diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index b6b604e54..46c6c90c7 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -100,8 +100,8 @@ namespace vcpkg void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", create_example_string("portsdiff mybranchname")); - args.check_min_arg_count(1, example.c_str()); - args.check_max_arg_count(2, example.c_str()); + args.check_min_arg_count(1, example); + args.check_max_arg_count(2, example); Environment::ensure_git_on_path(paths); const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0)); diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 31331fc2f..9d3352532 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -169,7 +169,7 @@ namespace vcpkg 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"); - args.check_min_arg_count(1, example.c_str()); + args.check_min_arg_count(1, example); const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); auto status_db = database_load_check(paths); diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index a604c5383..a4714477e 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -43,7 +43,7 @@ namespace vcpkg void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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", create_example_string("search png")); - args.check_max_arg_count(1, example.c_str()); + args.check_max_arg_count(1, example); const std::vector source_paragraphs = read_all_source_paragraphs(paths); diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index d61e420ab..2cc1f811c 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -179,7 +179,7 @@ namespace vcpkg return check_exact_arg_count(expected_arg_count, ""); } - void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count, const char* example_text) const + void vcpkg_cmd_arguments::check_max_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) @@ -190,7 +190,7 @@ namespace vcpkg } } - void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count, const char* example_text) const + void vcpkg_cmd_arguments::check_min_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) @@ -201,7 +201,7 @@ namespace vcpkg } } - void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count, const char* example_text) const + void vcpkg_cmd_arguments::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) -- cgit v1.2.3 From 852acbc2638c21d9639258417b8cd9fceed722c2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:05:49 -0800 Subject: [vcpkg_Input] Use std::string instead of char* --- toolsrc/src/commands_installation.cpp | 4 ++-- toolsrc/src/commands_remove.cpp | 2 +- toolsrc/src/vcpkg_Input.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index c376d522f..c7bac3fc1 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -219,7 +219,7 @@ namespace vcpkg args.check_min_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); - std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); + std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); Input::check_triplets(specs, paths); std::vector install_plan = Dependencies::create_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); @@ -280,7 +280,7 @@ namespace vcpkg StatusParagraphs status_db = database_load_check(paths); - const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str()); + const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example); Input::check_triplet(spec.target_triplet(), paths); const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_CHECKS_ONLY}); diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 9d3352532..445213fc2 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -174,7 +174,7 @@ namespace vcpkg const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); auto status_db = database_load_check(paths); - std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str()); + std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); Input::check_triplets(specs, paths); bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index f7aae1929..29d487fdb 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -5,7 +5,7 @@ namespace vcpkg {namespace Input { - package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const char* example_text) + package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text) { const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string); expected expected_spec = package_spec::from_string(as_lowercase, default_target_triplet); @@ -20,7 +20,7 @@ namespace vcpkg {namespace Input exit(EXIT_FAILURE); } - std::vector check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const char* example_text) + std::vector check_and_get_package_specs(const std::vector& package_specs_as_strings, const triplet& default_target_triplet, const std::string& example_text) { std::vector specs; for (const std::string& spec : package_specs_as_strings) -- cgit v1.2.3 From c77be8f221dbbb7b38c74ce382be9b4dbb4d296b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:08:26 -0800 Subject: [vcpkg_System] Add missing const keywords --- toolsrc/src/vcpkg_System.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index cb3eb6584..43eae3412 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -56,7 +56,7 @@ namespace vcpkg {namespace System std::cout << "\n"; } - void print(color c, const char* message) + void print(const color c, const char* message) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); @@ -69,7 +69,7 @@ namespace vcpkg {namespace System SetConsoleTextAttribute(hConsole, original_color); } - void println(color c, const char* message) + void println(const color c, const char* message) { print(c, message); std::cout << "\n"; -- cgit v1.2.3 From 9796e2532cc34896e38a6c0702e538454ffb5586 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:10:29 -0800 Subject: Use System::println(std::string&) overload --- toolsrc/src/commands_cache.cpp | 4 ++-- toolsrc/src/commands_hash.cpp | 2 +- toolsrc/src/commands_other.cpp | 2 +- toolsrc/src/vcpkg_cmd_arguments.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index f43b054a6..17b04b093 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -52,7 +52,7 @@ namespace vcpkg for (const BinaryParagraph& binary_paragraph : binary_paragraphs) { const std::string displayname = binary_paragraph.displayname(); - System::println(displayname.c_str()); + System::println(displayname); } } else @@ -66,7 +66,7 @@ namespace vcpkg continue; } - System::println(displayname.c_str()); + System::println(displayname); } } diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 42d1823fa..0e3e8a77c 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -20,7 +20,7 @@ namespace vcpkg auto hash = output.substr(start, end - start); hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end()); - System::println(hash.c_str()); + System::println(hash); } void hash_command(const vcpkg_cmd_arguments& args) diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index bb1768048..16b697952 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -50,7 +50,7 @@ namespace vcpkg void print_example(const char* command_and_arguments) { - System::println(create_example_string(command_and_arguments).c_str()); + System::println(create_example_string(command_and_arguments)); } void internal_test_command(const vcpkg_cmd_arguments& /*args*/, const vcpkg_paths& /*paths*/) diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index 2cc1f811c..a3648668f 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -156,7 +156,7 @@ namespace vcpkg System::println(System::color::error, "Unknown option(s) for command '%s':", this->command); for (const std::string& option : options_copy) { - System::println(option.c_str()); + System::println(option); } exit(EXIT_FAILURE); } -- cgit v1.2.3 From e523668cce29745d8024dd5d56ee1d705da24a49 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 12 Dec 2016 15:13:24 -0800 Subject: Change signature to std::string& (from char*) --- toolsrc/src/commands_installation.cpp | 2 +- toolsrc/src/commands_other.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index c7bac3fc1..fd318d2e7 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -349,7 +349,7 @@ namespace vcpkg } System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); - print_example(Strings::format("%s zlib:x64-windows", args.command).c_str()); + print_example(Strings::format("%s zlib:x64-windows", args.command)); exit(EXIT_FAILURE); } } diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp index 16b697952..6df325100 100644 --- a/toolsrc/src/commands_other.cpp +++ b/toolsrc/src/commands_other.cpp @@ -41,14 +41,14 @@ namespace vcpkg , INTEGRATE_COMMAND_HELPSTRING); } - std::string create_example_string(const char* command_and_arguments) + std::string create_example_string(const std::string& command_and_arguments) { std::string cs = Strings::format("Example:\n" " vcpkg %s", command_and_arguments); return cs; } - void print_example(const char* command_and_arguments) + void print_example(const std::string& command_and_arguments) { System::println(create_example_string(command_and_arguments)); } -- cgit v1.2.3 From c9b310c16528c907ab12bcc5ec9a0f5795ebf29f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 13 Dec 2016 16:35:06 -0800 Subject: Minor code clarity change --- toolsrc/src/commands_installation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index fd318d2e7..35c29b6a8 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -161,7 +161,9 @@ namespace vcpkg const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash std::transform(package_file_paths.cbegin(), package_file_paths.cend(), std::back_inserter(package_files), [package_remove_char_count](const fs::path& path) { - return path.generic_string().erase(0, package_remove_char_count); + std::string as_string = path.generic_string(); + as_string.erase(0, package_remove_char_count); + return std::move(as_string); }); std::sort(package_files.begin(), package_files.end()); -- cgit v1.2.3 From b1681d0838fdc3a3bd361e5678d23d2376a3edbd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 13 Dec 2016 19:02:02 -0800 Subject: Avoid copying struct --- toolsrc/src/vcpkg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 88b05b0a9..74b02e612 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -161,8 +161,8 @@ std::vector vcpkg::get_installed_files(con }), installed_files_of_current_pgh.end()); - const StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; - installed_files.push_back(pgh_and_files); + StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; + installed_files.push_back(std::move(pgh_and_files)); } return installed_files; -- cgit v1.2.3 From 5d54e079f7096251208d9b745cf865327110f849 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 14 Dec 2016 16:51:05 -0800 Subject: Refactor writing of listfile --- toolsrc/src/commands_installation.cpp | 36 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 35c29b6a8..e61a2dbfe 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -69,16 +69,16 @@ namespace vcpkg 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); + std::vector output; - auto package_prefix_path = paths.package_dir(bpgh.spec); - auto prefix_length = package_prefix_path.native().size(); + const fs::path package_prefix_path = paths.package_dir(bpgh.spec); + const size_t 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"; + output.push_back(Strings::format(R"(%s)", target_triplet_as_string)); for (auto it = fs::recursive_directory_iterator(package_prefix_path); it != fs::recursive_directory_iterator(); ++it) { @@ -89,8 +89,8 @@ namespace vcpkg continue; } - auto suffix = it->path().generic_u8string().substr(prefix_length + 1); - auto target = paths.installed / target_triplet_as_string / suffix; + const std::string suffix = it->path().generic_u8string().substr(prefix_length + 1); + const fs::path target = paths.installed / target_triplet_as_string / suffix; auto status = it->status(ec); if (ec) @@ -98,6 +98,7 @@ namespace vcpkg System::println(System::color::error, "failed: %s: %s", it->path().u8string(), ec.message()); continue; } + if (fs::is_directory(status)) { fs::create_directory(target, ec); @@ -106,25 +107,36 @@ namespace vcpkg System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); } - listfile << target_triplet << "/" << suffix << "\n"; + // Trailing backslash for directories + output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); + continue; } - else if (fs::is_regular_file(status)) + + 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"; + output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); + continue; } - else if (!fs::status_known(status)) + + if (!fs::status_known(status)) { System::println(System::color::error, "failed: %s: unknown status", it->path().u8string()); + continue; } - else - System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); + + System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); } + std::fstream listfile(paths.listfile_path(bpgh), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + for (const std::string& line : output) + { + listfile << line << "\n"; + } listfile.close(); } -- cgit v1.2.3 From 88daca5f547d00d58637a501c10c57e823771a02 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 15 Dec 2016 14:28:43 -0800 Subject: [listfile] When reading a listfile, add / at the end of directories --- toolsrc/src/vcpkg.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 14 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 74b02e612..6f1d30bc5 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -10,6 +10,7 @@ #include "vcpkg_Files.h" #include "Paragraphs.h" #include +#include "metrics.h" using namespace vcpkg; @@ -109,6 +110,82 @@ void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) fs::rename(tmp_update_filename, update_filename); } +static void upgrade_to_slash_terminated_sorted_format(std::vector* lines, const fs::path& listfile_path) +{ + static bool was_tracked = false; + + if (lines->empty()) + { + return; + } + + if (lines->at(0).back() == '/') + { + return; // File already in the new format + } + + if (!was_tracked) + { + was_tracked = true; + TrackProperty("listfile", "update to new format"); + } + + // The files are sorted such that directories are placed just before the files they contain + // (They are not necessarily sorted alphabetically, e.g. libflac) + // Therefore we can detect the entries that represent directories by comparing every element with the next one + // and checking if the next has a slash immediately after the current one's length + for (int i = 0; i < lines->size() - 1; i++) + { + std::string& current_string = lines->at(i); + const std::string& next_string = lines->at(i + 1); + + const size_t potential_slash_char_index = current_string.length(); + // Make sure the index exists first + if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') + { + current_string += '/'; // Mark as a directory + } + } + + // After suffixing the directories with a slash, we can now sort. + // We cannot sort before adding the suffixes because the following (actual example): + /* + x86-windows/include/FLAC <<<<<< This would be separated from its group due to sorting + x86-windows/include/FLAC/all.h + x86-windows/include/FLAC/assert.h + x86-windows/include/FLAC/callback.h + x86-windows/include/FLAC++ + x86-windows/include/FLAC++/all.h + x86-windows/include/FLAC++/decoder.h + x86-windows/include/FLAC++/encoder.h + * + x86-windows/include/FLAC/ <<<<<< This will now be kept with its group when sorting + x86-windows/include/FLAC/all.h + x86-windows/include/FLAC/assert.h + x86-windows/include/FLAC/callback.h + x86-windows/include/FLAC++/ + x86-windows/include/FLAC++/all.h + x86-windows/include/FLAC++/decoder.h + x86-windows/include/FLAC++/encoder.h + */ + // Note that after sorting, the FLAC++/ group will be placed before the FLAC/ group + // The new format is lexicographically sorted + std::sort(lines->begin(), lines->end()); + +#if 0 + // Replace the listfile on disk + const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated"; + std::fstream output(updated_listfile_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + for (const std::string& line : *lines) + { + output << line << "\n"; + } + output.close(); + + fs::rename(updated_listfile_path, listfile_path); +#endif +} + std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) { static const std::string MARK_FOR_REMOVAL = ""; @@ -124,7 +201,8 @@ std::vector vcpkg::get_installed_files(con continue; } - std::fstream listfile(paths.listfile_path(pgh->package)); + const fs::path listfile_path = paths.listfile_path(pgh->package); + std::fstream listfile(listfile_path); std::vector installed_files_of_current_pgh; while (std::getline(listfile, line)) @@ -136,22 +214,14 @@ std::vector vcpkg::get_installed_files(con installed_files_of_current_pgh.push_back(line); } + listfile.close(); + upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); - // Should already be sorted - std::sort(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end()); - - // Since the files are sorted, we can detect the entries that represent directories - // by comparing every element with the next one and checking if the next has a slash immediately after the current one's length - for (int i = 1; i < installed_files_of_current_pgh.size(); i++) + for (std::string& file : installed_files_of_current_pgh) { - std::string& current_string = installed_files_of_current_pgh.at(i - 1); - const std::string& next_string = installed_files_of_current_pgh.at(i); - - const size_t potential_slash_char_index = current_string.length(); - // Make sure the index exists first - if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') + if (file.back() == '/') { - current_string = MARK_FOR_REMOVAL; + file = MARK_FOR_REMOVAL; } } -- cgit v1.2.3 From 8f397bb8d1bd05a2e1f6d5de808322364100ae5d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 15 Dec 2016 17:09:14 -0800 Subject: Add Strings::trim() function --- toolsrc/src/vcpkg_Strings.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 19ba8595f..4859a480b 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -4,9 +4,16 @@ #include #include #include +#include +#include namespace vcpkg {namespace Strings {namespace details { + static const auto isspace = [](const char c) + { + return std::isspace(c); + }; + std::string format_internal(const char* fmtstr, ...) { va_list lst; @@ -85,4 +92,17 @@ namespace vcpkg {namespace Strings return output; } + + void trim(std::string* s) + { + s->erase(s->begin(), std::find_if_not(s->begin(), s->end(), details::isspace)); + s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end()); + } + + std::string trimmed(const std::string& s) + { + auto whitespace_front = std::find_if_not(s.begin(), s.end(), details::isspace); + auto whitespace_back = std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(); + return (whitespace_back <= whitespace_front ? std::string() : std::string(whitespace_front, whitespace_back)); + } }} -- cgit v1.2.3 From e4548a8cf46b20b8e89ab75ee9201e3b244484ba Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 15 Dec 2016 18:19:22 -0800 Subject: Add Files::read_all_lines() and Files::write_all_lines() --- toolsrc/src/vcpkg_Files.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 698579736..889ceb055 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -42,6 +42,35 @@ namespace vcpkg {namespace Files return std::move(output); } + expected> read_all_lines(const fs::path& file_path) + { + std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); + if (file_stream.fail()) + { + return std::errc::no_such_file_or_directory; + } + + std::vector output; + std::string line; + while (std::getline(file_stream, line)) + { + output.push_back(line); + } + file_stream.close(); + + return std::move(output); + } + + void write_all_lines(const fs::path& file_path, const std::vector& lines) + { + std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + for (const std::string& line : lines) + { + output << line << "\n"; + } + output.close(); + } + fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) { fs::path current_dir = starting_dir; -- cgit v1.2.3 From 15ca6919ad7d5dd86596603663845b3ea84d0d3b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 15 Dec 2016 18:24:06 -0800 Subject: Use Files::write_all_lines() --- toolsrc/src/commands_installation.cpp | 7 +------ toolsrc/src/vcpkg.cpp | 8 +------- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index e61a2dbfe..605343dfc 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -132,12 +132,7 @@ namespace vcpkg System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); } - std::fstream listfile(paths.listfile_path(bpgh), std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); - for (const std::string& line : output) - { - listfile << line << "\n"; - } - listfile.close(); + Files::write_all_lines(paths.listfile_path(bpgh), output); } static void remove_first_n_chars(std::vector* strings, const size_t n) diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6f1d30bc5..98c53f9ef 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -175,13 +175,7 @@ static void upgrade_to_slash_terminated_sorted_format(std::vector* #if 0 // Replace the listfile on disk const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated"; - std::fstream output(updated_listfile_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); - for (const std::string& line : *lines) - { - output << line << "\n"; - } - output.close(); - + Files::write_all_lines(updated_listfile_path, *lines); fs::rename(updated_listfile_path, listfile_path); #endif } -- cgit v1.2.3 From 38859d5c91c6411fb2b0757a68fd3ca297927650 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 15 Dec 2016 18:41:01 -0800 Subject: Improve code that filters out the directories from a vector of paths --- toolsrc/src/vcpkg.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 98c53f9ef..8d01cb267 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -182,8 +182,6 @@ static void upgrade_to_slash_terminated_sorted_format(std::vector* std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) { - static const std::string MARK_FOR_REMOVAL = ""; - std::vector installed_files; std::string line; @@ -211,19 +209,13 @@ std::vector vcpkg::get_installed_files(con listfile.close(); upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); - for (std::string& file : installed_files_of_current_pgh) - { - if (file.back() == '/') - { - file = MARK_FOR_REMOVAL; - } - } - - installed_files_of_current_pgh.erase(std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) - { - return file == MARK_FOR_REMOVAL; - }), - installed_files_of_current_pgh.end()); + // Remove the directories + installed_files_of_current_pgh.erase( + std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) -> bool + { + return file.back() == '/'; + } + ), installed_files_of_current_pgh.end()); StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; installed_files.push_back(std::move(pgh_and_files)); -- cgit v1.2.3 From bd50778cb53d7071d65159f0aa67e685a6628e19 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 15:42:15 -0800 Subject: [install_command] now overwrites files if they are already present The listfile checks ensures that no other package claims ownership of the particular file --- toolsrc/src/commands_installation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 605343dfc..8d940bc9d 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -114,7 +114,11 @@ namespace vcpkg if (fs::is_regular_file(status)) { - fs::copy_file(*it, target, ec); + if (fs::exists(target)) + { + System::println(System::color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message()); + } + fs::copy_file(*it, target, fs::copy_options::overwrite_existing, ec); if (ec) { System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); -- cgit v1.2.3 From a5c3fddfe7bc4f765a0efdd9b109709f2fb4ae9c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 16:02:19 -0800 Subject: Add Strings::trim_all_and_remove_whitespace_strings() --- toolsrc/src/vcpkg_Strings.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 4859a480b..403900dae 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -9,6 +9,7 @@ namespace vcpkg {namespace Strings {namespace details { + // To disambiguate between two overloads static const auto isspace = [](const char c) { return std::isspace(c); @@ -105,4 +106,13 @@ namespace vcpkg {namespace Strings auto whitespace_back = std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(); return (whitespace_back <= whitespace_front ? std::string() : std::string(whitespace_front, whitespace_back)); } + + void trim_all_and_remove_whitespace_strings(std::vector* strings) + { + strings->erase(std::remove_if(strings->begin(), strings->end(), [](std::string& s)-> bool + { + trim(&s); + return s == ""; + }), strings->end()); + } }} -- cgit v1.2.3 From 843e390c94cae55fdd4d411fc5c96f399af0f6f0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 16:20:27 -0800 Subject: Replace reading lines and ignoring empty lines with the new functions Namely: Files::read_all_lines(); Strings::trim_all_and_remove_whitespace_strings() --- toolsrc/src/vcpkg.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 8d01cb267..bf9dbd6ab 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -184,8 +184,6 @@ std::vector vcpkg::get_installed_files(con { std::vector installed_files; - std::string line; - for (const std::unique_ptr& pgh : status_db) { if (pgh->state != install_state_t::installed) @@ -194,19 +192,8 @@ std::vector vcpkg::get_installed_files(con } const fs::path listfile_path = paths.listfile_path(pgh->package); - std::fstream listfile(listfile_path); - - std::vector installed_files_of_current_pgh; - while (std::getline(listfile, line)) - { - if (line.empty()) - { - continue; - } - - installed_files_of_current_pgh.push_back(line); - } - listfile.close(); + std::vector installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(); + Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); // Remove the directories -- cgit v1.2.3 From e4571e75c2e572ef6a9f094bdd00326f8711e195 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 17:48:37 -0800 Subject: Do the trim and empty string erase in separate passes --- toolsrc/src/vcpkg_Strings.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 403900dae..d2e153ede 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -109,9 +109,13 @@ namespace vcpkg {namespace Strings void trim_all_and_remove_whitespace_strings(std::vector* strings) { - strings->erase(std::remove_if(strings->begin(), strings->end(), [](std::string& s)-> bool + for (std::string& s : *strings) + { + trim(&s); + } + + strings->erase(std::remove_if(strings->begin(), strings->end(), [](const std::string& s)-> bool { - trim(&s); return s == ""; }), strings->end()); } -- cgit v1.2.3 From fdec39f452df368a0dd9184cd556607857605832 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 19:37:11 -0800 Subject: Use check_exit() instead of check_throw() --- toolsrc/src/vcpkg_Files.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 889ceb055..853a57d16 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -9,7 +9,7 @@ namespace vcpkg {namespace Files void check_is_directory(const fs::path& dirpath) { - Checks::check_throw(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); + Checks::check_exit(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); } bool has_invalid_chars_for_filesystem(const std::string s) -- cgit v1.2.3 From b666e90c32e58a673331b303e64e299cc1168aa2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 19:38:02 -0800 Subject: Pass by ref --- toolsrc/src/vcpkg_Files.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 853a57d16..9e7002a37 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -12,7 +12,7 @@ namespace vcpkg {namespace Files Checks::check_exit(fs::is_directory(dirpath), "The path %s is not a directory", dirpath.string()); } - bool has_invalid_chars_for_filesystem(const std::string s) + bool has_invalid_chars_for_filesystem(const std::string& s) { return std::regex_search(s, FILESYSTEM_INVALID_CHARACTERS_REGEX); } -- cgit v1.2.3 From aad0cc4c042aad87b2b52eded0e465ed01e799c1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 19:40:58 -0800 Subject: Files::get_contents() -> Files::read_contents() --- toolsrc/src/Paragraphs.cpp | 2 +- toolsrc/src/commands_cache.cpp | 2 +- toolsrc/src/commands_integration.cpp | 2 +- toolsrc/src/commands_update.cpp | 2 +- toolsrc/src/main.cpp | 2 +- toolsrc/src/vcpkg.cpp | 6 +++--- toolsrc/src/vcpkg_Files.cpp | 2 +- toolsrc/src/vcpkg_metrics_uploader.cpp | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index 5efa9a7b3..823b4a85e 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -153,7 +153,7 @@ namespace vcpkg { namespace Paragraphs std::vector> get_paragraphs(const fs::path& control_path) { - return parse_paragraphs(Files::get_contents(control_path).get_or_throw()); + return parse_paragraphs(Files::read_contents(control_path).get_or_throw()); } std::vector> parse_paragraphs(const std::string& str) diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 17b04b093..1a10b93cf 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -15,7 +15,7 @@ namespace vcpkg try { - auto file_contents = Files::get_contents(path / "CONTROL"); + auto file_contents = Files::read_contents(path / "CONTROL"); if (auto text = file_contents.get()) { auto pghs = Paragraphs::parse_paragraphs(*text); diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integration.cpp index 31f30f216..e7e5b2d8d 100644 --- a/toolsrc/src/commands_integration.cpp +++ b/toolsrc/src/commands_integration.cpp @@ -173,7 +173,7 @@ namespace vcpkg bool should_install_system = true; if (fs::exists(system_wide_targets_file)) { - auto system_wide_file_contents = Files::get_contents(system_wide_targets_file); + auto system_wide_file_contents = Files::read_contents(system_wide_targets_file); if (auto contents_data = system_wide_file_contents.get()) { std::regex re(R"###()###"); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 82e3b7e52..a4ab7c6e7 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -71,7 +71,7 @@ namespace vcpkg System::println("\nTo update these packages, run\n vcpkg remove --purge ...\n vcpkg install ..."); } - auto version_file = Files::get_contents(paths.root / "toolsrc" / "VERSION.txt"); + auto version_file = Files::read_contents(paths.root / "toolsrc" / "VERSION.txt"); if (auto version_contents = version_file.get()) { int maj1, min1, rev1; diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 5e9dcf7ff..7703c541f 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -113,7 +113,7 @@ static void loadConfig() try { - std::string config_contents = Files::get_contents(localappdata / "vcpkg" / "config").get_or_throw(); + std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); std::unordered_map keys; auto pghs = Paragraphs::parse_paragraphs(config_contents); diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index bf9dbd6ab..6858d5518 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -27,7 +27,7 @@ static StatusParagraphs load_current_database(const fs::path& vcpkg_dir_status_f fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); } - auto text = Files::get_contents(vcpkg_dir_status_file).get_or_throw(); + auto text = Files::read_contents(vcpkg_dir_status_file).get_or_throw(); auto pghs = Paragraphs::parse_paragraphs(text); std::vector> status_pghs; @@ -70,7 +70,7 @@ StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) if (b->path().filename() == "incomplete") continue; - auto text = Files::get_contents(b->path()).get_or_throw(); + auto text = Files::read_contents(b->path()).get_or_throw(); auto pghs = Paragraphs::parse_paragraphs(text); for (auto&& p : pghs) { @@ -230,7 +230,7 @@ expected vcpkg::try_load_cached_package(const vcpkg_paths& path { const fs::path path = paths.package_dir(spec) / "CONTROL"; - auto control_contents_maybe = Files::get_contents(path); + auto control_contents_maybe = Files::read_contents(path); if (auto control_contents = control_contents_maybe.get()) { std::vector> pghs; diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 9e7002a37..48283e43f 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -17,7 +17,7 @@ namespace vcpkg {namespace Files return std::regex_search(s, FILESYSTEM_INVALID_CHARACTERS_REGEX); } - expected get_contents(const fs::path& file_path) noexcept + expected read_contents(const fs::path& file_path) noexcept { std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); if (file_stream.fail()) diff --git a/toolsrc/src/vcpkg_metrics_uploader.cpp b/toolsrc/src/vcpkg_metrics_uploader.cpp index 63668d1d7..14fc9ae48 100644 --- a/toolsrc/src/vcpkg_metrics_uploader.cpp +++ b/toolsrc/src/vcpkg_metrics_uploader.cpp @@ -19,5 +19,5 @@ WinMain( szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount); Checks::check_exit(argCount == 2, "Requires exactly one argument, the path to the payload file"); - Upload(Files::get_contents(szArgList[1]).get_or_throw()); + Upload(Files::read_contents(szArgList[1]).get_or_throw()); } -- cgit v1.2.3 From 73bf8306b29d68853dc3c97d5dd415bd5e857cf5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 20:11:50 -0800 Subject: Pass by const ref --- toolsrc/src/coff_file_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 3bf7922f5..1f30ea70b 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -223,7 +223,7 @@ namespace vcpkg { namespace COFFFileReader verify_equal_strings(FILE_START, file_start, FILE_START_SIZE, "LIB FILE_START"); } - dll_info read_dll(const fs::path path) + dll_info read_dll(const fs::path& path) { std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate); Checks::check_exit(fs.is_open(), "Could not open file %s for reading", path.generic_string()); @@ -260,7 +260,7 @@ namespace vcpkg { namespace COFFFileReader fpos_t m_absolute_position = 0; }; - lib_info read_lib(const fs::path path) + lib_info read_lib(const fs::path& path) { std::fstream fs(path, std::ios::in | std::ios::binary | std::ios::ate); Checks::check_exit(fs.is_open(), "Could not open file %s for reading", path.generic_string()); -- cgit v1.2.3 From 835693ce97f271c0213f65c1c782e8df84cfb409 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 16 Dec 2016 20:17:24 -0800 Subject: Don't return by const value --- 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 ddd44a1e6..f151a3ea5 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -151,7 +151,7 @@ namespace vcpkg { namespace PostBuildLint const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; - const std::regex OutdatedDynamicCrt::crt_regex() const + std::regex OutdatedDynamicCrt::crt_regex() const { const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); return r; -- cgit v1.2.3 From a077ccc4c7dfd7f2fd3a63aed9458952febcd94a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 19 Dec 2016 15:39:57 -0800 Subject: Avoid unnecessary copy --- toolsrc/src/post_build_lint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 3043bd4fa..4f0adf677 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -507,7 +507,7 @@ namespace vcpkg { namespace PostBuildLint static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls) { - const std::vector outdated_crts = OutdatedDynamicCrt::values(); + const std::vector& outdated_crts = OutdatedDynamicCrt::values(); std::vector dlls_with_outdated_crt; -- cgit v1.2.3 From 32ada00583cb96fd40849eb6b2003b8479b65d89 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 20 Dec 2016 14:45:13 -0800 Subject: Improve error message --- toolsrc/src/vcpkg_Dependencies.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 41172ba0f..ae7f697fa 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -58,7 +58,7 @@ namespace vcpkg { namespace Dependencies expected maybe_spgh = try_load_port(paths, spec.name()); SourceParagraph* spgh = maybe_spgh.get(); - Checks::check_exit(spgh != nullptr, "Cannot find package"); + Checks::check_exit(spgh != nullptr, "Cannot find package %s", spec.name()); process_dependencies(filter_dependencies(spgh->depends, spec.target_triplet())); was_examined.emplace(spec, install_plan_action{install_plan_type::BUILD_AND_INSTALL, nullptr, std::make_unique(std::move(*spgh))}); } -- cgit v1.2.3 From 8b9e624d0dfd4d0ce833027cdc7ac40bad2fe928 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 20 Dec 2016 14:45:35 -0800 Subject: Improve trim implementation --- toolsrc/src/vcpkg_Strings.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index d2e153ede..46a4b1855 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -96,15 +96,15 @@ namespace vcpkg {namespace Strings void trim(std::string* s) { - s->erase(s->begin(), std::find_if_not(s->begin(), s->end(), details::isspace)); s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end()); + s->erase(s->begin(), std::find_if_not(s->begin(), s->end(), details::isspace)); } std::string trimmed(const std::string& s) { - auto whitespace_front = std::find_if_not(s.begin(), s.end(), details::isspace); auto whitespace_back = std::find_if_not(s.rbegin(), s.rend(), details::isspace).base(); - return (whitespace_back <= whitespace_front ? std::string() : std::string(whitespace_front, whitespace_back)); + auto whitespace_front = std::find_if_not(s.begin(), whitespace_back, details::isspace); + return std::string(whitespace_front, whitespace_back); } void trim_all_and_remove_whitespace_strings(std::vector* strings) -- cgit v1.2.3 From 31d5994dd592422e3daaee325eeae727458c0e09 Mon Sep 17 00:00:00 2001 From: nekko1119 Date: Sat, 24 Dec 2016 05:27:22 +0900 Subject: Fix signed/unsigned mismatch warning --- toolsrc/src/vcpkg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 6858d5518..4748aeb54 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -134,7 +134,7 @@ static void upgrade_to_slash_terminated_sorted_format(std::vector* // (They are not necessarily sorted alphabetically, e.g. libflac) // Therefore we can detect the entries that represent directories by comparing every element with the next one // and checking if the next has a slash immediately after the current one's length - for (int i = 0; i < lines->size() - 1; i++) + for (size_t i = 0; i < lines->size() - 1; i++) { std::string& current_string = lines->at(i); const std::string& next_string = lines->at(i + 1); -- cgit v1.2.3 From 0b5e2e9e76e66b566cf4d3f68146fdbdff2bac05 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 12:47:08 -0800 Subject: Use nested namespace definition --- toolsrc/src/vcpkg_Checks.cpp | 4 ++-- toolsrc/src/vcpkg_Files.cpp | 4 ++-- toolsrc/src/vcpkg_Strings.cpp | 8 ++++---- toolsrc/src/vcpkg_System.cpp | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 817ac9e96..46b28e55c 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -3,7 +3,7 @@ #include #include "vcpkg_System.h" -namespace vcpkg {namespace Checks +namespace vcpkg::Checks { void unreachable() { @@ -41,4 +41,4 @@ namespace vcpkg {namespace Checks exit_with_message(errorMessage); } } -}} +} diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 48283e43f..1d4faa773 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -3,7 +3,7 @@ #include #include "vcpkg_System.h" -namespace vcpkg {namespace Files +namespace vcpkg::Files { static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); @@ -140,4 +140,4 @@ namespace vcpkg {namespace Files } System::println(""); } -}} +} diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 46a4b1855..cf7d3b0ee 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -7,7 +7,7 @@ #include #include -namespace vcpkg {namespace Strings {namespace details +namespace vcpkg::Strings::details { // To disambiguate between two overloads static const auto isspace = [](const char c) @@ -40,9 +40,9 @@ namespace vcpkg {namespace Strings {namespace details return output; } -}}} +} -namespace vcpkg {namespace Strings +namespace vcpkg::Strings { std::wstring utf8_to_utf16(const std::string& s) { @@ -119,4 +119,4 @@ namespace vcpkg {namespace Strings return s == ""; }), strings->end()); } -}} +} diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 43eae3412..405dfd1b8 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -3,7 +3,7 @@ #include #include -namespace vcpkg {namespace System +namespace vcpkg::System { fs::path get_exe_path_of_current_process() { @@ -104,6 +104,6 @@ namespace vcpkg {namespace System double Stopwatch2::microseconds() const { return (reinterpret_cast(&end_time)->QuadPart - - reinterpret_cast(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast(&freq)->QuadPart; + reinterpret_cast(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast(&freq)->QuadPart; } -}} +} -- cgit v1.2.3 From 1565cafb836a8efdb7c39c9c1df1ca4d671f3d90 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 14:09:48 -0800 Subject: Use nullptr --- toolsrc/src/metrics.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index 51c7179c8..1806dad87 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -237,13 +237,13 @@ true std::wstring GetSQMUser() { - LONG err = NULL; + LONG err; struct RAII_HKEY { - HKEY hkey = NULL; + HKEY hkey = nullptr; ~RAII_HKEY() { - if (hkey != NULL) + if (hkey != nullptr) RegCloseKey(hkey); } } HKCU_SQMClient; @@ -257,7 +257,7 @@ true std::array buffer; DWORD lType = 0; DWORD dwBufferSize = static_cast(buffer.size() * sizeof(wchar_t)); - err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", NULL, &lType, reinterpret_cast(buffer.data()), &dwBufferSize); + err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", nullptr, &lType, reinterpret_cast(buffer.data()), &dwBufferSize); if (err == ERROR_SUCCESS && lType == REG_SZ && dwBufferSize >= sizeof(wchar_t)) { size_t sz = dwBufferSize / sizeof(wchar_t); -- cgit v1.2.3 From 88b5791b0bcaa9cce7f488bbd03042aa65e4417e Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 14:14:11 -0800 Subject: Use Nested Namespace Definition --- toolsrc/src/coff_file_reader.cpp | 4 ++-- toolsrc/src/post_build_lint.cpp | 4 ++-- toolsrc/src/vcpkg_Dependencies.cpp | 4 ++-- toolsrc/src/vcpkg_Environment.cpp | 4 ++-- toolsrc/src/vcpkg_Input.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 1f30ea70b..8ce714bbe 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -6,7 +6,7 @@ using namespace std; -namespace vcpkg { namespace COFFFileReader +namespace vcpkg::COFFFileReader { template static T reinterpret_bytes(const char* data) @@ -306,4 +306,4 @@ namespace vcpkg { namespace COFFFileReader return {std::vector(machine_types.cbegin(), machine_types.cend())}; } -}} +} diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 4f0adf677..1fca3a2f6 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -7,7 +7,7 @@ #include "BuildInfo.h" #include -namespace vcpkg { namespace PostBuildLint +namespace vcpkg::PostBuildLint { enum class lint_status { @@ -668,4 +668,4 @@ namespace vcpkg { namespace PostBuildLint System::println("-- Performing post-build validation done"); } -}} +} diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index ae7f697fa..f1464a605 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -9,7 +9,7 @@ #include "vcpkg_Files.h" #include "vcpkg.h" -namespace vcpkg { namespace Dependencies +namespace vcpkg::Dependencies { std::vector create_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { @@ -72,4 +72,4 @@ namespace vcpkg { namespace Dependencies } return ret; } -}} +} diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index ed70e6881..c7eec3bd0 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -5,7 +5,7 @@ #include "metrics.h" #include "vcpkg_System.h" -namespace vcpkg {namespace Environment +namespace vcpkg::Environment { static const fs::path default_cmake_installation_dir = "C:/Program Files/CMake/bin"; static const fs::path default_cmake_installation_dir_x86 = "C:/Program Files (x86)/CMake/bin"; @@ -83,4 +83,4 @@ namespace vcpkg {namespace Environment // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned ensure_on_path(nuget_version, L"nuget 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency nuget"); } -}} +} diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index 29d487fdb..a8145230c 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -3,7 +3,7 @@ #include "metrics.h" #include "vcpkg_Commands.h" -namespace vcpkg {namespace Input +namespace vcpkg::Input { package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text) { @@ -49,4 +49,4 @@ namespace vcpkg {namespace Input check_triplet(spec.target_triplet(), paths); } } -}} +} -- cgit v1.2.3 From 6e29b7b8d4b3a21e46a721f79d184213d1c874a4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 14:21:09 -0800 Subject: Pass by reference --- toolsrc/src/vcpkg_Input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index a8145230c..365f28cdb 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -42,7 +42,7 @@ namespace vcpkg::Input } } - void check_triplets(std::vector triplets, const vcpkg_paths& paths) + void check_triplets(const std::vector& triplets, const vcpkg_paths& paths) { for (const package_spec& spec : triplets) { -- cgit v1.2.3 From 708e93d82acd4da9c651cc7043dfd32a182ecc11 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 14:25:50 -0800 Subject: Use Nested Namespace Definition --- toolsrc/src/BuildInfo.cpp | 4 ++-- toolsrc/src/Paragraphs.cpp | 4 ++-- toolsrc/src/vcpkg_info.cpp | 4 ++-- toolsrc/src/vcpkglib_helpers.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index f151a3ea5..a45dc4b72 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 PostBuildLint +namespace vcpkg::PostBuildLint { const ConfigurationType& BuildType::config() const { @@ -161,4 +161,4 @@ namespace vcpkg { namespace PostBuildLint { return this->m_dll_name; } -}} +} diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index 823b4a85e..d99ad45cf 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -1,7 +1,7 @@ #include "Paragraphs.h" #include "vcpkg_Files.h" -namespace vcpkg { namespace Paragraphs +namespace vcpkg::Paragraphs { struct Parser { @@ -160,4 +160,4 @@ namespace vcpkg { namespace Paragraphs { return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs(); } -}} +} diff --git a/toolsrc/src/vcpkg_info.cpp b/toolsrc/src/vcpkg_info.cpp index 25c09d6da..69bc6a355 100644 --- a/toolsrc/src/vcpkg_info.cpp +++ b/toolsrc/src/vcpkg_info.cpp @@ -6,7 +6,7 @@ #define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)"" // Double quotes needed at the end to prevent blank token -namespace vcpkg { namespace Info +namespace vcpkg::Info { const std::string& version() { @@ -31,4 +31,4 @@ namespace vcpkg { namespace Info static const std::string s_email = R"(vcpkg@microsoft.com)"; return s_email; } -}} +} diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index d104bb19d..fdc287507 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -3,7 +3,7 @@ #include #include -namespace vcpkg {namespace details +namespace vcpkg::details { std::string optional_field(const std::unordered_map& fields, const std::string& fieldname) { @@ -53,4 +53,4 @@ namespace vcpkg {namespace details simple_desc.append("..."); return simple_desc; } -}} +} -- cgit v1.2.3 From 64e1bf8de73d18c85776c4cce2f40281f3ebb253 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 14:27:36 -0800 Subject: Use Nested Namespace Definition --- toolsrc/src/tests_paragraph.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/tests_paragraph.cpp b/toolsrc/src/tests_paragraph.cpp index 6d9e46fcf..fb20eee82 100644 --- a/toolsrc/src/tests_paragraph.cpp +++ b/toolsrc/src/tests_paragraph.cpp @@ -7,14 +7,14 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; -namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework +namespace Microsoft::VisualStudio::CppUnitTestFramework { template <> inline std::wstring ToString(const vcpkg::package_spec_parse_result& t) { return ToString(static_cast(t)); } -}}} +} namespace UnitTest1 { -- cgit v1.2.3 From e5f60816cb6a786aa828aa2845522bb81c02cbe6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 22 Dec 2016 16:43:47 -0800 Subject: Introduce ImmutableSortedVector --- toolsrc/src/vcpkg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 4748aeb54..eb2184ccb 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -204,7 +204,7 @@ std::vector vcpkg::get_installed_files(con } ), installed_files_of_current_pgh.end()); - StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)}; + StatusParagraph_and_associated_files pgh_and_files = {*pgh, ImmutableSortedVector::create(std::move(installed_files_of_current_pgh))}; installed_files.push_back(std::move(pgh_and_files)); } -- cgit v1.2.3 From ff10939203b7694f21d8e8e0464f092dff1b4eb0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 5 Jan 2017 15:23:08 -0800 Subject: Refactor pre-install check --- toolsrc/src/commands_installation.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index 8d940bc9d..c239bf06c 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -164,9 +164,8 @@ namespace vcpkg return output; } - void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) + static ImmutableSortedVector build_list_of_package_files(const fs::path& package_dir) { - const fs::path package_dir = paths.package_dir(binary_paragraph.spec); const std::vector package_file_paths = Files::recursive_find_all_files_in_dir(package_dir); std::vector package_files; const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash @@ -176,14 +175,27 @@ namespace vcpkg as_string.erase(0, package_remove_char_count); return std::move(as_string); }); - std::sort(package_files.begin(), package_files.end()); - const std::vector& pgh_and_files = get_installed_files(paths, status_db); - const triplet& triplet = binary_paragraph.spec.target_triplet(); + return ImmutableSortedVector::create(std::move(package_files)); + } + + static ImmutableSortedVector build_list_of_installed_files(const std::vector& pgh_and_files, const triplet& triplet) + { std::vector 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 remove_first_n_chars(&installed_files, installed_remove_char_count); - std::sort(installed_files.begin(), installed_files.end()); // Should already be sorted + + return ImmutableSortedVector::create(std::move(installed_files)); + } + + 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 triplet& triplet = binary_paragraph.spec.target_triplet(); + const std::vector pgh_and_files = get_installed_files(paths, status_db); + + const ImmutableSortedVector package_files = build_list_of_package_files(package_dir); + const ImmutableSortedVector installed_files = build_list_of_installed_files(pgh_and_files, triplet); std::vector intersection; std::set_intersection(package_files.cbegin(), package_files.cend(), -- cgit v1.2.3 From 6a4ec92a90849e7cc343bbc8673ce0f063ffd939 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:03:21 -0800 Subject: Place build & build_external commands into separate files --- toolsrc/src/commands_build.cpp | 130 +++++++++++++++++++++++++++++ toolsrc/src/commands_build_external.cpp | 32 ++++++++ toolsrc/src/commands_edit.cpp | 2 +- toolsrc/src/commands_installation.cpp | 141 +------------------------------- 4 files changed, 164 insertions(+), 141 deletions(-) create mode 100644 toolsrc/src/commands_build.cpp create mode 100644 toolsrc/src/commands_build_external.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp new file mode 100644 index 000000000..9f37e25f9 --- /dev/null +++ b/toolsrc/src/commands_build.cpp @@ -0,0 +1,130 @@ +#include "vcpkg_Commands.h" +#include "StatusParagraphs.h" +#include "vcpkg.h" +#include "vcpkg_Input.h" +#include "post_build_lint.h" +#include "vcpkg_Dependencies.h" +#include "vcpkg_System.h" +#include "vcpkg_Environment.h" +#include "metrics.h" +#include "vcpkg_info.h" +#include + +namespace vcpkg +{ + using Dependencies::package_spec_with_install_plan; + using Dependencies::install_plan_type; + + static const std::string OPTION_CHECKS_ONLY = "--checks-only"; + + static void create_binary_control_file(const vcpkg_paths& paths, const SourceParagraph& source_paragraph, const triplet& target_triplet) + { + const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, target_triplet); + const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL"; + std::ofstream(binary_control_file) << bpgh; + } + + namespace Commands::details + { + void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) + { + Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); + const triplet& target_triplet = spec.target_triplet(); + + const fs::path ports_cmake_script_path = paths.ports_cmake; + const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + Strings::utf8_to_utf16(target_triplet.architecture()), + Strings::utf8_to_utf16(source_paragraph.name), + Strings::utf8_to_utf16(target_triplet.canonical_name()), + port_dir.generic_wstring(), + ports_cmake_script_path.generic_wstring()); + + System::Stopwatch2 timer; + timer.start(); + int return_code = System::cmd_execute(command); + timer.stop(); + TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds()); + + if (return_code != 0) + { + System::println(System::color::error, "Error: building package %s failed", to_string(spec)); + System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n" + "submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n" + " Package: %s\n" + " Vcpkg version: %s\n" + "\n" + "Additionally, attach any relevant sections from the log files above." + , to_string(spec), Info::version()); + TrackProperty("error", "build failed"); + TrackProperty("build_error", to_string(spec)); + exit(EXIT_FAILURE); + } + + PostBuildLint::perform_all_checks(spec, paths); + + create_binary_control_file(paths, source_paragraph, target_triplet); + + // const fs::path port_buildtrees_dir = paths.buildtrees / spec.name; + // delete_directory(port_buildtrees_dir); + } + } + void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + { + static const std::string example = create_example_string("build zlib:x64-windows"); + + // Installing multiple packages leads to unintuitive behavior if one of them depends on another. + // Allowing only 1 package for now. + + args.check_exact_arg_count(1, example); + + StatusParagraphs status_db = database_load_check(paths); + + const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example); + Input::check_triplet(spec.target_triplet(), paths); + + const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_CHECKS_ONLY}); + if (options.find(OPTION_CHECKS_ONLY) != options.end()) + { + PostBuildLint::perform_all_checks(spec, paths); + exit(EXIT_SUCCESS); + } + + // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). + const expected maybe_spgh = try_load_port(paths, spec.name()); + Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); + const SourceParagraph& spgh = *maybe_spgh.get(); + + const std::vector first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); + + std::vector first_level_deps_specs; + for (const std::string& dep : first_level_deps) + { + first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); + } + + std::vector unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); + unmet_dependencies.erase( + std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const package_spec_with_install_plan& p) + { + return p.plan.type == install_plan_type::ALREADY_INSTALLED; + }), + unmet_dependencies.end()); + + if (!unmet_dependencies.empty()) + { + 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 package_spec_with_install_plan& p : unmet_dependencies) + { + System::println(" %s", to_string(p.spec)); + } + System::println(""); + exit(EXIT_FAILURE); + } + + Environment::ensure_utilities_on_path(paths); + Commands::details::build_internal(spgh, spec, paths, paths.port_dir(spec)); + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp new file mode 100644 index 000000000..d34981e04 --- /dev/null +++ b/toolsrc/src/commands_build_external.cpp @@ -0,0 +1,32 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" +#include "vcpkg_Environment.h" +#include "vcpkg_Input.h" +#include "vcpkg.h" + +namespace vcpkg +{ + void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + { + static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); + args.check_exact_arg_count(2, example); + + expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); + if (auto spec = maybe_current_spec.get()) + { + Input::check_triplet(spec->target_triplet(), paths); + Environment::ensure_utilities_on_path(paths); + const fs::path port_dir = args.command_arguments.at(1); + const expected maybe_spgh = try_load_port(port_dir); + if (auto spgh = maybe_spgh.get()) + { + Commands::details::build_internal(*spgh, *spec, paths, port_dir); + exit(EXIT_SUCCESS); + } + } + + System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); + print_example(Strings::format("%s zlib:x64-windows", args.command)); + exit(EXIT_FAILURE); + } +} diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index fbf4eab62..f7c489f2b 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -27,7 +27,7 @@ namespace vcpkg } } - std::wstring cmdLine = Strings::wformat(LR"("%s" "%s" "%s")", 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()); exit(System::cmd_execute(cmdLine)); } } diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp index c239bf06c..f44852930 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_installation.cpp @@ -1,72 +1,17 @@ #include "vcpkg_Commands.h" #include "vcpkg.h" -#include #include "vcpkg_Environment.h" #include "metrics.h" #include "vcpkg_Files.h" -#include "post_build_lint.h" #include "vcpkg_System.h" #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" -#include "vcpkg_Maps.h" -#include "vcpkg_info.h" namespace vcpkg { using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; - static const std::string OPTION_CHECKS_ONLY = "--checks-only"; - - static void create_binary_control_file(const vcpkg_paths& paths, const SourceParagraph& source_paragraph, const triplet& target_triplet) - { - const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, target_triplet); - const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL"; - std::ofstream(binary_control_file) << bpgh; - } - - static void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) - { - Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); - const triplet& target_triplet = spec.target_triplet(); - - const fs::path ports_cmake_script_path = paths.ports_cmake; - const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", - Strings::utf8_to_utf16(target_triplet.architecture()), - Strings::utf8_to_utf16(source_paragraph.name), - Strings::utf8_to_utf16(target_triplet.canonical_name()), - port_dir.generic_wstring(), - ports_cmake_script_path.generic_wstring()); - - System::Stopwatch2 timer; - timer.start(); - int return_code = System::cmd_execute(command); - timer.stop(); - TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds()); - - if (return_code != 0) - { - System::println(System::color::error, "Error: building package %s failed", to_string(spec)); - System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n" - "submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n" - " Package: %s\n" - " Vcpkg version: %s\n" - "\n" - "Additionally, attach any relevant sections from the log files above." - , to_string(spec), Info::version()); - TrackProperty("error", "build failed"); - TrackProperty("build_error", to_string(spec)); - exit(EXIT_FAILURE); - } - - PostBuildLint::perform_all_checks(spec, paths); - - create_binary_control_file(paths, source_paragraph, target_triplet); - - // const fs::path port_buildtrees_dir = paths.buildtrees / spec.name; - // delete_directory(port_buildtrees_dir); - } - static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) { std::vector output; @@ -271,7 +216,7 @@ namespace vcpkg } else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) { - build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + Commands::details::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); @@ -293,88 +238,4 @@ namespace vcpkg exit(EXIT_SUCCESS); } - - void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) - { - static const std::string example = create_example_string("build zlib:x64-windows"); - - // Installing multiple packages leads to unintuitive behavior if one of them depends on another. - // Allowing only 1 package for now. - - args.check_exact_arg_count(1, example); - - StatusParagraphs status_db = database_load_check(paths); - - const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example); - Input::check_triplet(spec.target_triplet(), paths); - - const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_CHECKS_ONLY}); - if (options.find(OPTION_CHECKS_ONLY) != options.end()) - { - PostBuildLint::perform_all_checks(spec, paths); - exit(EXIT_SUCCESS); - } - - // Explicitly load and use the portfile's build dependencies when resolving the build command (instead of a cached package's dependencies). - const expected maybe_spgh = try_load_port(paths, spec.name()); - Checks::check_exit(!maybe_spgh.error_code(), "Could not find package named %s: %s", spec, maybe_spgh.error_code().message()); - const SourceParagraph& spgh = *maybe_spgh.get(); - - const std::vector first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); - - std::vector first_level_deps_specs; - for (const std::string& dep : first_level_deps) - { - first_level_deps_specs.push_back(package_spec::from_name_and_triplet(dep, spec.target_triplet()).get_or_throw()); - } - - std::vector unmet_dependencies = Dependencies::create_install_plan(paths, first_level_deps_specs, status_db); - unmet_dependencies.erase( - std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const package_spec_with_install_plan& p) - { - return p.plan.type == install_plan_type::ALREADY_INSTALLED; - }), - unmet_dependencies.end()); - - if (!unmet_dependencies.empty()) - { - 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 package_spec_with_install_plan& p : unmet_dependencies) - { - System::println(" %s", to_string(p.spec)); - } - System::println(""); - exit(EXIT_FAILURE); - } - - Environment::ensure_utilities_on_path(paths); - build_internal(spgh, spec, paths, paths.port_dir(spec)); - exit(EXIT_SUCCESS); - } - - void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) - { - static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); - args.check_exact_arg_count(2, example); - - expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); - if (auto spec = maybe_current_spec.get()) - { - Input::check_triplet(spec->target_triplet(), paths); - Environment::ensure_utilities_on_path(paths); - const fs::path port_dir = args.command_arguments.at(1); - const expected maybe_spgh = try_load_port(port_dir); - if (auto spgh = maybe_spgh.get()) - { - build_internal(*spgh, *spec, paths, port_dir); - exit(EXIT_SUCCESS); - } - } - - System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); - print_example(Strings::format("%s zlib:x64-windows", args.command)); - exit(EXIT_FAILURE); - } } -- cgit v1.2.3 From 30587111d362bc8c2e0b700549d0fe7d62b9193d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:04:32 -0800 Subject: Rename commands_installation to commands_install Names should match the command --- toolsrc/src/commands_install.cpp | 241 ++++++++++++++++++++++++++++++++++ toolsrc/src/commands_installation.cpp | 241 ---------------------------------- 2 files changed, 241 insertions(+), 241 deletions(-) create mode 100644 toolsrc/src/commands_install.cpp delete mode 100644 toolsrc/src/commands_installation.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp new file mode 100644 index 000000000..f44852930 --- /dev/null +++ b/toolsrc/src/commands_install.cpp @@ -0,0 +1,241 @@ +#include "vcpkg_Commands.h" +#include "vcpkg.h" +#include "vcpkg_Environment.h" +#include "metrics.h" +#include "vcpkg_Files.h" +#include "vcpkg_System.h" +#include "vcpkg_Dependencies.h" +#include "vcpkg_Input.h" + +namespace vcpkg +{ + using Dependencies::package_spec_with_install_plan; + using Dependencies::install_plan_type; + + static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) + { + std::vector output; + + const fs::path package_prefix_path = paths.package_dir(bpgh.spec); + const size_t 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); + output.push_back(Strings::format(R"(%s)", target_triplet_as_string)); + + 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; + } + + const std::string suffix = it->path().generic_u8string().substr(prefix_length + 1); + const fs::path 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()); + } + + // Trailing backslash for directories + output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); + continue; + } + + if (fs::is_regular_file(status)) + { + if (fs::exists(target)) + { + System::println(System::color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message()); + } + fs::copy_file(*it, target, fs::copy_options::overwrite_existing, ec); + if (ec) + { + System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); + } + output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); + continue; + } + + if (!fs::status_known(status)) + { + System::println(System::color::error, "failed: %s: unknown status", it->path().u8string()); + continue; + } + + System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); + } + + Files::write_all_lines(paths.listfile_path(bpgh), output); + } + + static void remove_first_n_chars(std::vector* strings, const size_t n) + { + for (std::string& s : *strings) + { + s.erase(0, n); + } + }; + + static std::vector extract_files_in_triplet(const std::vector& pgh_and_files, const triplet& triplet) + { + std::vector output; + for (const StatusParagraph_and_associated_files& t : pgh_and_files) + { + if (t.pgh.package.spec.target_triplet() != triplet) + { + continue; + } + + output.insert(output.end(), t.files.cbegin(), t.files.cend()); + } + + std::sort(output.begin(), output.end()); + return output; + } + + static ImmutableSortedVector build_list_of_package_files(const fs::path& package_dir) + { + const std::vector package_file_paths = Files::recursive_find_all_files_in_dir(package_dir); + std::vector package_files; + const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash + std::transform(package_file_paths.cbegin(), package_file_paths.cend(), std::back_inserter(package_files), [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 ImmutableSortedVector::create(std::move(package_files)); + } + + static ImmutableSortedVector build_list_of_installed_files(const std::vector& pgh_and_files, const triplet& triplet) + { + std::vector 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 + remove_first_n_chars(&installed_files, installed_remove_char_count); + + return ImmutableSortedVector::create(std::move(installed_files)); + } + + 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 triplet& triplet = binary_paragraph.spec.target_triplet(); + const std::vector pgh_and_files = get_installed_files(paths, status_db); + + const ImmutableSortedVector package_files = build_list_of_package_files(package_dir); + const ImmutableSortedVector installed_files = build_list_of_installed_files(pgh_and_files, triplet); + + std::vector intersection; + std::set_intersection(package_files.cbegin(), package_files.cend(), + installed_files.cbegin(), installed_files.cend(), + 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", + triplet_install_path.generic_string(), + binary_paragraph.spec); + System::println(""); + for (const std::string& s : intersection) + { + System::println(" %s", s); + } + System::println(""); + 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"); + args.check_min_arg_count(1, example); + StatusParagraphs status_db = database_load_check(paths); + + std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); + Input::check_triplets(specs, paths); + std::vector install_plan = Dependencies::create_install_plan(paths, specs, status_db); + Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); + + std::string specs_string = to_string(install_plan[0].spec); + for (size_t i = 1; i < install_plan.size(); ++i) + { + specs_string.push_back(','); + specs_string.append(to_string(install_plan[i].spec)); + } + TrackProperty("installplan", specs_string); + Environment::ensure_utilities_on_path(paths); + + for (const package_spec_with_install_plan& action : install_plan) + { + try + { + if (action.plan.type == install_plan_type::ALREADY_INSTALLED) + { + if (std::find(specs.begin(), specs.end(), action.spec) != specs.end()) + { + System::println(System::color::success, "Package %s is already installed", action.spec); + } + } + else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) + { + Commands::details::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); + install_package(paths, bpgh, status_db); + System::println(System::color::success, "Package %s is installed", action.spec); + } + else if (action.plan.type == install_plan_type::INSTALL) + { + install_package(paths, *action.plan.bpgh, status_db); + System::println(System::color::success, "Package %s is installed", action.spec); + } + else + Checks::unreachable(); + } + catch (const std::exception& e) + { + System::println(System::color::error, "Error: Could not install package %s: %s", action.spec, e.what()); + exit(EXIT_FAILURE); + } + } + + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp deleted file mode 100644 index f44852930..000000000 --- a/toolsrc/src/commands_installation.cpp +++ /dev/null @@ -1,241 +0,0 @@ -#include "vcpkg_Commands.h" -#include "vcpkg.h" -#include "vcpkg_Environment.h" -#include "metrics.h" -#include "vcpkg_Files.h" -#include "vcpkg_System.h" -#include "vcpkg_Dependencies.h" -#include "vcpkg_Input.h" - -namespace vcpkg -{ - using Dependencies::package_spec_with_install_plan; - using Dependencies::install_plan_type; - - static void install_and_write_listfile(const vcpkg_paths& paths, const BinaryParagraph& bpgh) - { - std::vector output; - - const fs::path package_prefix_path = paths.package_dir(bpgh.spec); - const size_t 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); - output.push_back(Strings::format(R"(%s)", target_triplet_as_string)); - - 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; - } - - const std::string suffix = it->path().generic_u8string().substr(prefix_length + 1); - const fs::path 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()); - } - - // Trailing backslash for directories - output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); - continue; - } - - if (fs::is_regular_file(status)) - { - if (fs::exists(target)) - { - System::println(System::color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message()); - } - fs::copy_file(*it, target, fs::copy_options::overwrite_existing, ec); - if (ec) - { - System::println(System::color::error, "failed: %s: %s", target.u8string(), ec.message()); - } - output.push_back(Strings::format(R"(%s/%s)", target_triplet_as_string, suffix)); - continue; - } - - if (!fs::status_known(status)) - { - System::println(System::color::error, "failed: %s: unknown status", it->path().u8string()); - continue; - } - - System::println(System::color::error, "failed: %s: cannot handle file type", it->path().u8string()); - } - - Files::write_all_lines(paths.listfile_path(bpgh), output); - } - - static void remove_first_n_chars(std::vector* strings, const size_t n) - { - for (std::string& s : *strings) - { - s.erase(0, n); - } - }; - - static std::vector extract_files_in_triplet(const std::vector& pgh_and_files, const triplet& triplet) - { - std::vector output; - for (const StatusParagraph_and_associated_files& t : pgh_and_files) - { - if (t.pgh.package.spec.target_triplet() != triplet) - { - continue; - } - - output.insert(output.end(), t.files.cbegin(), t.files.cend()); - } - - std::sort(output.begin(), output.end()); - return output; - } - - static ImmutableSortedVector build_list_of_package_files(const fs::path& package_dir) - { - const std::vector package_file_paths = Files::recursive_find_all_files_in_dir(package_dir); - std::vector package_files; - const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash - std::transform(package_file_paths.cbegin(), package_file_paths.cend(), std::back_inserter(package_files), [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 ImmutableSortedVector::create(std::move(package_files)); - } - - static ImmutableSortedVector build_list_of_installed_files(const std::vector& pgh_and_files, const triplet& triplet) - { - std::vector 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 - remove_first_n_chars(&installed_files, installed_remove_char_count); - - return ImmutableSortedVector::create(std::move(installed_files)); - } - - 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 triplet& triplet = binary_paragraph.spec.target_triplet(); - const std::vector pgh_and_files = get_installed_files(paths, status_db); - - const ImmutableSortedVector package_files = build_list_of_package_files(package_dir); - const ImmutableSortedVector installed_files = build_list_of_installed_files(pgh_and_files, triplet); - - std::vector intersection; - std::set_intersection(package_files.cbegin(), package_files.cend(), - installed_files.cbegin(), installed_files.cend(), - 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", - triplet_install_path.generic_string(), - binary_paragraph.spec); - System::println(""); - for (const std::string& s : intersection) - { - System::println(" %s", s); - } - System::println(""); - 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"); - args.check_min_arg_count(1, example); - StatusParagraphs status_db = database_load_check(paths); - - std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); - Input::check_triplets(specs, paths); - std::vector install_plan = Dependencies::create_install_plan(paths, specs, status_db); - Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); - - std::string specs_string = to_string(install_plan[0].spec); - for (size_t i = 1; i < install_plan.size(); ++i) - { - specs_string.push_back(','); - specs_string.append(to_string(install_plan[i].spec)); - } - TrackProperty("installplan", specs_string); - Environment::ensure_utilities_on_path(paths); - - for (const package_spec_with_install_plan& action : install_plan) - { - try - { - if (action.plan.type == install_plan_type::ALREADY_INSTALLED) - { - if (std::find(specs.begin(), specs.end(), action.spec) != specs.end()) - { - System::println(System::color::success, "Package %s is already installed", action.spec); - } - } - else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) - { - Commands::details::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); - const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); - install_package(paths, bpgh, status_db); - System::println(System::color::success, "Package %s is installed", action.spec); - } - else if (action.plan.type == install_plan_type::INSTALL) - { - install_package(paths, *action.plan.bpgh, status_db); - System::println(System::color::success, "Package %s is installed", action.spec); - } - else - Checks::unreachable(); - } - catch (const std::exception& e) - { - System::println(System::color::error, "Error: Could not install package %s: %s", action.spec, e.what()); - exit(EXIT_FAILURE); - } - } - - exit(EXIT_SUCCESS); - } -} -- cgit v1.2.3 From 4c51e65d5004311c7c7ba0687e7dba934ba986c1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:05:20 -0800 Subject: Rename commands_integration.cpp to commands_integrate.cpp Filename should match the command name --- toolsrc/src/commands_integrate.cpp | 318 +++++++++++++++++++++++++++++++++++ toolsrc/src/commands_integration.cpp | 318 ----------------------------------- 2 files changed, 318 insertions(+), 318 deletions(-) create mode 100644 toolsrc/src/commands_integrate.cpp delete mode 100644 toolsrc/src/commands_integration.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp new file mode 100644 index 000000000..e7e5b2d8d --- /dev/null +++ b/toolsrc/src/commands_integrate.cpp @@ -0,0 +1,318 @@ +#define WIN32_LEAN_AND_MEAN +#include +#include +#include "vcpkg_Commands.h" +#include +#include +#include +#include "vcpkg_Environment.h" +#include "vcpkg_Checks.h" +#include "vcpkg_System.h" +#include "vcpkg_Files.h" + +namespace vcpkg +{ + static const std::array old_system_target_files = { + "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets", + "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets" + }; + static const fs::path system_wide_targets_file = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props"; + + static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept + { + return Strings::format(R"###( + + + +)###", target_path, target_path); + } + + static std::string create_system_targets_shortcut() noexcept + { + return R"###( + + + + $(LOCALAPPDATA)\vcpkg\vcpkg.user + + + +)###"; + } + + static std::string create_nuget_targets_file(const fs::path& msbuild_vcpkg_targets_file) noexcept + { + const std::string as_string = msbuild_vcpkg_targets_file.string(); + + return Strings::format(R"###( + + + + + + +)###", as_string, as_string); + } + + static std::string create_nuget_props_file() noexcept + { + return R"###( + + + true + + +)###"; + } + + static std::string get_nuget_id(const fs::path& vcpkg_root_dir) + { + std::string dir_id = vcpkg_root_dir.generic_string(); + std::replace(dir_id.begin(), dir_id.end(), '/', '.'); + dir_id.erase(1, 1); // Erasing the ":" + + // NuGet id cannot have invalid characters. We will only use alphanumeric and dot. + dir_id.erase(std::remove_if(dir_id.begin(), dir_id.end(), [](char c) + { + return !isalnum(c) && (c != '.'); + }), dir_id.end()); + + const std::string nuget_id = "vcpkg." + dir_id; + return nuget_id; + } + + static std::string create_nuspec_file(const fs::path& vcpkg_root_dir, const std::string& nuget_id, const std::string& nupkg_version) + { + const std::string nuspec_file_content_template = R"( + + + @NUGET_ID@ + @VERSION@ + cpp-packages + + This package imports all libraries currently installed in @VCPKG_DIR@. This package does not contain any libraries and instead refers to the folder directly (like a symlink). + + + + + + + +)"; + + std::string nuspec_file_content = std::regex_replace(nuspec_file_content_template, std::regex("@NUGET_ID@"), nuget_id); + nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@VCPKG_DIR@"), vcpkg_root_dir.string()); + nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@VERSION@"), nupkg_version); + return nuspec_file_content; + } + + enum class elevation_prompt_user_choice + { + yes, + no + }; + + static elevation_prompt_user_choice elevated_cmd_execute(const std::string& param) + { + SHELLEXECUTEINFO shExInfo = {0}; + shExInfo.cbSize = sizeof(shExInfo); + shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + shExInfo.hwnd = nullptr; + shExInfo.lpVerb = "runas"; + shExInfo.lpFile = "cmd"; // Application to start + + shExInfo.lpParameters = param.c_str(); // Additional parameters + shExInfo.lpDirectory = nullptr; + shExInfo.nShow = SW_HIDE; + shExInfo.hInstApp = nullptr; + + if (!ShellExecuteExA(&shExInfo)) + { + return elevation_prompt_user_choice::no; + } + if (shExInfo.hProcess == nullptr) + { + return elevation_prompt_user_choice::no; + } + WaitForSingleObject(shExInfo.hProcess, INFINITE); + CloseHandle(shExInfo.hProcess); + return elevation_prompt_user_choice::yes; + } + + static fs::path get_appdata_targets_path() + { + return fs::path(System::wdupenv_str(L"LOCALAPPDATA")) / "vcpkg" / "vcpkg.user.targets"; + } + + static void integrate_install(const vcpkg_paths& paths) + { + // TODO: This block of code should eventually be removed + for (auto&& old_system_wide_targets_file : old_system_target_files) + { + 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()); + elevation_prompt_user_choice user_choice = elevated_cmd_execute(param); + switch (user_choice) + { + case elevation_prompt_user_choice::yes: + break; + case elevation_prompt_user_choice::no: + System::println(System::color::warning, "Warning: Previous integration file was not removed"); + exit(EXIT_FAILURE); + default: + Checks::unreachable(); + } + } + } + + const fs::path tmp_dir = paths.buildsystems / "tmp"; + fs::create_directory(paths.buildsystems); + fs::create_directory(tmp_dir); + + bool should_install_system = true; + if (fs::exists(system_wide_targets_file)) + { + auto system_wide_file_contents = Files::read_contents(system_wide_targets_file); + if (auto contents_data = system_wide_file_contents.get()) + { + std::regex re(R"###()###"); + std::match_results match; + auto found = std::regex_search(*contents_data, match, re); + if (found) + { + int ver = atoi(match[1].str().c_str()); + if (ver >= 1) + should_install_system = false; + } + } + } + + if (should_install_system) + { + const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets"; + std::ofstream(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()); + elevation_prompt_user_choice user_choice = elevated_cmd_execute(param); + switch (user_choice) + { + case elevation_prompt_user_choice::yes: + break; + case elevation_prompt_user_choice::no: + System::println(System::color::warning, "Warning: integration was not applied"); + exit(EXIT_FAILURE); + default: + Checks::unreachable(); + } + + Checks::check_exit(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"; + std::ofstream(appdata_src_path) << create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()); + auto appdata_dst_path = get_appdata_targets_path(); + + if (!fs::copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing)) + { + System::println(System::color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string()); + exit(EXIT_FAILURE); + } + System::println(System::color::success, "Applied user-wide integration for this vcpkg root."); + System::println("\n" + "All C++ projects can now #include any installed libraries.\n" + "Linking will be handled automatically.\n" + "Installing new libraries will make them instantly available."); + + exit(EXIT_SUCCESS); + } + + static void integrate_remove() + { + auto path = get_appdata_targets_path(); + if (!fs::exists(path)) + { + System::println(System::color::success, "User-wide integration is not installed"); + exit(EXIT_SUCCESS); + } + + const std::wstring cmd_line = Strings::wformat(LR"(DEL "%s")", get_appdata_targets_path().native()); + const int exit_code = System::cmd_execute(cmd_line); + if (exit_code) + { + System::println(System::color::error, "Error: Unable to remove user-wide integration: %d", exit_code); + exit(exit_code); + } + System::println(System::color::success, "User-wide integration was removed"); + exit(EXIT_SUCCESS); + } + + static void integrate_project(const vcpkg_paths& paths) + { + Environment::ensure_nuget_on_path(paths); + + const fs::path& buildsystems_dir = paths.buildsystems; + const fs::path tmp_dir = buildsystems_dir / "tmp"; + fs::create_directory(buildsystems_dir); + fs::create_directory(tmp_dir); + + const fs::path targets_file_path = tmp_dir / "vcpkg.nuget.targets"; + const fs::path props_file_path = tmp_dir / "vcpkg.nuget.props"; + const fs::path nuspec_file_path = tmp_dir / "vcpkg.nuget.nuspec"; + const std::string nuget_id = get_nuget_id(paths.root); + const std::string nupkg_version = "1.0.0"; + + std::ofstream(targets_file_path) << create_nuget_targets_file(paths.buildsystems_msbuild_targets); + std::ofstream(props_file_path) << create_nuget_props_file(); + std::ofstream(nuspec_file_path) << create_nuspec_file(paths.root, nuget_id, nupkg_version); + + // Using all forward slashes for the command line + const std::wstring cmd_line = Strings::wformat(LR"(nuget.exe pack -OutputDirectory "%s" "%s" > nul)", buildsystems_dir.native(), nuspec_file_path.native()); + + const int exit_code = System::cmd_execute(cmd_line); + + const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version); + if (exit_code != 0 || !fs::exists(nuget_package)) + { + System::println(System::color::error, "Error: NuGet package creation failed"); + exit(EXIT_FAILURE); + } + + System::println(System::color::success, "Created nupkg: %s", nuget_package.string()); + + 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, buildsystems_dir.generic_string()); + + exit(EXIT_SUCCESS); + } + + 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"; + + void integrate_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + { + static const std::string example = Strings::format("Commands:\n" + "%s", INTEGRATE_COMMAND_HELPSTRING); + args.check_exact_arg_count(1, example); + + if (args.command_arguments[0] == "install") + { + return integrate_install(paths); + } + if (args.command_arguments[0] == "remove") + { + return integrate_remove(); + } + if (args.command_arguments[0] == "project") + { + return integrate_project(paths); + } + + System::println(System::color::error, "Unknown parameter %s for integrate", args.command_arguments[0]); + exit(EXIT_FAILURE); + } +} diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integration.cpp deleted file mode 100644 index e7e5b2d8d..000000000 --- a/toolsrc/src/commands_integration.cpp +++ /dev/null @@ -1,318 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include -#include -#include "vcpkg_Commands.h" -#include -#include -#include -#include "vcpkg_Environment.h" -#include "vcpkg_Checks.h" -#include "vcpkg_System.h" -#include "vcpkg_Files.h" - -namespace vcpkg -{ - static const std::array old_system_target_files = { - "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets", - "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.system.targets" - }; - static const fs::path system_wide_targets_file = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props"; - - static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept - { - return Strings::format(R"###( - - - -)###", target_path, target_path); - } - - static std::string create_system_targets_shortcut() noexcept - { - return R"###( - - - - $(LOCALAPPDATA)\vcpkg\vcpkg.user - - - -)###"; - } - - static std::string create_nuget_targets_file(const fs::path& msbuild_vcpkg_targets_file) noexcept - { - const std::string as_string = msbuild_vcpkg_targets_file.string(); - - return Strings::format(R"###( - - - - - - -)###", as_string, as_string); - } - - static std::string create_nuget_props_file() noexcept - { - return R"###( - - - true - - -)###"; - } - - static std::string get_nuget_id(const fs::path& vcpkg_root_dir) - { - std::string dir_id = vcpkg_root_dir.generic_string(); - std::replace(dir_id.begin(), dir_id.end(), '/', '.'); - dir_id.erase(1, 1); // Erasing the ":" - - // NuGet id cannot have invalid characters. We will only use alphanumeric and dot. - dir_id.erase(std::remove_if(dir_id.begin(), dir_id.end(), [](char c) - { - return !isalnum(c) && (c != '.'); - }), dir_id.end()); - - const std::string nuget_id = "vcpkg." + dir_id; - return nuget_id; - } - - static std::string create_nuspec_file(const fs::path& vcpkg_root_dir, const std::string& nuget_id, const std::string& nupkg_version) - { - const std::string nuspec_file_content_template = R"( - - - @NUGET_ID@ - @VERSION@ - cpp-packages - - This package imports all libraries currently installed in @VCPKG_DIR@. This package does not contain any libraries and instead refers to the folder directly (like a symlink). - - - - - - - -)"; - - std::string nuspec_file_content = std::regex_replace(nuspec_file_content_template, std::regex("@NUGET_ID@"), nuget_id); - nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@VCPKG_DIR@"), vcpkg_root_dir.string()); - nuspec_file_content = std::regex_replace(nuspec_file_content, std::regex("@VERSION@"), nupkg_version); - return nuspec_file_content; - } - - enum class elevation_prompt_user_choice - { - yes, - no - }; - - static elevation_prompt_user_choice elevated_cmd_execute(const std::string& param) - { - SHELLEXECUTEINFO shExInfo = {0}; - shExInfo.cbSize = sizeof(shExInfo); - shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - shExInfo.hwnd = nullptr; - shExInfo.lpVerb = "runas"; - shExInfo.lpFile = "cmd"; // Application to start - - shExInfo.lpParameters = param.c_str(); // Additional parameters - shExInfo.lpDirectory = nullptr; - shExInfo.nShow = SW_HIDE; - shExInfo.hInstApp = nullptr; - - if (!ShellExecuteExA(&shExInfo)) - { - return elevation_prompt_user_choice::no; - } - if (shExInfo.hProcess == nullptr) - { - return elevation_prompt_user_choice::no; - } - WaitForSingleObject(shExInfo.hProcess, INFINITE); - CloseHandle(shExInfo.hProcess); - return elevation_prompt_user_choice::yes; - } - - static fs::path get_appdata_targets_path() - { - return fs::path(System::wdupenv_str(L"LOCALAPPDATA")) / "vcpkg" / "vcpkg.user.targets"; - } - - static void integrate_install(const vcpkg_paths& paths) - { - // TODO: This block of code should eventually be removed - for (auto&& old_system_wide_targets_file : old_system_target_files) - { - 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()); - elevation_prompt_user_choice user_choice = elevated_cmd_execute(param); - switch (user_choice) - { - case elevation_prompt_user_choice::yes: - break; - case elevation_prompt_user_choice::no: - System::println(System::color::warning, "Warning: Previous integration file was not removed"); - exit(EXIT_FAILURE); - default: - Checks::unreachable(); - } - } - } - - const fs::path tmp_dir = paths.buildsystems / "tmp"; - fs::create_directory(paths.buildsystems); - fs::create_directory(tmp_dir); - - bool should_install_system = true; - if (fs::exists(system_wide_targets_file)) - { - auto system_wide_file_contents = Files::read_contents(system_wide_targets_file); - if (auto contents_data = system_wide_file_contents.get()) - { - std::regex re(R"###()###"); - std::match_results match; - auto found = std::regex_search(*contents_data, match, re); - if (found) - { - int ver = atoi(match[1].str().c_str()); - if (ver >= 1) - should_install_system = false; - } - } - } - - if (should_install_system) - { - const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets"; - std::ofstream(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()); - elevation_prompt_user_choice user_choice = elevated_cmd_execute(param); - switch (user_choice) - { - case elevation_prompt_user_choice::yes: - break; - case elevation_prompt_user_choice::no: - System::println(System::color::warning, "Warning: integration was not applied"); - exit(EXIT_FAILURE); - default: - Checks::unreachable(); - } - - Checks::check_exit(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"; - std::ofstream(appdata_src_path) << create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.string()); - auto appdata_dst_path = get_appdata_targets_path(); - - if (!fs::copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing)) - { - System::println(System::color::error, "Error: Failed to copy file: %s -> %s", appdata_src_path.string(), appdata_dst_path.string()); - exit(EXIT_FAILURE); - } - System::println(System::color::success, "Applied user-wide integration for this vcpkg root."); - System::println("\n" - "All C++ projects can now #include any installed libraries.\n" - "Linking will be handled automatically.\n" - "Installing new libraries will make them instantly available."); - - exit(EXIT_SUCCESS); - } - - static void integrate_remove() - { - auto path = get_appdata_targets_path(); - if (!fs::exists(path)) - { - System::println(System::color::success, "User-wide integration is not installed"); - exit(EXIT_SUCCESS); - } - - const std::wstring cmd_line = Strings::wformat(LR"(DEL "%s")", get_appdata_targets_path().native()); - const int exit_code = System::cmd_execute(cmd_line); - if (exit_code) - { - System::println(System::color::error, "Error: Unable to remove user-wide integration: %d", exit_code); - exit(exit_code); - } - System::println(System::color::success, "User-wide integration was removed"); - exit(EXIT_SUCCESS); - } - - static void integrate_project(const vcpkg_paths& paths) - { - Environment::ensure_nuget_on_path(paths); - - const fs::path& buildsystems_dir = paths.buildsystems; - const fs::path tmp_dir = buildsystems_dir / "tmp"; - fs::create_directory(buildsystems_dir); - fs::create_directory(tmp_dir); - - const fs::path targets_file_path = tmp_dir / "vcpkg.nuget.targets"; - const fs::path props_file_path = tmp_dir / "vcpkg.nuget.props"; - const fs::path nuspec_file_path = tmp_dir / "vcpkg.nuget.nuspec"; - const std::string nuget_id = get_nuget_id(paths.root); - const std::string nupkg_version = "1.0.0"; - - std::ofstream(targets_file_path) << create_nuget_targets_file(paths.buildsystems_msbuild_targets); - std::ofstream(props_file_path) << create_nuget_props_file(); - std::ofstream(nuspec_file_path) << create_nuspec_file(paths.root, nuget_id, nupkg_version); - - // Using all forward slashes for the command line - const std::wstring cmd_line = Strings::wformat(LR"(nuget.exe pack -OutputDirectory "%s" "%s" > nul)", buildsystems_dir.native(), nuspec_file_path.native()); - - const int exit_code = System::cmd_execute(cmd_line); - - const fs::path nuget_package = buildsystems_dir / Strings::format("%s.%s.nupkg", nuget_id, nupkg_version); - if (exit_code != 0 || !fs::exists(nuget_package)) - { - System::println(System::color::error, "Error: NuGet package creation failed"); - exit(EXIT_FAILURE); - } - - System::println(System::color::success, "Created nupkg: %s", nuget_package.string()); - - 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, buildsystems_dir.generic_string()); - - exit(EXIT_SUCCESS); - } - - 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"; - - void integrate_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) - { - static const std::string example = Strings::format("Commands:\n" - "%s", INTEGRATE_COMMAND_HELPSTRING); - args.check_exact_arg_count(1, example); - - if (args.command_arguments[0] == "install") - { - return integrate_install(paths); - } - if (args.command_arguments[0] == "remove") - { - return integrate_remove(); - } - if (args.command_arguments[0] == "project") - { - return integrate_project(paths); - } - - System::println(System::color::error, "Unknown parameter %s for integrate", args.command_arguments[0]); - exit(EXIT_FAILURE); - } -} -- cgit v1.2.3 From df2a05e8546281135c6ea12430734d74371bcf46 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:35:33 -0800 Subject: Introduce Command namespace. Refactoring --- toolsrc/src/commands_available_commands.cpp | 44 ++++++++++++ toolsrc/src/commands_build.cpp | 80 +++++++++++---------- toolsrc/src/commands_build_external.cpp | 8 +-- toolsrc/src/commands_cache.cpp | 4 +- toolsrc/src/commands_create.cpp | 4 +- toolsrc/src/commands_edit.cpp | 4 +- toolsrc/src/commands_hash.cpp | 4 +- toolsrc/src/commands_help.cpp | 8 +-- toolsrc/src/commands_helpers.cpp | 55 +++++++++++++++ toolsrc/src/commands_import.cpp | 4 +- toolsrc/src/commands_install.cpp | 6 +- toolsrc/src/commands_integrate.cpp | 2 +- toolsrc/src/commands_list.cpp | 4 +- toolsrc/src/commands_other.cpp | 103 ---------------------------- toolsrc/src/commands_owns.cpp | 4 +- toolsrc/src/commands_portsdiff.cpp | 4 +- toolsrc/src/commands_remove.cpp | 4 +- toolsrc/src/commands_search.cpp | 5 +- toolsrc/src/commands_update.cpp | 2 +- toolsrc/src/main.cpp | 10 +-- toolsrc/src/vcpkg_Input.cpp | 2 +- toolsrc/src/vcpkg_cmd_arguments.cpp | 6 +- 22 files changed, 181 insertions(+), 186 deletions(-) create mode 100644 toolsrc/src/commands_available_commands.cpp create mode 100644 toolsrc/src/commands_helpers.cpp delete mode 100644 toolsrc/src/commands_other.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp new file mode 100644 index 000000000..f78416aed --- /dev/null +++ b/toolsrc/src/commands_available_commands.cpp @@ -0,0 +1,44 @@ +#include "vcpkg_Commands.h" + +namespace vcpkg::Commands +{ + const std::vector>& get_available_commands_type_a() + { + static std::vector> t = { + {"install", install_command}, + {"remove", remove_command}, + {"build", build_command}, + {"build_external", build_external_command} + }; + return t; + } + + const std::vector>& get_available_commands_type_b() + { + static std::vector> t = { + {"/?", help_command}, + {"help", help_command}, + {"search", search_command}, + {"list", list_command}, + {"integrate", integrate_command}, + {"owns", owns_command}, + {"update", update_command}, + {"edit", edit_command}, + {"create", create_command}, + {"import", import_command}, + {"cache", cache_command}, + {"portsdiff", portsdiff_command} + }; + return t; + } + + const std::vector>& get_available_commands_type_c() + { + static std::vector> t = { + {"version", &version_command}, + {"contact", &contact_command}, + {"hash", &hash_command}, + }; + return t; + } +} diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 9f37e25f9..178643d8e 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -10,7 +10,7 @@ #include "vcpkg_info.h" #include -namespace vcpkg +namespace vcpkg::Commands { using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; @@ -24,53 +24,51 @@ namespace vcpkg std::ofstream(binary_control_file) << bpgh; } - namespace Commands::details + void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { - void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) + Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); + const triplet& target_triplet = spec.target_triplet(); + + const fs::path ports_cmake_script_path = paths.ports_cmake; + const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + Strings::utf8_to_utf16(target_triplet.architecture()), + Strings::utf8_to_utf16(source_paragraph.name), + Strings::utf8_to_utf16(target_triplet.canonical_name()), + port_dir.generic_wstring(), + ports_cmake_script_path.generic_wstring()); + + System::Stopwatch2 timer; + timer.start(); + int return_code = System::cmd_execute(command); + timer.stop(); + TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds()); + + if (return_code != 0) { - Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); - const triplet& target_triplet = spec.target_triplet(); - - const fs::path ports_cmake_script_path = paths.ports_cmake; - const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", - Strings::utf8_to_utf16(target_triplet.architecture()), - Strings::utf8_to_utf16(source_paragraph.name), - Strings::utf8_to_utf16(target_triplet.canonical_name()), - port_dir.generic_wstring(), - ports_cmake_script_path.generic_wstring()); - - System::Stopwatch2 timer; - timer.start(); - int return_code = System::cmd_execute(command); - timer.stop(); - TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds()); - - if (return_code != 0) - { - System::println(System::color::error, "Error: building package %s failed", to_string(spec)); - System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n" - "submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n" - " Package: %s\n" - " Vcpkg version: %s\n" - "\n" - "Additionally, attach any relevant sections from the log files above." - , to_string(spec), Info::version()); - TrackProperty("error", "build failed"); - TrackProperty("build_error", to_string(spec)); - exit(EXIT_FAILURE); - } + System::println(System::color::error, "Error: building package %s failed", to_string(spec)); + System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n" + "submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n" + " Package: %s\n" + " Vcpkg version: %s\n" + "\n" + "Additionally, attach any relevant sections from the log files above." + , to_string(spec), Info::version()); + TrackProperty("error", "build failed"); + TrackProperty("build_error", to_string(spec)); + exit(EXIT_FAILURE); + } - PostBuildLint::perform_all_checks(spec, paths); + PostBuildLint::perform_all_checks(spec, paths); - create_binary_control_file(paths, source_paragraph, target_triplet); + create_binary_control_file(paths, source_paragraph, target_triplet); - // const fs::path port_buildtrees_dir = paths.buildtrees / spec.name; - // delete_directory(port_buildtrees_dir); - } + // const fs::path port_buildtrees_dir = paths.buildtrees / spec.name; + // delete_directory(port_buildtrees_dir); } + void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = create_example_string("build zlib:x64-windows"); + static const std::string example = Helpers::create_example_string("build zlib:x64-windows"); // Installing multiple packages leads to unintuitive behavior if one of them depends on another. // Allowing only 1 package for now. @@ -124,7 +122,7 @@ namespace vcpkg } Environment::ensure_utilities_on_path(paths); - Commands::details::build_internal(spgh, spec, paths, paths.port_dir(spec)); + Commands::build_internal(spgh, spec, paths, paths.port_dir(spec)); exit(EXIT_SUCCESS); } } diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index d34981e04..5ed52ad97 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -4,11 +4,11 @@ #include "vcpkg_Input.h" #include "vcpkg.h" -namespace vcpkg +namespace vcpkg::Commands { void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); + static const std::string example = Commands::Helpers::create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); args.check_exact_arg_count(2, example); expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); @@ -20,13 +20,13 @@ namespace vcpkg const expected maybe_spgh = try_load_port(port_dir); if (auto spgh = maybe_spgh.get()) { - Commands::details::build_internal(*spgh, *spec, paths, port_dir); + Commands::build_internal(*spgh, *spec, paths, port_dir); exit(EXIT_SUCCESS); } } System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); - print_example(Strings::format("%s zlib:x64-windows", args.command)); + Commands::Helpers::print_example(Strings::format("%s zlib:x64-windows", args.command)); exit(EXIT_FAILURE); } } diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 1a10b93cf..3d2916418 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -4,7 +4,7 @@ #include "Paragraphs.h" #include "BinaryParagraph.h" -namespace vcpkg +namespace vcpkg::Commands { static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { @@ -37,7 +37,7 @@ namespace vcpkg void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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", 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::Helpers::create_example_string("cache png")); args.check_max_arg_count(1, example); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index ad00cd676..2fcd85dba 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -4,11 +4,11 @@ #include "vcpkg_Files.h" #include "vcpkg_Input.h" -namespace vcpkg +namespace vcpkg::Commands { void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###"); + static const std::string example = Commands::Helpers::create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###"); args.check_max_arg_count(3, example); args.check_min_arg_count(2, example); diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index f7c489f2b..090837a19 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -2,11 +2,11 @@ #include "vcpkg_System.h" #include "vcpkg_Input.h" -namespace vcpkg +namespace vcpkg::Commands { void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = create_example_string("edit zlib"); + static const std::string example = Commands::Helpers::create_example_string("edit zlib"); args.check_exact_arg_count(1, example); const std::string port_name = args.command_arguments.at(0); diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 0e3e8a77c..c6827e07a 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,7 +1,7 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -namespace vcpkg +namespace vcpkg::Commands { static void do_file_hash(fs::path const& path, std::wstring const& hashType) { @@ -26,7 +26,7 @@ namespace vcpkg void hash_command(const vcpkg_cmd_arguments& args) { static const std::string example = Strings::format( - "The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2")); + "The argument should be a file path\n%s", Commands::Helpers::create_example_string("hash boost_1_62_0.tar.bz2")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index fd02d948e..5baec62c7 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -2,7 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg_info.h" -namespace vcpkg +namespace vcpkg::Commands { void version_command(const vcpkg_cmd_arguments& args) { @@ -19,18 +19,18 @@ namespace vcpkg args.check_max_arg_count(1); if (args.command_arguments.empty()) { - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_SUCCESS); } const auto& topic = args.command_arguments[0]; if (topic == "triplet") { - help_topic_valid_triplet(paths); + Commands::help_topic_valid_triplet(paths); } else { System::println(System::color::error, "Error: unknown topic %s", topic); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); diff --git a/toolsrc/src/commands_helpers.cpp b/toolsrc/src/commands_helpers.cpp new file mode 100644 index 000000000..5d6e519ab --- /dev/null +++ b/toolsrc/src/commands_helpers.cpp @@ -0,0 +1,55 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" + +namespace vcpkg::Commands::Helpers +{ + void print_usage() + { + System::println( + "Commands:\n" + " vcpkg search [pat] Search for packages available to be built\n" + " vcpkg install Install a package\n" + " vcpkg remove Uninstall a package. \n" + " vcpkg remove --purge Uninstall and delete a package. \n" + " vcpkg list List installed packages\n" + " vcpkg update Display list of packages for updating\n" + " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" + "\n" + "%s" // Integration help + "\n" + " vcpkg edit Open up a port for editing (uses %%EDITOR%%, default 'code')\n" + " vcpkg import Import a pre-built library\n" + " vcpkg create \n" + " [archivename] Create a new package\n" + " vcpkg owns Search for files in installed packages\n" + " vcpkg cache List cached compiled packages\n" + " vcpkg version Display version information\n" + " vcpkg contact Display contact information to send feedback\n" + "\n" + //"internal commands:\n" + //" --check-build-deps \n" + //" --create-binary-control \n" + //"\n" + "Options:\n" + " --triplet Specify the target architecture triplet.\n" + " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" + "\n" + " --vcpkg-root Specify the vcpkg root directory\n" + " (default: %%VCPKG_ROOT%%)\n" + "\n" + "For more help (including examples) see the accompanying README.md." + , 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); + return cs; + } + + void print_example(const std::string& command_and_arguments) + { + System::println(create_example_string(command_and_arguments)); + } +} diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 3832f0e7b..c2c871414 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Files.h" #include -namespace vcpkg +namespace vcpkg::Commands { struct Binaries { @@ -77,7 +77,7 @@ namespace vcpkg void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); + static const std::string example = Commands::Helpers::create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); args.check_exact_arg_count(3, example); const fs::path control_file_path(args.command_arguments[0]); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index f44852930..ff5ddb0e7 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -7,7 +7,7 @@ #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" -namespace vcpkg +namespace vcpkg::Commands { using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; @@ -185,7 +185,7 @@ namespace vcpkg 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"); + static const std::string example = Commands::Helpers::create_example_string("install zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); @@ -216,7 +216,7 @@ namespace vcpkg } else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) { - Commands::details::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + Commands::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index e7e5b2d8d..323735f6d 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -10,7 +10,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" -namespace vcpkg +namespace vcpkg::Commands { static const std::array old_system_target_files = { "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets", diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index cc51232e9..3e71f9c92 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -3,7 +3,7 @@ #include "vcpkg_System.h" #include "vcpkglib_helpers.h" -namespace vcpkg +namespace vcpkg::Commands { static void do_print(const StatusParagraph& pgh) { @@ -16,7 +16,7 @@ namespace vcpkg void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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", 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::Helpers::create_example_string("list png")); args.check_max_arg_count(1, example); const StatusParagraphs status_paragraphs = database_load_check(paths); diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp deleted file mode 100644 index 6df325100..000000000 --- a/toolsrc/src/commands_other.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "vcpkg_Commands.h" -#include "vcpkg_System.h" - -namespace vcpkg -{ - void print_usage() - { - System::println( - "Commands:\n" - " vcpkg search [pat] Search for packages available to be built\n" - " vcpkg install Install a package\n" - " vcpkg remove Uninstall a package. \n" - " vcpkg remove --purge Uninstall and delete a package. \n" - " vcpkg list List installed packages\n" - " vcpkg update Display list of packages for updating\n" - " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" - "\n" - "%s" // Integration help - "\n" - " vcpkg edit Open up a port for editing (uses %%EDITOR%%, default 'code')\n" - " vcpkg import Import a pre-built library\n" - " vcpkg create \n" - " [archivename] Create a new package\n" - " vcpkg owns Search for files in installed packages\n" - " vcpkg cache List cached compiled packages\n" - " vcpkg version Display version information\n" - " vcpkg contact Display contact information to send feedback\n" - "\n" - //"internal commands:\n" - //" --check-build-deps \n" - //" --create-binary-control \n" - //"\n" - "Options:\n" - " --triplet Specify the target architecture triplet.\n" - " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" - "\n" - " --vcpkg-root Specify the vcpkg root directory\n" - " (default: %%VCPKG_ROOT%%)\n" - "\n" - "For more help (including examples) see the accompanying README.md." - , 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); - return cs; - } - - void print_example(const std::string& command_and_arguments) - { - System::println(create_example_string(command_and_arguments)); - } - - void internal_test_command(const vcpkg_cmd_arguments& /*args*/, const vcpkg_paths& /*paths*/) - { - // auto data = FormatEventData("test"); - // Track(data); - exit(EXIT_SUCCESS); - } - - const std::vector>& get_available_commands_type_a() - { - static std::vector> t = { - {"install", install_command}, - {"remove", remove_command}, - {"build", build_command}, - {"build_external", build_external_command} - }; - return t; - } - - const std::vector>& get_available_commands_type_b() - { - static std::vector> t = { - {"/?", help_command}, - {"help", help_command}, - {"search", search_command}, - {"list", list_command}, - {"integrate", integrate_command}, - {"owns", owns_command}, - {"update", update_command}, - {"edit", edit_command}, - {"create", create_command}, - {"import", import_command}, - {"cache", cache_command}, - {"internal_test", internal_test_command}, - {"portsdiff", portsdiff_command} - }; - return t; - } - - const std::vector>& get_available_commands_type_c() - { - static std::vector> t = { - {"version", &version_command}, - {"contact", &contact_command}, - {"hash", &hash_command}, - }; - return t; - } -} diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index 62dac57eb..e7719fe68 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -2,7 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg.h" -namespace vcpkg +namespace vcpkg::Commands { static void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) { @@ -23,7 +23,7 @@ namespace vcpkg void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a pattern to search for. %s", create_example_string("owns zlib.dll")); + static const std::string example = Strings::format("The argument should be a pattern to search for. %s", Commands::Helpers::create_example_string("owns zlib.dll")); args.check_exact_arg_count(1, example); StatusParagraphs status_db = database_load_check(paths); diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 46c6c90c7..4794dee2b 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -10,7 +10,7 @@ #include "SourceParagraph.h" #include "vcpkg_Environment.h" -namespace vcpkg +namespace vcpkg::Commands { static void do_print_name_and_version(const std::vector& ports_to_print, const std::map& names_and_versions) { @@ -99,7 +99,7 @@ namespace vcpkg void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", 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::Helpers::create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 445213fc2..16e8687e7 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Input.h" #include -namespace vcpkg +namespace vcpkg::Commands { static const std::string OPTION_PURGE = "--purge"; @@ -168,7 +168,7 @@ namespace vcpkg 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"); + static const std::string example = Commands::Helpers::create_example_string("remove zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index a4714477e..cc3e3fe26 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -4,7 +4,7 @@ #include "vcpkglib_helpers.h" #include "SourceParagraph.h" -namespace vcpkg +namespace vcpkg::Commands { static std::vector read_all_source_paragraphs(const vcpkg_paths& paths) { @@ -42,7 +42,8 @@ namespace vcpkg void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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", 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::Helpers::create_example_string("search png")); args.check_max_arg_count(1, example); const std::vector source_paragraphs = read_all_source_paragraphs(paths); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index a4ab7c6e7..9a480f3f5 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -5,7 +5,7 @@ #include "Paragraphs.h" #include "vcpkg_info.h" -namespace vcpkg +namespace vcpkg::Commands { void update_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 7703c541f..8490dc81b 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -21,7 +21,7 @@ bool g_debugging = false; void invalid_command(const std::string& cmd) { System::println(System::color::error, "invalid command: %s", cmd); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } @@ -30,11 +30,11 @@ static void inner(const vcpkg_cmd_arguments& args) TrackProperty("command", args.command); if (args.command.empty()) { - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } - if (auto command_function = find_command(args.command, get_available_commands_type_c())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c())) { return command_function(args); } @@ -66,7 +66,7 @@ static void inner(const vcpkg_cmd_arguments& args) int exit_code = _wchdir(paths.root.c_str()); Checks::check_exit(exit_code == 0, "Changing the working dir failed"); - if (auto command_function = find_command(args.command, get_available_commands_type_b())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) { return command_function(args, paths); } @@ -91,7 +91,7 @@ static void inner(const vcpkg_cmd_arguments& args) Input::check_triplet(default_target_triplet, paths); - if (auto command_function = find_command(args.command, get_available_commands_type_a())) + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a())) { return command_function(args, paths, default_target_triplet); } diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index 365f28cdb..0c36291b4 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -37,7 +37,7 @@ namespace vcpkg::Input { System::println(System::color::error, "Error: invalid triplet: %s", t.canonical_name()); TrackProperty("error", "invalid triplet: " + t.canonical_name()); - help_topic_valid_triplet(paths); + Commands::help_topic_valid_triplet(paths); exit(EXIT_FAILURE); } } diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index a3648668f..ac55e931a 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -18,7 +18,7 @@ namespace vcpkg { System::println(System::color::error, "Error: expected value after %s", option_name); TrackProperty("error", "error option name"); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } @@ -26,7 +26,7 @@ namespace vcpkg { System::println(System::color::error, "Error: %s specified multiple times", option_name); TrackProperty("error", "error option specified multiple times"); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } @@ -42,7 +42,7 @@ namespace vcpkg { System::println(System::color::error, "Error: conflicting values specified for --%s", option_name); TrackProperty("error", "error conflicting switches"); - print_usage(); + Commands::Helpers::print_usage(); exit(EXIT_FAILURE); } option_field = new_setting; -- cgit v1.2.3 From 8e1ed2c9a95fa5b9e0bb0a9849a6e20878696f8c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:41:50 -0800 Subject: Place contact and version commands in different cpp files --- toolsrc/src/commands_contact.cpp | 13 +++++++++++++ toolsrc/src/commands_help.cpp | 18 ------------------ toolsrc/src/commands_version.cpp | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 toolsrc/src/commands_contact.cpp create mode 100644 toolsrc/src/commands_version.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp new file mode 100644 index 000000000..5bd1c1a67 --- /dev/null +++ b/toolsrc/src/commands_contact.cpp @@ -0,0 +1,13 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" +#include "vcpkg_info.h" + +namespace vcpkg::Commands +{ + void contact_command(const vcpkg_cmd_arguments& args) + { + args.check_exact_arg_count(0); + System::println("Send an email to %s with any feedback.", Info::email()); + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index 5baec62c7..a0881e64d 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,19 +1,8 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg_info.h" namespace vcpkg::Commands { - void version_command(const vcpkg_cmd_arguments& args) - { - args.check_exact_arg_count(0); - System::println("Vcpkg package management program version %s\n" - "\n" - "See LICENSE.txt for license information.", Info::version() - ); - exit(EXIT_SUCCESS); - } - void help_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { args.check_max_arg_count(1); @@ -36,13 +25,6 @@ namespace vcpkg::Commands exit(EXIT_SUCCESS); } - void contact_command(const vcpkg_cmd_arguments& args) - { - args.check_exact_arg_count(0); - System::println("Send an email to %s with any feedback.", Info::email()); - exit(EXIT_SUCCESS); - } - void help_topic_valid_triplet(const vcpkg_paths& paths) { System::println("Available architecture triplets:"); diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp new file mode 100644 index 000000000..03cce32d4 --- /dev/null +++ b/toolsrc/src/commands_version.cpp @@ -0,0 +1,16 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" +#include "vcpkg_info.h" + +namespace vcpkg::Commands +{ + void version_command(const vcpkg_cmd_arguments& args) + { + args.check_exact_arg_count(0); + System::println("Vcpkg package management program version %s\n" + "\n" + "See LICENSE.txt for license information.", Info::version() + ); + exit(EXIT_SUCCESS); + } +} -- cgit v1.2.3 From cc8851144a871931b93d84bd962364159ad1c424 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 22:03:57 -0800 Subject: Reorganize commands, each in its own namespace Additionally, functions related to a command can now live in the same namespace --- toolsrc/src/commands_available_commands.cpp | 38 +++++++------- toolsrc/src/commands_build.cpp | 10 ++-- toolsrc/src/commands_build_external.cpp | 10 ++-- toolsrc/src/commands_cache.cpp | 6 +-- toolsrc/src/commands_contact.cpp | 4 +- toolsrc/src/commands_create.cpp | 6 +-- toolsrc/src/commands_edit.cpp | 6 +-- toolsrc/src/commands_hash.cpp | 6 +-- toolsrc/src/commands_help.cpp | 80 +++++++++++++++++++++++------ toolsrc/src/commands_helpers.cpp | 48 ----------------- toolsrc/src/commands_import.cpp | 6 +-- toolsrc/src/commands_install.cpp | 8 +-- toolsrc/src/commands_integrate.cpp | 4 +- toolsrc/src/commands_list.cpp | 6 +-- toolsrc/src/commands_owns.cpp | 6 +-- toolsrc/src/commands_portsdiff.cpp | 6 +-- toolsrc/src/commands_remove.cpp | 6 +-- toolsrc/src/commands_search.cpp | 6 +-- toolsrc/src/commands_update.cpp | 4 +- toolsrc/src/commands_version.cpp | 4 +- toolsrc/src/main.cpp | 4 +- toolsrc/src/vcpkg_Input.cpp | 2 +- toolsrc/src/vcpkg_cmd_arguments.cpp | 6 +-- 23 files changed, 142 insertions(+), 140 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp index f78416aed..48239587d 100644 --- a/toolsrc/src/commands_available_commands.cpp +++ b/toolsrc/src/commands_available_commands.cpp @@ -5,10 +5,10 @@ namespace vcpkg::Commands const std::vector>& get_available_commands_type_a() { static std::vector> t = { - {"install", install_command}, - {"remove", remove_command}, - {"build", build_command}, - {"build_external", build_external_command} + {"install", &Install::perform_and_exit}, + {"remove", &Remove::perform_and_exit}, + {"build", &Build::perform_and_exit}, + {"build_external", &BuildExternal::perform_and_exit} }; return t; } @@ -16,18 +16,18 @@ namespace vcpkg::Commands const std::vector>& get_available_commands_type_b() { static std::vector> t = { - {"/?", help_command}, - {"help", help_command}, - {"search", search_command}, - {"list", list_command}, - {"integrate", integrate_command}, - {"owns", owns_command}, - {"update", update_command}, - {"edit", edit_command}, - {"create", create_command}, - {"import", import_command}, - {"cache", cache_command}, - {"portsdiff", portsdiff_command} + {"/?", &Help::perform_and_exit}, + {"help", &Help::perform_and_exit}, + {"search", &Search::perform_and_exit}, + {"list", &List::perform_and_exit}, + {"integrate", &Integrate::perform_and_exit}, + {"owns", &Owns::perform_and_exit}, + {"update", &Update::perform_and_exit}, + {"edit", &Edit::perform_and_exit}, + {"create", &Create::perform_and_exit}, + {"import", &Import::perform_and_exit}, + {"cache", &Cache::perform_and_exit}, + {"portsdiff", &PortsDiff::perform_and_exit} }; return t; } @@ -35,9 +35,9 @@ namespace vcpkg::Commands const std::vector>& get_available_commands_type_c() { static std::vector> t = { - {"version", &version_command}, - {"contact", &contact_command}, - {"hash", &hash_command}, + {"version", &Version::perform_and_exit}, + {"contact", &Contact::perform_and_exit}, + {"hash", &Hash::perform_and_exit}, }; return t; } diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 178643d8e..72ebb264b 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -10,7 +10,7 @@ #include "vcpkg_info.h" #include -namespace vcpkg::Commands +namespace vcpkg::Commands::Build { using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; @@ -24,7 +24,7 @@ namespace vcpkg::Commands std::ofstream(binary_control_file) << bpgh; } - void build_internal(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) + void build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir) { Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()"); const triplet& target_triplet = spec.target_triplet(); @@ -66,9 +66,9 @@ namespace vcpkg::Commands // delete_directory(port_buildtrees_dir); } - void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = Helpers::create_example_string("build zlib:x64-windows"); + static const std::string example = Commands::Help::create_example_string("build zlib:x64-windows"); // Installing multiple packages leads to unintuitive behavior if one of them depends on another. // Allowing only 1 package for now. @@ -122,7 +122,7 @@ namespace vcpkg::Commands } Environment::ensure_utilities_on_path(paths); - Commands::build_internal(spgh, spec, paths, paths.port_dir(spec)); + build_package(spgh, spec, paths, paths.port_dir(spec)); exit(EXIT_SUCCESS); } } diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index 5ed52ad97..09a9256d7 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -4,11 +4,11 @@ #include "vcpkg_Input.h" #include "vcpkg.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::BuildExternal { - void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = Commands::Helpers::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); expected maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet); @@ -20,13 +20,13 @@ namespace vcpkg::Commands const expected maybe_spgh = try_load_port(port_dir); if (auto spgh = maybe_spgh.get()) { - Commands::build_internal(*spgh, *spec, paths, port_dir); + Commands::Build::build_package(*spgh, *spec, paths, port_dir); exit(EXIT_SUCCESS); } } System::println(System::color::error, "Error: %s: %s", maybe_current_spec.error_code().message(), args.command_arguments[0]); - Commands::Helpers::print_example(Strings::format("%s zlib:x64-windows", args.command)); + Commands::Help::print_example(Strings::format("%s zlib:x64-windows", args.command)); exit(EXIT_FAILURE); } } diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 3d2916418..63bf32260 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -4,7 +4,7 @@ #include "Paragraphs.h" #include "BinaryParagraph.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Cache { static std::vector read_all_binary_paragraphs(const vcpkg_paths& paths) { @@ -34,10 +34,10 @@ namespace vcpkg::Commands return output; } - void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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::Helpers::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); const std::vector binary_paragraphs = read_all_binary_paragraphs(paths); diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp index 5bd1c1a67..3e3ebc2b4 100644 --- a/toolsrc/src/commands_contact.cpp +++ b/toolsrc/src/commands_contact.cpp @@ -2,9 +2,9 @@ #include "vcpkg_System.h" #include "vcpkg_info.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Contact { - void contact_command(const vcpkg_cmd_arguments& args) + void perform_and_exit(const vcpkg_cmd_arguments& args) { args.check_exact_arg_count(0); System::println("Send an email to %s with any feedback.", Info::email()); diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index 2fcd85dba..d842d3fab 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -4,11 +4,11 @@ #include "vcpkg_Files.h" #include "vcpkg_Input.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Create { - void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Commands::Helpers::create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###"); + static const std::string example = Commands::Help::create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###"); args.check_max_arg_count(3, example); args.check_min_arg_count(2, example); diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 090837a19..a4981cf80 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -2,11 +2,11 @@ #include "vcpkg_System.h" #include "vcpkg_Input.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Edit { - void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Commands::Helpers::create_example_string("edit zlib"); + static const std::string example = Commands::Help::create_example_string("edit zlib"); args.check_exact_arg_count(1, example); const std::string port_name = args.command_arguments.at(0); diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index c6827e07a..7048fb0d9 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,7 +1,7 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Hash { static void do_file_hash(fs::path const& path, std::wstring const& hashType) { @@ -23,10 +23,10 @@ namespace vcpkg::Commands System::println(hash); } - void hash_command(const vcpkg_cmd_arguments& args) + void perform_and_exit(const vcpkg_cmd_arguments& args) { static const std::string example = Strings::format( - "The argument should be a file path\n%s", Commands::Helpers::create_example_string("hash boost_1_62_0.tar.bz2")); + "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); diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index a0881e64d..e4769752c 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,37 +1,87 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Help { - void help_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void help_topic_valid_triplet(const vcpkg_paths& paths) + { + System::println("Available architecture triplets:"); + auto it = fs::directory_iterator(paths.triplets); + for (; it != fs::directory_iterator(); ++it) + { + System::println(" %s", it->path().stem().filename().string()); + } + } + + void print_usage() + { + System::println( + "Commands:\n" + " vcpkg search [pat] Search for packages available to be built\n" + " vcpkg install Install a package\n" + " vcpkg remove Uninstall a package. \n" + " vcpkg remove --purge Uninstall and delete a package. \n" + " vcpkg list List installed packages\n" + " vcpkg update Display list of packages for updating\n" + " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" + "\n" + "%s" // Integration help + "\n" + " vcpkg edit Open up a port for editing (uses %%EDITOR%%, default 'code')\n" + " vcpkg import Import a pre-built library\n" + " vcpkg create \n" + " [archivename] Create a new package\n" + " vcpkg owns Search for files in installed packages\n" + " vcpkg cache List cached compiled packages\n" + " vcpkg version Display version information\n" + " vcpkg contact Display contact information to send feedback\n" + "\n" + //"internal commands:\n" + //" --check-build-deps \n" + //" --create-binary-control \n" + //"\n" + "Options:\n" + " --triplet Specify the target architecture triplet.\n" + " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" + "\n" + " --vcpkg-root 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); + } + + std::string create_example_string(const std::string& command_and_arguments) + { + std::string cs = Strings::format("Example:\n" + " vcpkg %s", command_and_arguments); + return cs; + } + + void print_example(const std::string& command_and_arguments) + { + System::println(create_example_string(command_and_arguments)); + } + + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { args.check_max_arg_count(1); if (args.command_arguments.empty()) { - Commands::Helpers::print_usage(); + print_usage(); exit(EXIT_SUCCESS); } const auto& topic = args.command_arguments[0]; if (topic == "triplet") { - Commands::help_topic_valid_triplet(paths); + help_topic_valid_triplet(paths); } else { System::println(System::color::error, "Error: unknown topic %s", topic); - Commands::Helpers::print_usage(); + print_usage(); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } - - void help_topic_valid_triplet(const vcpkg_paths& paths) - { - System::println("Available architecture triplets:"); - auto it = fs::directory_iterator(paths.triplets); - for (; it != fs::directory_iterator(); ++it) - { - System::println(" %s", it->path().stem().filename().string()); - } - } } diff --git a/toolsrc/src/commands_helpers.cpp b/toolsrc/src/commands_helpers.cpp index 5d6e519ab..0c7ce15bb 100644 --- a/toolsrc/src/commands_helpers.cpp +++ b/toolsrc/src/commands_helpers.cpp @@ -3,53 +3,5 @@ namespace vcpkg::Commands::Helpers { - void print_usage() - { - System::println( - "Commands:\n" - " vcpkg search [pat] Search for packages available to be built\n" - " vcpkg install Install a package\n" - " vcpkg remove Uninstall a package. \n" - " vcpkg remove --purge Uninstall and delete a package. \n" - " vcpkg list List installed packages\n" - " vcpkg update Display list of packages for updating\n" - " vcpkg hash [alg] Hash a file by specific algorithm, default SHA512\n" - "\n" - "%s" // Integration help - "\n" - " vcpkg edit Open up a port for editing (uses %%EDITOR%%, default 'code')\n" - " vcpkg import Import a pre-built library\n" - " vcpkg create \n" - " [archivename] Create a new package\n" - " vcpkg owns Search for files in installed packages\n" - " vcpkg cache List cached compiled packages\n" - " vcpkg version Display version information\n" - " vcpkg contact Display contact information to send feedback\n" - "\n" - //"internal commands:\n" - //" --check-build-deps \n" - //" --create-binary-control \n" - //"\n" - "Options:\n" - " --triplet Specify the target architecture triplet.\n" - " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" - "\n" - " --vcpkg-root Specify the vcpkg root directory\n" - " (default: %%VCPKG_ROOT%%)\n" - "\n" - "For more help (including examples) see the accompanying README.md." - , 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); - return cs; - } - - void print_example(const std::string& command_and_arguments) - { - System::println(create_example_string(command_and_arguments)); - } } diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index c2c871414..14e83e75f 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Files.h" #include -namespace vcpkg::Commands +namespace vcpkg::Commands::Import { struct Binaries { @@ -75,9 +75,9 @@ namespace vcpkg::Commands std::ofstream(control_file_path) << control_file_data; } - void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Commands::Helpers::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); const fs::path control_file_path(args.command_arguments[0]); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index ff5ddb0e7..ff517d9b1 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -7,7 +7,7 @@ #include "vcpkg_Dependencies.h" #include "vcpkg_Input.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Install { using Dependencies::package_spec_with_install_plan; using Dependencies::install_plan_type; @@ -183,9 +183,9 @@ namespace vcpkg::Commands status_db.insert(std::make_unique(spgh)); } - void install_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = Commands::Helpers::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); StatusParagraphs status_db = database_load_check(paths); @@ -216,7 +216,7 @@ namespace vcpkg::Commands } else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) { - Commands::build_internal(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + Commands::Build::build_package(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 323735f6d..2bd5027ec 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -10,7 +10,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Integrate { static const std::array old_system_target_files = { "C:/Program Files (x86)/MSBuild/14.0/Microsoft.Common.Targets/ImportBefore/vcpkg.nuget.targets", @@ -293,7 +293,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console " vcpkg integrate remove Remove user-wide integration\n" " vcpkg integrate project Generate a referencing nuget package for individual VS project use\n"; - void integrate_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { static const std::string example = Strings::format("Commands:\n" "%s", INTEGRATE_COMMAND_HELPSTRING); diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 3e71f9c92..d9c4a52f2 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -3,7 +3,7 @@ #include "vcpkg_System.h" #include "vcpkglib_helpers.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::List { static void do_print(const StatusParagraph& pgh) { @@ -13,10 +13,10 @@ namespace vcpkg::Commands details::shorten_description(pgh.package.description)); } - void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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::Helpers::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); const StatusParagraphs status_paragraphs = database_load_check(paths); diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index e7719fe68..bb1a7eb9f 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -2,7 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Owns { static void search_file(const vcpkg_paths& paths, const std::string& file_substr, const StatusParagraphs& status_db) { @@ -21,9 +21,9 @@ namespace vcpkg::Commands } } - void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a pattern to search for. %s", Commands::Helpers::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); StatusParagraphs status_db = database_load_check(paths); diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 4794dee2b..1665d7c47 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -10,7 +10,7 @@ #include "SourceParagraph.h" #include "vcpkg_Environment.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::PortsDiff { static void do_print_name_and_version(const std::vector& ports_to_print, const std::map& names_and_versions) { @@ -97,9 +97,9 @@ namespace vcpkg::Commands Checks::check_exit(output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); } - void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Helpers::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); diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 16e8687e7..23d981fc1 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Input.h" #include -namespace vcpkg::Commands +namespace vcpkg::Commands::Remove { static const std::string OPTION_PURGE = "--purge"; @@ -166,9 +166,9 @@ namespace vcpkg::Commands 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) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { - static const std::string example = Commands::Helpers::create_example_string("remove zlib zlib:x64-windows curl boost"); + static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index cc3e3fe26..3f197b06b 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -4,7 +4,7 @@ #include "vcpkglib_helpers.h" #include "SourceParagraph.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Search { static std::vector read_all_source_paragraphs(const vcpkg_paths& paths) { @@ -40,10 +40,10 @@ namespace vcpkg::Commands details::shorten_description(source_paragraph.description)); } - void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& 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::Helpers::create_example_string("search png")); + Commands::Help::create_example_string("search png")); args.check_max_arg_count(1, example); const std::vector source_paragraphs = read_all_source_paragraphs(paths); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 9a480f3f5..12b4dad50 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -5,9 +5,9 @@ #include "Paragraphs.h" #include "vcpkg_info.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Update { - void update_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { args.check_exact_arg_count(0); System::println("Using local portfile versions. To update the local portfiles, use `git pull`."); diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp index 03cce32d4..e98251601 100644 --- a/toolsrc/src/commands_version.cpp +++ b/toolsrc/src/commands_version.cpp @@ -2,9 +2,9 @@ #include "vcpkg_System.h" #include "vcpkg_info.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::Version { - void version_command(const vcpkg_cmd_arguments& args) + void perform_and_exit(const vcpkg_cmd_arguments& args) { args.check_exact_arg_count(0); System::println("Vcpkg package management program version %s\n" diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 8490dc81b..08e65391f 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -21,7 +21,7 @@ bool g_debugging = false; void invalid_command(const std::string& cmd) { System::println(System::color::error, "invalid command: %s", cmd); - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } @@ -30,7 +30,7 @@ static void inner(const vcpkg_cmd_arguments& args) TrackProperty("command", args.command); if (args.command.empty()) { - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index 0c36291b4..bf7ccd346 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -37,7 +37,7 @@ namespace vcpkg::Input { System::println(System::color::error, "Error: invalid triplet: %s", t.canonical_name()); TrackProperty("error", "invalid triplet: " + t.canonical_name()); - Commands::help_topic_valid_triplet(paths); + Commands::Help::help_topic_valid_triplet(paths); exit(EXIT_FAILURE); } } diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index ac55e931a..aa1c35965 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -18,7 +18,7 @@ namespace vcpkg { System::println(System::color::error, "Error: expected value after %s", option_name); TrackProperty("error", "error option name"); - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } @@ -26,7 +26,7 @@ namespace vcpkg { System::println(System::color::error, "Error: %s specified multiple times", option_name); TrackProperty("error", "error option specified multiple times"); - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } @@ -42,7 +42,7 @@ namespace vcpkg { System::println(System::color::error, "Error: conflicting values specified for --%s", option_name); TrackProperty("error", "error conflicting switches"); - Commands::Helpers::print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } option_field = new_setting; -- cgit v1.2.3 From fe2c0a3a78f4904288ce958ded767160d1de260c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 13 Jan 2017 02:09:08 -0800 Subject: [edit command] Now checks that port exists before opening --- toolsrc/src/commands_edit.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index a4981cf80..3297b5295 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -11,6 +11,7 @@ namespace vcpkg::Commands::Edit const std::string port_name = args.command_arguments.at(0); const fs::path portpath = paths.ports / port_name; + Checks::check_exit(fs::is_directory(portpath), "Could not find port named %s", port_name); // Find editor std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR"); -- cgit v1.2.3 From 6d3ab4579d50f74cbe43373fa16ba875a97a8717 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:12:43 -0800 Subject: [vcpkg_paths] Add "scripts" entry --- toolsrc/src/vcpkg_paths.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index b7e716307..39e4c8986 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -31,8 +31,9 @@ namespace vcpkg paths.ports = paths.root / "ports"; paths.installed = paths.root / "installed"; paths.triplets = paths.root / "triplets"; + paths.scripts = paths.root / "scripts"; - paths.buildsystems = paths.root / "scripts" / "buildsystems"; + paths.buildsystems = paths.scripts / "buildsystems"; paths.buildsystems_msbuild_targets = paths.buildsystems / "msbuild" / "vcpkg.targets"; paths.vcpkg_dir = paths.installed / "vcpkg"; @@ -40,7 +41,7 @@ namespace vcpkg paths.vcpkg_dir_info = paths.vcpkg_dir / "info"; paths.vcpkg_dir_updates = paths.vcpkg_dir / "updates"; - paths.ports_cmake = paths.root / "scripts" / "ports.cmake"; + paths.ports_cmake = paths.scripts / "ports.cmake"; return paths; } -- cgit v1.2.3 From 3a6571a0191df8ff000384937a6254f378ca23cf Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:13:12 -0800 Subject: Add Strings::split() function --- toolsrc/src/vcpkg_Strings.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index cf7d3b0ee..16477a45c 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -119,4 +119,25 @@ namespace vcpkg::Strings return s == ""; }), strings->end()); } + + std::vector split(const std::string& s, const std::string& delimiter) + { + std::vector output; + + size_t i = 0; + size_t pos = s.find(delimiter); + while (pos != std::string::npos) + { + output.push_back(s.substr(i, pos - i)); + i = ++pos; + pos = s.find(delimiter, pos); + + if (pos == std::string::npos) + { + output.push_back(s.substr(i, s.length())); + } + } + + return output; + } } -- cgit v1.2.3 From 79a00367390dd974170b3abb5ad357d3db8ff5e3 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:15:26 -0800 Subject: [VS2017] Add function do get dumpbin.exe --- toolsrc/src/vcpkg_Environment.cpp | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index c7eec3bd0..1cbd60341 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -4,6 +4,7 @@ #include "vcpkg_Commands.h" #include "metrics.h" #include "vcpkg_System.h" +#include "vcpkg_Strings.h" namespace vcpkg::Environment { @@ -83,4 +84,53 @@ namespace vcpkg::Environment // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned ensure_on_path(nuget_version, L"nuget 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency nuget"); } + + static std::vector get_VS2017_installation_instances(const vcpkg_paths& paths) + { + const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1"; + const std::wstring cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s", script.native()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd); + Checks::check_exit(ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances"); + return Strings::split(ec_data.output, "\n"); + } + + static fs::path find_dumpbin_exe(const vcpkg_paths& paths) + { + const std::vector vs2017_installation_instances = get_VS2017_installation_instances(paths); + std::vector paths_examined; + + // VS2017 + for (const std::string& instance : vs2017_installation_instances) + { + const fs::path dumpbin_path = Strings::format(R"(%s\VC\Tools\MSVC\14.10.24911\bin\HostX86\x86\dumpbin.exe)", instance); + paths_examined.push_back(dumpbin_path); + if (fs::exists(dumpbin_path)) + { + return dumpbin_path; + } + } + + // VS2015 + const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // TODO: Check why this requires parent_path() call + const fs::path vs2015_dumpbin_exe = vs2015_cmntools.parent_path().parent_path() / "VC" / "bin" / "dumpbin.exe"; + paths_examined.push_back(vs2015_dumpbin_exe); + if (fs::exists(vs2015_dumpbin_exe)) + { + return vs2015_dumpbin_exe; + } + + System::println(System::color::error, "Could not detect dumpbin.exe."); + System::println("The following paths were examined:"); + for (const fs::path& path : paths_examined) + { + System::println(path.generic_string()); + } + exit(EXIT_FAILURE); + } + + const fs::path& get_dumpbin_exe(const vcpkg_paths& paths) + { + static const fs::path dumpbin_exe = find_dumpbin_exe(paths); + return dumpbin_exe; + } } -- cgit v1.2.3 From 9194f36a6c3ac873ca13a4be11745968ae1e263e Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:24:31 -0800 Subject: [VS2017] Use Environment::get_dumpbin_exe() --- toolsrc/src/post_build_lint.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index 1fca3a2f6..af76b7963 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -3,6 +3,7 @@ #include "vcpkg_Files.h" #include #include "vcpkg_System.h" +#include "vcpkg_Environment.h" #include "coff_file_reader.h" #include "BuildInfo.h" #include @@ -15,8 +16,6 @@ namespace vcpkg::PostBuildLint ERROR_DETECTED = 1 }; - static const fs::path DUMPBIN_EXE = R"(%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe)"; - static lint_status check_for_files_in_include_directory(const fs::path& package_dir) { const fs::path include_dir = package_dir / "include"; @@ -185,12 +184,12 @@ namespace vcpkg::PostBuildLint return lint_status::SUCCESS; } - static lint_status check_exports_of_dlls(const std::vector& dlls) + static lint_status check_exports_of_dlls(const std::vector& dlls, const fs::path& dumpbin_exe) { std::vector 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::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); @@ -211,7 +210,7 @@ namespace vcpkg::PostBuildLint return lint_status::SUCCESS; } - static lint_status check_uwp_bit_of_dlls(const std::string& expected_system_name, const std::vector& dlls) + static lint_status check_uwp_bit_of_dlls(const std::string& expected_system_name, const std::vector& dlls, const fs::path dumpbin_exe) { if (expected_system_name != "uwp") { @@ -221,7 +220,7 @@ namespace vcpkg::PostBuildLint std::vector 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::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); @@ -459,7 +458,7 @@ namespace vcpkg::PostBuildLint BuildType build_type; }; - static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs) + static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs, const fs::path dumpbin_exe) { std::vector bad_build_types = BuildType::values(); bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end()); @@ -468,7 +467,7 @@ namespace vcpkg::PostBuildLint 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::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); @@ -505,7 +504,7 @@ namespace vcpkg::PostBuildLint OutdatedDynamicCrt outdated_crt; }; - static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls) + static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls, const fs::path dumpbin_exe) { const std::vector& outdated_crts = OutdatedDynamicCrt::values(); @@ -513,7 +512,7 @@ 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::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); @@ -575,6 +574,8 @@ namespace vcpkg::PostBuildLint void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) { + const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths); + System::println("-- Performing post-build validation"); BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); @@ -623,11 +624,11 @@ namespace vcpkg::PostBuildLint 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); - error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls); + error_count += check_exports_of_dlls(dlls, dumpbin_exe); + error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); - error_count += check_outdated_crt_linkage_of_dlls(dlls); + error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); break; } case LinkageType::STATIC: @@ -638,8 +639,8 @@ namespace vcpkg::PostBuildLint error_count += check_bin_folders_are_not_present_in_static_build(package_dir); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); break; } case LinkageType::UNKNOWN: -- cgit v1.2.3 From 50d5e12390636137fedc1472872a4ae777bf1b2c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:30:04 -0800 Subject: [VS2017] Extract function that detects the VS2015 instance, when no VS2017 is found --- toolsrc/src/vcpkg_Environment.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 1cbd60341..00f7206e3 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -94,6 +94,13 @@ namespace vcpkg::Environment return Strings::split(ec_data.output, "\n"); } + static const fs::path& get_VS2015_installation_instance() + { + static const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // TODO: Check why this requires parent_path() call + static const fs::path vs2015_path = vs2015_cmntools.parent_path().parent_path(); + return vs2015_path; + } + static fs::path find_dumpbin_exe(const vcpkg_paths& paths) { const std::vector vs2017_installation_instances = get_VS2017_installation_instances(paths); @@ -111,8 +118,7 @@ namespace vcpkg::Environment } // VS2015 - const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // TODO: Check why this requires parent_path() call - const fs::path vs2015_dumpbin_exe = vs2015_cmntools.parent_path().parent_path() / "VC" / "bin" / "dumpbin.exe"; + const fs::path vs2015_dumpbin_exe = get_VS2015_installation_instance() / "VC" / "bin" / "dumpbin.exe"; paths_examined.push_back(vs2015_dumpbin_exe); if (fs::exists(vs2015_dumpbin_exe)) { -- cgit v1.2.3 From 691f337bb3e56487911615a14cd06c86c029eb4b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 15:48:54 -0800 Subject: [VS2017] Don't depend on a specific MSVC dir name --- toolsrc/src/vcpkg_Environment.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 00f7206e3..0f4d4b60a 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -5,6 +5,7 @@ #include "metrics.h" #include "vcpkg_System.h" #include "vcpkg_Strings.h" +#include "vcpkg_Files.h" namespace vcpkg::Environment { @@ -109,11 +110,29 @@ namespace vcpkg::Environment // VS2017 for (const std::string& instance : vs2017_installation_instances) { - const fs::path dumpbin_path = Strings::format(R"(%s\VC\Tools\MSVC\14.10.24911\bin\HostX86\x86\dumpbin.exe)", instance); - paths_examined.push_back(dumpbin_path); - if (fs::exists(dumpbin_path)) + const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance); + std::vector msvc_subdirectories; + Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current) { - return dumpbin_path; + return fs::is_directory(current); + }, &msvc_subdirectories); + + Checks::check_exit(!msvc_subdirectories.empty(), "No subdirectories were found in %s", msvc_path.generic_string()); + + // 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(); + }); + + for (const fs::path& subdir : msvc_subdirectories) + { + const fs::path dumpbin_path = Strings::format(R"(%s\bin\HostX86\x86\dumpbin.exe)", subdir.generic_string()); + paths_examined.push_back(dumpbin_path); + if (fs::exists(dumpbin_path)) + { + return dumpbin_path; + } } } -- cgit v1.2.3 From c1aca5d4adfe0fedd4636ffb488c6f22bbb33f81 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:02:02 -0800 Subject: Build path throuh fs::path APIs instead of Strings::format() --- toolsrc/src/vcpkg_Environment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 0f4d4b60a..f6bcd3088 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -127,7 +127,7 @@ namespace vcpkg::Environment for (const fs::path& subdir : msvc_subdirectories) { - const fs::path dumpbin_path = Strings::format(R"(%s\bin\HostX86\x86\dumpbin.exe)", subdir.generic_string()); + const fs::path dumpbin_path = subdir / "bin" / "HostX86" / "x86" / "dumpbin.exe"; paths_examined.push_back(dumpbin_path); if (fs::exists(dumpbin_path)) { -- cgit v1.2.3 From a532b949073a14303cf3092d6b8d83a9e4ee8577 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:04:43 -0800 Subject: Formatting --- toolsrc/src/vcpkg_Environment.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index f6bcd3088..3efcfb872 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -113,17 +113,17 @@ namespace vcpkg::Environment const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance); std::vector msvc_subdirectories; Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current) - { - return fs::is_directory(current); - }, &msvc_subdirectories); + { + return fs::is_directory(current); + }, &msvc_subdirectories); Checks::check_exit(!msvc_subdirectories.empty(), "No subdirectories were found in %s", msvc_path.generic_string()); // 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(); - }); + { + return left.filename() > right.filename(); + }); for (const fs::path& subdir : msvc_subdirectories) { -- cgit v1.2.3 From e0e3f6ac21d074b0c043e9d6a2aff769930f07a7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:15:30 -0800 Subject: [VS2017] Add function to get vcvarsall.bat --- toolsrc/src/vcpkg_Environment.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 3efcfb872..54541bd45 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -158,4 +158,43 @@ namespace vcpkg::Environment static const fs::path dumpbin_exe = find_dumpbin_exe(paths); return dumpbin_exe; } + + static fs::path find_vcvarsall_bat(const vcpkg_paths& paths) + { + const std::vector vs2017_installation_instances = get_VS2017_installation_instances(paths); + std::vector paths_examined; + + // VS2017 + for (const fs::path& instance : vs2017_installation_instances) + { + const fs::path vcvarsall_bat = instance / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; + paths_examined.push_back(vcvarsall_bat); + if (fs::exists(vcvarsall_bat)) + { + return vcvarsall_bat; + } + } + + // VS2015 + const fs::path vs2015_vcvarsall_bat = get_VS2015_installation_instance() / "VC" / "vcvarsall.bat"; + paths_examined.push_back(vs2015_vcvarsall_bat); + if (fs::exists(vs2015_vcvarsall_bat)) + { + return vs2015_vcvarsall_bat; + } + + System::println(System::color::error, "Could not detect vccarsall.bat."); + System::println("The following paths were examined:"); + for (const fs::path& path : paths_examined) + { + System::println(path.generic_string()); + } + exit(EXIT_FAILURE); + } + + const fs::path& get_vcvarsall_bat(const vcpkg_paths& paths) + { + static const fs::path vcvarsall_bat = find_vcvarsall_bat(paths); + return vcvarsall_bat; + } } -- cgit v1.2.3 From 127fbe20263302ee2d877dcfedcf853d0415ce2f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:16:19 -0800 Subject: [VS2017] Use Environment::get_vcvarsall_bat() --- toolsrc/src/commands_build.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 72ebb264b..af1b3dc24 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -30,7 +30,9 @@ namespace vcpkg::Commands::Build const triplet& target_triplet = spec.target_triplet(); const fs::path ports_cmake_script_path = paths.ports_cmake; - const std::wstring command = Strings::wformat(LR"("%%VS140COMNTOOLS%%..\..\VC\vcvarsall.bat" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + const fs::path vcvarsall_bat = Environment::get_vcvarsall_bat(paths); + const std::wstring command = Strings::wformat(LR"("%s" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + vcvarsall_bat.native(), Strings::utf8_to_utf16(target_triplet.architecture()), Strings::utf8_to_utf16(source_paragraph.name), Strings::utf8_to_utf16(target_triplet.canonical_name()), -- cgit v1.2.3 From 612d2041214e90d242a5cad9bcf8b2b52357685d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:37:03 -0800 Subject: Remove check for empty MSVC dir. --- toolsrc/src/vcpkg_Environment.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 54541bd45..de17158b4 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -117,8 +117,6 @@ namespace vcpkg::Environment return fs::is_directory(current); }, &msvc_subdirectories); - Checks::check_exit(!msvc_subdirectories.empty(), "No subdirectories were found in %s", msvc_path.generic_string()); - // Sort them so that latest comes first std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [&](const fs::path& left, const fs::path& right) { -- cgit v1.2.3 From a4b419dc7b6fd533904b5c702053c4a871f72629 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:39:05 -0800 Subject: Add comment about trailing backslash in VS140COMNTOOLS --- toolsrc/src/vcpkg_Environment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index de17158b4..709627878 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -97,7 +97,7 @@ namespace vcpkg::Environment static const fs::path& get_VS2015_installation_instance() { - static const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // TODO: Check why this requires parent_path() call + static const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // The call to parent path is needed because the env variable has a trailing backslash static const fs::path vs2015_path = vs2015_cmntools.parent_path().parent_path(); return vs2015_path; } -- cgit v1.2.3 From ac2f2cb478bba52c247ccdab13b9c5ad15cd4947 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:46:58 -0800 Subject: Strings::split() now handles trailing delimiters --- toolsrc/src/vcpkg_Strings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 16477a45c..e53cfa1ef 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -132,7 +132,7 @@ namespace vcpkg::Strings i = ++pos; pos = s.find(delimiter, pos); - if (pos == std::string::npos) + if (pos == std::string::npos && i != s.length()) // The second check is so no items are added if there is nothing after the last delimiter { output.push_back(s.substr(i, s.length())); } -- cgit v1.2.3 From 5d603cbae259e492b8ff034a748573d3f680e7c7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 16:50:29 -0800 Subject: Improve Strings::split() --- toolsrc/src/vcpkg_Strings.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index e53cfa1ef..b974b0a06 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -125,17 +125,16 @@ namespace vcpkg::Strings std::vector output; size_t i = 0; - size_t pos = s.find(delimiter); - while (pos != std::string::npos) + for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos)) { output.push_back(s.substr(i, pos - i)); i = ++pos; - pos = s.find(delimiter, pos); + } - if (pos == std::string::npos && i != s.length()) // The second check is so no items are added if there is nothing after the last delimiter - { - output.push_back(s.substr(i, s.length())); - } + // Add the rest of the string after the last delimiter, unless there is nothing after it + if (i != s.length()) + { + output.push_back(s.substr(i, s.length())); } return output; -- cgit v1.2.3 From 522b393901638c3abfc89ff63085ec64367c7671 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 17:02:43 -0800 Subject: Bump version of required CMake to 3.7.2 --- toolsrc/src/vcpkg_Environment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 709627878..e1eb22969 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -63,7 +63,7 @@ namespace vcpkg::Environment void ensure_cmake_on_path(const vcpkg_paths& paths) { - const fs::path downloaded_cmake = paths.downloads / "cmake-3.5.2-win32-x86" / "bin"; + const fs::path downloaded_cmake = paths.downloads / "cmake-3.7.2-win32-x86" / "bin"; const std::wstring path_buf = Strings::wformat(L"%s;%s;%s;%s", downloaded_cmake.native(), System::wdupenv_str(L"PATH"), @@ -71,7 +71,7 @@ namespace vcpkg::Environment default_cmake_installation_dir_x86.native()); _wputenv_s(L"PATH", path_buf.c_str()); - static constexpr std::array cmake_version = {3,5,0}; + static constexpr std::array cmake_version = {3,7,2}; // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned ensure_on_path(cmake_version, L"cmake --version 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency cmake"); } -- cgit v1.2.3 From 4e86b01a36cba7a1e1b883a8d62a6f68c2b6e030 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 17:24:34 -0800 Subject: [Environemnt] Don't depend on present working dir --- toolsrc/src/vcpkg_Environment.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index e1eb22969..22a9252b0 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -14,7 +14,7 @@ namespace vcpkg::Environment static const fs::path default_git_installation_dir = "C:/Program Files/git/cmd"; static const fs::path default_git_installation_dir_x86 = "C:/Program Files (x86)/git/cmd"; - static void ensure_on_path(const std::array& version, const wchar_t* version_check_cmd, const wchar_t* install_cmd) + static void ensure_on_path(const std::array& version, const std::wstring& version_check_cmd, const std::wstring& install_cmd) { System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(version_check_cmd); if (ec_data.exit_code == 0) @@ -57,8 +57,11 @@ namespace vcpkg::Environment _wputenv_s(L"PATH", path_buf.c_str()); static constexpr std::array git_version = {2,0,0}; + static const std::wstring version_check_cmd = L"git --version 2>&1"; + const fs::path script = paths.scripts / "fetchDependency.ps1"; // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - ensure_on_path(git_version, L"git --version 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency git"); + const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency git", script.native()); + ensure_on_path(git_version, version_check_cmd, install_cmd); } void ensure_cmake_on_path(const vcpkg_paths& paths) @@ -72,8 +75,11 @@ namespace vcpkg::Environment _wputenv_s(L"PATH", path_buf.c_str()); static constexpr std::array cmake_version = {3,7,2}; + static const std::wstring version_check_cmd = L"cmake --version 2>&1"; + const fs::path script = paths.scripts / "fetchDependency.ps1"; // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - ensure_on_path(cmake_version, L"cmake --version 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency cmake"); + const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency cmake", script.native()); + ensure_on_path(cmake_version, version_check_cmd, install_cmd); } void ensure_nuget_on_path(const vcpkg_paths& paths) @@ -82,8 +88,11 @@ namespace vcpkg::Environment _wputenv_s(L"PATH", path_buf.c_str()); static constexpr std::array nuget_version = {1,0,0}; + static const std::wstring version_check_cmd = L"nuget 2>&1"; + const fs::path script = paths.scripts / "fetchDependency.ps1"; // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - ensure_on_path(nuget_version, L"nuget 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency nuget"); + const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency nuget", script.native()); + ensure_on_path(nuget_version, version_check_cmd, install_cmd); } static std::vector get_VS2017_installation_instances(const vcpkg_paths& paths) -- cgit v1.2.3 From d9f770ad8d6010a09d6be2ec9a262fc6ce074267 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 17:28:20 -0800 Subject: Improve comment --- toolsrc/src/vcpkg_Environment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 22a9252b0..aaa6bb106 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -106,7 +106,7 @@ namespace vcpkg::Environment static const fs::path& get_VS2015_installation_instance() { - static const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // The call to parent path is needed because the env variable has a trailing backslash + static const fs::path vs2015_cmntools = fs::path(System::wdupenv_str(L"VS140COMNTOOLS")).parent_path(); // The call to parent_path() is needed because the env variable has a trailing backslash static const fs::path vs2015_path = vs2015_cmntools.parent_path().parent_path(); return vs2015_path; } -- cgit v1.2.3 From 64bcc326fb98a7ae8249cc50b6305166e8f3ac89 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 17:49:41 -0800 Subject: Improve format of output error messages --- toolsrc/src/vcpkg_Environment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index aaa6bb106..b6705cc47 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -155,7 +155,7 @@ namespace vcpkg::Environment System::println("The following paths were examined:"); for (const fs::path& path : paths_examined) { - System::println(path.generic_string()); + System::println(" %s", path.generic_string()); } exit(EXIT_FAILURE); } @@ -194,7 +194,7 @@ namespace vcpkg::Environment System::println("The following paths were examined:"); for (const fs::path& path : paths_examined) { - System::println(path.generic_string()); + System::println(" %s",path.generic_string()); } exit(EXIT_FAILURE); } -- cgit v1.2.3 From 2670075bf202529aa23b6c278b589e3c0541076e Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 18:36:22 -0800 Subject: Extract method --- toolsrc/src/vcpkg_Environment.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index b6705cc47..76aa07fb6 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -46,6 +46,13 @@ namespace vcpkg::Environment } } + static std::wstring create_default_install_cmd(const vcpkg_paths& paths, const std::wstring& tool_name) + { + const fs::path script = paths.scripts / "fetchDependency.ps1"; + // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned + return Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency %s", script.native(), tool_name); + } + void ensure_git_on_path(const vcpkg_paths& paths) { const fs::path downloaded_git = paths.downloads / "PortableGit" / "cmd"; @@ -58,9 +65,7 @@ namespace vcpkg::Environment static constexpr std::array git_version = {2,0,0}; static const std::wstring version_check_cmd = L"git --version 2>&1"; - const fs::path script = paths.scripts / "fetchDependency.ps1"; - // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency git", script.native()); + const std::wstring install_cmd = create_default_install_cmd(paths, L"git"); ensure_on_path(git_version, version_check_cmd, install_cmd); } @@ -76,9 +81,7 @@ namespace vcpkg::Environment static constexpr std::array cmake_version = {3,7,2}; static const std::wstring version_check_cmd = L"cmake --version 2>&1"; - const fs::path script = paths.scripts / "fetchDependency.ps1"; - // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency cmake", script.native()); + const std::wstring install_cmd = create_default_install_cmd(paths, L"cmake"); ensure_on_path(cmake_version, version_check_cmd, install_cmd); } @@ -89,9 +92,7 @@ namespace vcpkg::Environment static constexpr std::array nuget_version = {1,0,0}; static const std::wstring version_check_cmd = L"nuget 2>&1"; - const fs::path script = paths.scripts / "fetchDependency.ps1"; - // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned - const std::wstring install_cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s -Dependency nuget", script.native()); + const std::wstring install_cmd = create_default_install_cmd(paths, L"nuget"); ensure_on_path(nuget_version, version_check_cmd, install_cmd); } -- cgit v1.2.3 From 868a7623addee16f19b17718163b7719c4d739e2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 18:42:34 -0800 Subject: Bump nuget.exe version --- toolsrc/src/vcpkg_Environment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 76aa07fb6..1a50a604a 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -90,7 +90,7 @@ namespace vcpkg::Environment const std::wstring path_buf = Strings::wformat(L"%s;%s", paths.downloads.native(), System::wdupenv_str(L"PATH")); _wputenv_s(L"PATH", path_buf.c_str()); - static constexpr std::array nuget_version = {1,0,0}; + static constexpr std::array nuget_version = {3,3,0}; static const std::wstring version_check_cmd = L"nuget 2>&1"; const std::wstring install_cmd = create_default_install_cmd(paths, L"nuget"); ensure_on_path(nuget_version, version_check_cmd, install_cmd); -- cgit v1.2.3 From 93c3c0648a782b1fa75bae1f200beca6ba871f9a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 23 Jan 2017 19:25:47 -0800 Subject: [VS2017] Enable building with v141 toolset --- toolsrc/src/commands_build.cpp | 7 ++++--- toolsrc/src/vcpkg_Environment.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index af1b3dc24..d9d5d2107 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -30,12 +30,13 @@ namespace vcpkg::Commands::Build const triplet& target_triplet = spec.target_triplet(); const fs::path ports_cmake_script_path = paths.ports_cmake; - const fs::path vcvarsall_bat = Environment::get_vcvarsall_bat(paths); - const std::wstring command = Strings::wformat(LR"("%s" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", - vcvarsall_bat.native(), + const Environment::vcvarsall_and_platform_toolset vcvarsall_bat = Environment::get_vcvarsall_bat(paths); + const std::wstring command = Strings::wformat(LR"("%s" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s -DVCPKG_PLATFORM_TOOLSET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + vcvarsall_bat.path.native(), Strings::utf8_to_utf16(target_triplet.architecture()), Strings::utf8_to_utf16(source_paragraph.name), Strings::utf8_to_utf16(target_triplet.canonical_name()), + vcvarsall_bat.platform_toolset, port_dir.generic_wstring(), ports_cmake_script_path.generic_wstring()); diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 1a50a604a..c204bfaf4 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -167,7 +167,7 @@ namespace vcpkg::Environment return dumpbin_exe; } - static fs::path find_vcvarsall_bat(const vcpkg_paths& paths) + static vcvarsall_and_platform_toolset find_vcvarsall_bat(const vcpkg_paths& paths) { const std::vector vs2017_installation_instances = get_VS2017_installation_instances(paths); std::vector paths_examined; @@ -179,7 +179,7 @@ namespace vcpkg::Environment paths_examined.push_back(vcvarsall_bat); if (fs::exists(vcvarsall_bat)) { - return vcvarsall_bat; + return { vcvarsall_bat , L"v141"}; } } @@ -188,7 +188,7 @@ namespace vcpkg::Environment paths_examined.push_back(vs2015_vcvarsall_bat); if (fs::exists(vs2015_vcvarsall_bat)) { - return vs2015_vcvarsall_bat; + return { vs2015_vcvarsall_bat, L"v140" }; } System::println(System::color::error, "Could not detect vccarsall.bat."); @@ -200,9 +200,9 @@ namespace vcpkg::Environment exit(EXIT_FAILURE); } - const fs::path& get_vcvarsall_bat(const vcpkg_paths& paths) + const vcvarsall_and_platform_toolset& get_vcvarsall_bat(const vcpkg_paths& paths) { - static const fs::path vcvarsall_bat = find_vcvarsall_bat(paths); + static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(paths); return vcvarsall_bat; } } -- cgit v1.2.3 From d5e7a501e907f06ad1e8bb4ffdebce9a29179d2d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 24 Jan 2017 12:30:14 -0800 Subject: Download nuget.exe in a version-including subfolder in Downloads\ --- toolsrc/src/vcpkg_Environment.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index c204bfaf4..66d33edeb 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -87,7 +87,8 @@ namespace vcpkg::Environment void ensure_nuget_on_path(const vcpkg_paths& paths) { - const std::wstring path_buf = Strings::wformat(L"%s;%s", paths.downloads.native(), System::wdupenv_str(L"PATH")); + const fs::path downloaded_nuget = paths.downloads / "nuget-3.5.0"; + const std::wstring path_buf = Strings::wformat(L"%s;%s", downloaded_nuget.native(), System::wdupenv_str(L"PATH")); _wputenv_s(L"PATH", path_buf.c_str()); static constexpr std::array nuget_version = {3,3,0}; -- cgit v1.2.3 From e3c3497dbc03607492f38e54122106bc8f00ca20 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 24 Jan 2017 14:12:27 -0800 Subject: Suppress VS2017's vcvarsall.bat output --- toolsrc/src/commands_build.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index d9d5d2107..e7e005100 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -31,7 +31,7 @@ namespace vcpkg::Commands::Build const fs::path ports_cmake_script_path = paths.ports_cmake; const Environment::vcvarsall_and_platform_toolset vcvarsall_bat = Environment::get_vcvarsall_bat(paths); - const std::wstring command = Strings::wformat(LR"("%s" %s && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s -DVCPKG_PLATFORM_TOOLSET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", + const std::wstring command = Strings::wformat(LR"("%s" %s >nul 2>&1 && cmake -DCMD=BUILD -DPORT=%s -DTARGET_TRIPLET=%s -DVCPKG_PLATFORM_TOOLSET=%s "-DCURRENT_PORT_DIR=%s/." -P "%s")", vcvarsall_bat.path.native(), Strings::utf8_to_utf16(target_triplet.architecture()), Strings::utf8_to_utf16(source_paragraph.name), -- cgit v1.2.3 From 7fe735c02e37057596396d42b17caef3169415b0 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 24 Jan 2017 18:00:43 -0800 Subject: Add error message when CONTROL file cannot be opened --- toolsrc/src/Paragraphs.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index d99ad45cf..f4592afed 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -41,8 +41,8 @@ namespace vcpkg::Paragraphs static bool is_alphanum(char ch) { return (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z') - || (ch >= '0' && ch <= '9'); + || (ch >= 'a' && ch <= 'z') + || (ch >= '0' && ch <= '9'); } static bool is_lineend(char ch) @@ -153,7 +153,13 @@ namespace vcpkg::Paragraphs std::vector> get_paragraphs(const fs::path& control_path) { - return parse_paragraphs(Files::read_contents(control_path).get_or_throw()); + const expected contents = Files::read_contents(control_path); + if (auto spgh = contents.get()) + { + return parse_paragraphs(*spgh); + } + + Checks::exit_with_message("Error while reading %s: %s", control_path.generic_string(), contents.error_code().message()); } std::vector> parse_paragraphs(const std::string& str) -- cgit v1.2.3 From 9b8afccc9db0959cb3a47d77fd0255096011e245 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 24 Jan 2017 19:08:51 -0800 Subject: Properly convert wchar to char before printing --- toolsrc/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 08e65391f..b78319167 100644 --- a/toolsrc/src/main.cpp +++ b/toolsrc/src/main.cpp @@ -13,6 +13,7 @@ #include "vcpkg_Input.h" #include "Paragraphs.h" #include "vcpkg_info.h" +#include "vcpkg_Strings.h" using namespace vcpkg; @@ -242,7 +243,7 @@ int wmain(const int argc, const wchar_t* const* const argv) << "EXCEPTION='" << exc_msg << "'\n" << "CMD=\n"; for (int x = 0; x < argc; ++x) - std::cerr << argv[x] << "|\n"; + std::cerr << Strings::utf16_to_utf8(argv[x]) << "|\n"; std::cerr << "\n"; } -- cgit v1.2.3 From 73f4c47d761e51cdc0682df88dead76b407f1058 Mon Sep 17 00:00:00 2001 From: Olaf van der Spek Date: Wed, 25 Jan 2017 19:09:01 +0100 Subject: Update commands_update.cpp --- toolsrc/src/commands_update.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 12b4dad50..021bfe705 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -84,7 +84,7 @@ 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 scripts\\bootstrap.ps1 to update.", + System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use powershell -exec bypass scripts/bootstrap.ps1 to update.", maj2, min2, rev2, maj1, min1, rev1); } -- cgit v1.2.3 From 3d1b72ea05bd4065a3cc5eb57cac1d9277451d0f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 25 Jan 2017 14:20:17 -0800 Subject: Move MachineType.cpp to src\ --- toolsrc/src/MachineType.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 toolsrc/src/MachineType.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/MachineType.cpp b/toolsrc/src/MachineType.cpp new file mode 100644 index 000000000..0115f3e5e --- /dev/null +++ b/toolsrc/src/MachineType.cpp @@ -0,0 +1,41 @@ +#include "MachineType.h" +#include "vcpkg_Checks.h" + +namespace vcpkg +{ + MachineType getMachineType(const uint16_t value) + { + MachineType t = static_cast(value); + switch (t) + { + case MachineType::UNKNOWN: + case MachineType::AM33: + case MachineType::AMD64: + case MachineType::ARM: + case MachineType::ARM64: + case MachineType::ARMNT: + case MachineType::EBC: + case MachineType::I386: + case MachineType::IA64: + case MachineType::M32R: + case MachineType::MIPS16: + case MachineType::MIPSFPU: + case MachineType::MIPSFPU16: + case MachineType::POWERPC: + case MachineType::POWERPCFP: + case MachineType::R4000: + case MachineType::RISCV32: + case MachineType::RISCV64: + case MachineType::RISCV128: + case MachineType::SH3: + case MachineType::SH3DSP: + case MachineType::SH4: + case MachineType::SH5: + case MachineType::THUMB: + case MachineType::WCEMIPSV2: + return t; + default: + Checks::exit_with_message("Unknown machine type code 0x%x", value); + } + } +} -- cgit v1.2.3 From 25872147c1016fea74aac5627880fb7d40c0c1f7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 25 Jan 2017 16:44:56 -0800 Subject: Add quotes are port name in error message --- toolsrc/src/commands_edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index 3297b5295..cb457a9e2 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -11,7 +11,7 @@ namespace vcpkg::Commands::Edit const std::string port_name = args.command_arguments.at(0); const fs::path portpath = paths.ports / port_name; - Checks::check_exit(fs::is_directory(portpath), "Could not find port named %s", port_name); + Checks::check_exit(fs::is_directory(portpath), R"(Could not find port named "%s")", port_name); // Find editor std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR"); -- cgit v1.2.3 From 59be40a100910d1f833cd54762e624b7123965ed Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 25 Jan 2017 19:32:50 -0800 Subject: Rename vcpkg.h/cpp to vcpkglib.h/cpp --- toolsrc/src/commands_build.cpp | 2 +- toolsrc/src/commands_build_external.cpp | 2 +- toolsrc/src/commands_install.cpp | 2 +- toolsrc/src/commands_list.cpp | 2 +- toolsrc/src/commands_owns.cpp | 2 +- toolsrc/src/commands_remove.cpp | 2 +- toolsrc/src/commands_update.cpp | 2 +- toolsrc/src/vcpkg.cpp | 248 -------------------------------- toolsrc/src/vcpkg_Dependencies.cpp | 2 +- toolsrc/src/vcpkglib.cpp | 248 ++++++++++++++++++++++++++++++++ 10 files changed, 256 insertions(+), 256 deletions(-) delete mode 100644 toolsrc/src/vcpkg.cpp create mode 100644 toolsrc/src/vcpkglib.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index e7e005100..629cbbb5f 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -1,6 +1,6 @@ #include "vcpkg_Commands.h" #include "StatusParagraphs.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_Input.h" #include "post_build_lint.h" #include "vcpkg_Dependencies.h" diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index 09a9256d7..51dc29e86 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -2,7 +2,7 @@ #include "vcpkg_System.h" #include "vcpkg_Environment.h" #include "vcpkg_Input.h" -#include "vcpkg.h" +#include "vcpkglib.h" namespace vcpkg::Commands::BuildExternal { diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index ff517d9b1..6fc0e32f0 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -1,5 +1,5 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_Environment.h" #include "metrics.h" #include "vcpkg_Files.h" diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index d9c4a52f2..18e95d405 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -1,5 +1,5 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_System.h" #include "vcpkglib_helpers.h" diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index bb1a7eb9f..fe02b6224 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -1,6 +1,6 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg.h" +#include "vcpkglib.h" namespace vcpkg::Commands::Owns { diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 23d981fc1..4b53f4778 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -1,5 +1,5 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" #include diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index 021bfe705..d7a554303 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -1,5 +1,5 @@ #include "vcpkg_Commands.h" -#include "vcpkg.h" +#include "vcpkglib.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" #include "Paragraphs.h" diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp deleted file mode 100644 index eb2184ccb..000000000 --- a/toolsrc/src/vcpkg.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include "vcpkg.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "vcpkg_Files.h" -#include "Paragraphs.h" -#include -#include "metrics.h" - -using namespace vcpkg; - -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)) - { - if (!fs::exists(vcpkg_dir_status_file_old)) - { - // no status file, use empty db - return StatusParagraphs(); - } - - fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); - } - - auto text = Files::read_contents(vcpkg_dir_status_file).get_or_throw(); - auto pghs = Paragraphs::parse_paragraphs(text); - - std::vector> status_pghs; - for (auto&& p : pghs) - { - status_pghs.push_back(std::make_unique(p)); - } - - return StatusParagraphs(std::move(status_pghs)); -} - -StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) -{ - auto updates_dir = paths.vcpkg_dir_updates; - - std::error_code ec; - fs::create_directory(paths.installed, ec); - fs::create_directory(paths.vcpkg_dir, ec); - fs::create_directory(paths.vcpkg_dir_info, ec); - fs::create_directory(updates_dir, ec); - - const fs::path& status_file = paths.vcpkg_dir_status_file; - const fs::path status_file_old = status_file.parent_path() / "status-old"; - const fs::path status_file_new = status_file.parent_path() / "status-new"; - - StatusParagraphs current_status_db = load_current_database(status_file, status_file_old); - - auto b = fs::directory_iterator(updates_dir); - auto e = fs::directory_iterator(); - if (b == e) - { - // updates directory is empty, control file is up-to-date. - return current_status_db; - } - - for (; b != e; ++b) - { - if (!fs::is_regular_file(b->status())) - continue; - if (b->path().filename() == "incomplete") - continue; - - auto text = Files::read_contents(b->path()).get_or_throw(); - auto pghs = Paragraphs::parse_paragraphs(text); - for (auto&& p : pghs) - { - current_status_db.insert(std::make_unique(p)); - } - } - - std::fstream(status_file_new, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc) << current_status_db; - - if (fs::exists(status_file_old)) - fs::remove(status_file_old); - if (fs::exists(status_file)) - fs::rename(status_file, status_file_old); - fs::rename(status_file_new, status_file); - fs::remove(status_file_old); - - b = fs::directory_iterator(updates_dir); - for (; b != e; ++b) - { - if (!fs::is_regular_file(b->status())) - continue; - fs::remove(b->path()); - } - - return current_status_db; -} - -void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) -{ - static int update_id = 0; - auto my_update_id = update_id++; - auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete"; - auto update_filename = paths.vcpkg_dir_updates / std::to_string(my_update_id); - std::fstream fs(tmp_update_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); - fs << p; - fs.close(); - fs::rename(tmp_update_filename, update_filename); -} - -static void upgrade_to_slash_terminated_sorted_format(std::vector* lines, const fs::path& listfile_path) -{ - static bool was_tracked = false; - - if (lines->empty()) - { - return; - } - - if (lines->at(0).back() == '/') - { - return; // File already in the new format - } - - if (!was_tracked) - { - was_tracked = true; - TrackProperty("listfile", "update to new format"); - } - - // The files are sorted such that directories are placed just before the files they contain - // (They are not necessarily sorted alphabetically, e.g. libflac) - // Therefore we can detect the entries that represent directories by comparing every element with the next one - // and checking if the next has a slash immediately after the current one's length - for (size_t i = 0; i < lines->size() - 1; i++) - { - std::string& current_string = lines->at(i); - const std::string& next_string = lines->at(i + 1); - - const size_t potential_slash_char_index = current_string.length(); - // Make sure the index exists first - if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') - { - current_string += '/'; // Mark as a directory - } - } - - // After suffixing the directories with a slash, we can now sort. - // We cannot sort before adding the suffixes because the following (actual example): - /* - x86-windows/include/FLAC <<<<<< This would be separated from its group due to sorting - x86-windows/include/FLAC/all.h - x86-windows/include/FLAC/assert.h - x86-windows/include/FLAC/callback.h - x86-windows/include/FLAC++ - x86-windows/include/FLAC++/all.h - x86-windows/include/FLAC++/decoder.h - x86-windows/include/FLAC++/encoder.h - * - x86-windows/include/FLAC/ <<<<<< This will now be kept with its group when sorting - x86-windows/include/FLAC/all.h - x86-windows/include/FLAC/assert.h - x86-windows/include/FLAC/callback.h - x86-windows/include/FLAC++/ - x86-windows/include/FLAC++/all.h - x86-windows/include/FLAC++/decoder.h - x86-windows/include/FLAC++/encoder.h - */ - // Note that after sorting, the FLAC++/ group will be placed before the FLAC/ group - // The new format is lexicographically sorted - std::sort(lines->begin(), lines->end()); - -#if 0 - // Replace the listfile on disk - const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated"; - Files::write_all_lines(updated_listfile_path, *lines); - fs::rename(updated_listfile_path, listfile_path); -#endif -} - -std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) -{ - std::vector installed_files; - - for (const std::unique_ptr& pgh : status_db) - { - if (pgh->state != install_state_t::installed) - { - continue; - } - - const fs::path listfile_path = paths.listfile_path(pgh->package); - std::vector installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(); - Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); - upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); - - // Remove the directories - installed_files_of_current_pgh.erase( - std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) -> bool - { - return file.back() == '/'; - } - ), installed_files_of_current_pgh.end()); - - StatusParagraph_and_associated_files pgh_and_files = {*pgh, ImmutableSortedVector::create(std::move(installed_files_of_current_pgh))}; - installed_files.push_back(std::move(pgh_and_files)); - } - - return installed_files; -} - -expected vcpkg::try_load_port(const fs::path& path) -{ - try - { - auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); - return SourceParagraph(pghs[0]); - } - catch (std::runtime_error const&) - { - } - - return std::errc::no_such_file_or_directory; -} - -expected vcpkg::try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec) -{ - const fs::path path = paths.package_dir(spec) / "CONTROL"; - - auto control_contents_maybe = Files::read_contents(path); - if (auto control_contents = control_contents_maybe.get()) - { - std::vector> pghs; - try - { - pghs = Paragraphs::parse_paragraphs(*control_contents); - } - catch (std::runtime_error) - { - } - Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", path.string()); - return BinaryParagraph(pghs[0]); - } - return control_contents_maybe.error_code(); -} diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index f1464a605..1daa6de02 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -7,7 +7,7 @@ #include #include "vcpkg_Maps.h" #include "vcpkg_Files.h" -#include "vcpkg.h" +#include "vcpkglib.h" namespace vcpkg::Dependencies { diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp new file mode 100644 index 000000000..5cea0c585 --- /dev/null +++ b/toolsrc/src/vcpkglib.cpp @@ -0,0 +1,248 @@ +#include "vcpkglib.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "vcpkg_Files.h" +#include "Paragraphs.h" +#include +#include "metrics.h" + +using namespace vcpkg; + +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)) + { + if (!fs::exists(vcpkg_dir_status_file_old)) + { + // no status file, use empty db + return StatusParagraphs(); + } + + fs::rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); + } + + auto text = Files::read_contents(vcpkg_dir_status_file).get_or_throw(); + auto pghs = Paragraphs::parse_paragraphs(text); + + std::vector> status_pghs; + for (auto&& p : pghs) + { + status_pghs.push_back(std::make_unique(p)); + } + + return StatusParagraphs(std::move(status_pghs)); +} + +StatusParagraphs vcpkg::database_load_check(const vcpkg_paths& paths) +{ + auto updates_dir = paths.vcpkg_dir_updates; + + std::error_code ec; + fs::create_directory(paths.installed, ec); + fs::create_directory(paths.vcpkg_dir, ec); + fs::create_directory(paths.vcpkg_dir_info, ec); + fs::create_directory(updates_dir, ec); + + const fs::path& status_file = paths.vcpkg_dir_status_file; + const fs::path status_file_old = status_file.parent_path() / "status-old"; + const fs::path status_file_new = status_file.parent_path() / "status-new"; + + StatusParagraphs current_status_db = load_current_database(status_file, status_file_old); + + auto b = fs::directory_iterator(updates_dir); + auto e = fs::directory_iterator(); + if (b == e) + { + // updates directory is empty, control file is up-to-date. + return current_status_db; + } + + for (; b != e; ++b) + { + if (!fs::is_regular_file(b->status())) + continue; + if (b->path().filename() == "incomplete") + continue; + + auto text = Files::read_contents(b->path()).get_or_throw(); + auto pghs = Paragraphs::parse_paragraphs(text); + for (auto&& p : pghs) + { + current_status_db.insert(std::make_unique(p)); + } + } + + std::fstream(status_file_new, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc) << current_status_db; + + if (fs::exists(status_file_old)) + fs::remove(status_file_old); + if (fs::exists(status_file)) + fs::rename(status_file, status_file_old); + fs::rename(status_file_new, status_file); + fs::remove(status_file_old); + + b = fs::directory_iterator(updates_dir); + for (; b != e; ++b) + { + if (!fs::is_regular_file(b->status())) + continue; + fs::remove(b->path()); + } + + return current_status_db; +} + +void vcpkg::write_update(const vcpkg_paths& paths, const StatusParagraph& p) +{ + static int update_id = 0; + auto my_update_id = update_id++; + auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete"; + auto update_filename = paths.vcpkg_dir_updates / std::to_string(my_update_id); + std::fstream fs(tmp_update_filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + fs << p; + fs.close(); + fs::rename(tmp_update_filename, update_filename); +} + +static void upgrade_to_slash_terminated_sorted_format(std::vector* lines, const fs::path& listfile_path) +{ + static bool was_tracked = false; + + if (lines->empty()) + { + return; + } + + if (lines->at(0).back() == '/') + { + return; // File already in the new format + } + + if (!was_tracked) + { + was_tracked = true; + TrackProperty("listfile", "update to new format"); + } + + // The files are sorted such that directories are placed just before the files they contain + // (They are not necessarily sorted alphabetically, e.g. libflac) + // Therefore we can detect the entries that represent directories by comparing every element with the next one + // and checking if the next has a slash immediately after the current one's length + for (size_t i = 0; i < lines->size() - 1; i++) + { + std::string& current_string = lines->at(i); + const std::string& next_string = lines->at(i + 1); + + const size_t potential_slash_char_index = current_string.length(); + // Make sure the index exists first + if (next_string.size() > potential_slash_char_index && next_string.at(potential_slash_char_index) == '/') + { + current_string += '/'; // Mark as a directory + } + } + + // After suffixing the directories with a slash, we can now sort. + // We cannot sort before adding the suffixes because the following (actual example): + /* + x86-windows/include/FLAC <<<<<< This would be separated from its group due to sorting + x86-windows/include/FLAC/all.h + x86-windows/include/FLAC/assert.h + x86-windows/include/FLAC/callback.h + x86-windows/include/FLAC++ + x86-windows/include/FLAC++/all.h + x86-windows/include/FLAC++/decoder.h + x86-windows/include/FLAC++/encoder.h + * + x86-windows/include/FLAC/ <<<<<< This will now be kept with its group when sorting + x86-windows/include/FLAC/all.h + x86-windows/include/FLAC/assert.h + x86-windows/include/FLAC/callback.h + x86-windows/include/FLAC++/ + x86-windows/include/FLAC++/all.h + x86-windows/include/FLAC++/decoder.h + x86-windows/include/FLAC++/encoder.h + */ + // Note that after sorting, the FLAC++/ group will be placed before the FLAC/ group + // The new format is lexicographically sorted + std::sort(lines->begin(), lines->end()); + +#if 0 + // Replace the listfile on disk + const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated"; + Files::write_all_lines(updated_listfile_path, *lines); + fs::rename(updated_listfile_path, listfile_path); +#endif +} + +std::vector vcpkg::get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db) +{ + std::vector installed_files; + + for (const std::unique_ptr& pgh : status_db) + { + if (pgh->state != install_state_t::installed) + { + continue; + } + + const fs::path listfile_path = paths.listfile_path(pgh->package); + std::vector installed_files_of_current_pgh = Files::read_all_lines(listfile_path).get_or_throw(); + Strings::trim_all_and_remove_whitespace_strings(&installed_files_of_current_pgh); + upgrade_to_slash_terminated_sorted_format(&installed_files_of_current_pgh, listfile_path); + + // Remove the directories + installed_files_of_current_pgh.erase( + std::remove_if(installed_files_of_current_pgh.begin(), installed_files_of_current_pgh.end(), [](const std::string& file) -> bool + { + return file.back() == '/'; + } + ), installed_files_of_current_pgh.end()); + + StatusParagraph_and_associated_files pgh_and_files = {*pgh, ImmutableSortedVector::create(std::move(installed_files_of_current_pgh))}; + installed_files.push_back(std::move(pgh_and_files)); + } + + return installed_files; +} + +expected vcpkg::try_load_port(const fs::path& path) +{ + try + { + auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s\\CONTROL", path.string()); + return SourceParagraph(pghs[0]); + } + catch (std::runtime_error const&) + { + } + + return std::errc::no_such_file_or_directory; +} + +expected vcpkg::try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec) +{ + const fs::path path = paths.package_dir(spec) / "CONTROL"; + + auto control_contents_maybe = Files::read_contents(path); + if (auto control_contents = control_contents_maybe.get()) + { + std::vector> pghs; + try + { + pghs = Paragraphs::parse_paragraphs(*control_contents); + } + catch (std::runtime_error) + { + } + Checks::check_exit(pghs.size() == 1, "Invalid control file at %s", path.string()); + return BinaryParagraph(pghs[0]); + } + return control_contents_maybe.error_code(); +} -- cgit v1.2.3 From 31ddf1a80393d825925cf45b4573710423d14233 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 25 Jan 2017 19:34:25 -0800 Subject: Rename main.cpp to vcpkg.cpp --- toolsrc/src/main.cpp | 249 -------------------------------------------------- toolsrc/src/vcpkg.cpp | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+), 249 deletions(-) delete mode 100644 toolsrc/src/main.cpp create mode 100644 toolsrc/src/vcpkg.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp deleted file mode 100644 index b78319167..000000000 --- a/toolsrc/src/main.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include - -#include -#include -#include -#include -#include "vcpkg_Commands.h" -#include "metrics.h" -#include -#include "vcpkg_Files.h" -#include "vcpkg_System.h" -#include "vcpkg_Input.h" -#include "Paragraphs.h" -#include "vcpkg_info.h" -#include "vcpkg_Strings.h" - -using namespace vcpkg; - -bool g_debugging = false; - -void invalid_command(const std::string& cmd) -{ - System::println(System::color::error, "invalid command: %s", cmd); - Commands::Help::print_usage(); - exit(EXIT_FAILURE); -} - -static void inner(const vcpkg_cmd_arguments& args) -{ - TrackProperty("command", args.command); - if (args.command.empty()) - { - Commands::Help::print_usage(); - exit(EXIT_FAILURE); - } - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c())) - { - return command_function(args); - } - - fs::path vcpkg_root_dir; - if (args.vcpkg_root_dir != nullptr) - { - vcpkg_root_dir = fs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir)); - } - else - { - auto vcpkg_root_dir_env = System::wdupenv_str(L"VCPKG_ROOT"); - - if (!vcpkg_root_dir_env.empty()) - { - vcpkg_root_dir = fs::absolute(vcpkg_root_dir_env); - } - else - { - vcpkg_root_dir = Files::find_file_recursively_up(fs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root"); - } - } - - Checks::check_exit(!vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); - - const expected expected_paths = vcpkg_paths::create(vcpkg_root_dir); - Checks::check_exit(!expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message()); - const vcpkg_paths paths = expected_paths.get_or_throw(); - int exit_code = _wchdir(paths.root.c_str()); - Checks::check_exit(exit_code == 0, "Changing the working dir failed"); - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) - { - return command_function(args, paths); - } - - triplet default_target_triplet; - if (args.target_triplet != nullptr) - { - default_target_triplet = triplet::from_canonical_name(*args.target_triplet); - } - else - { - const auto vcpkg_default_triplet_env = System::wdupenv_str(L"VCPKG_DEFAULT_TRIPLET"); - if (!vcpkg_default_triplet_env.empty()) - { - default_target_triplet = triplet::from_canonical_name(Strings::utf16_to_utf8(vcpkg_default_triplet_env)); - } - else - { - default_target_triplet = triplet::X86_WINDOWS; - } - } - - Input::check_triplet(default_target_triplet, paths); - - if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a())) - { - return command_function(args, paths, default_target_triplet); - } - - return invalid_command(args.command); -} - -static void loadConfig() -{ - fs::path localappdata; - { - // Config path in AppDataLocal - wchar_t* localappdatapath = nullptr; - if (S_OK != SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localappdatapath)) - __fastfail(1); - localappdata = localappdatapath; - CoTaskMemFree(localappdatapath); - } - - try - { - std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); - - std::unordered_map keys; - auto pghs = Paragraphs::parse_paragraphs(config_contents); - if (pghs.size() > 0) - keys = pghs[0]; - - for (size_t x = 1; x < pghs.size(); ++x) - { - for (auto&& p : pghs[x]) - keys.insert(p); - } - - auto user_id = keys["User-Id"]; - auto user_time = keys["User-Since"]; - Checks::check_throw(!user_id.empty() && !user_time.empty(), ""); // Use as goto to the catch statement - - SetUserInformation(user_id, user_time); - return; - } - catch (...) - { - } - - // config file not found, could not be read, or invalid - std::string user_id, user_time; - InitUserInformation(user_id, user_time); - SetUserInformation(user_id, user_time); - try - { - std::error_code ec; - fs::create_directory(localappdata / "vcpkg", ec); - std::ofstream(localappdata / "vcpkg" / "config", std::ios_base::out | std::ios_base::trunc) - << "User-Id: " << user_id << "\n" - << "User-Since: " << user_time << "\n"; - } - catch (...) - { - } -} - -static System::Stopwatch2 g_timer; - -static std::string trim_path_from_command_line(const std::string& full_command_line) -{ - Checks::check_exit(full_command_line.size() > 0, "Internal failure - cannot have empty command line"); - - if (full_command_line[0] == '"') - { - auto it = std::find(full_command_line.cbegin() + 1, full_command_line.cend(), '"'); - if (it != full_command_line.cend()) // Skip over the quote - ++it; - while (it != full_command_line.cend() && *it == ' ') // Skip over a space - ++it; - return std::string(it, full_command_line.cend()); - } - - auto it = std::find(full_command_line.cbegin(), full_command_line.cend(), ' '); - while (it != full_command_line.cend() && *it == ' ') - ++it; - return std::string(it, full_command_line.cend()); -} - -int wmain(const int argc, const wchar_t* const* const argv) -{ - if (argc == 0) - std::abort(); - - std::cout.sync_with_stdio(false); - std::cout.imbue(std::locale::classic()); - - g_timer.start(); - atexit([]() - { - g_timer.stop(); - TrackMetric("elapsed_us", g_timer.microseconds()); - Flush(); - }); - - TrackProperty("version", Info::version()); - - const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); - TrackProperty("cmdline", trimmed_command_line); - loadConfig(); - TrackProperty("sqmuser", GetSQMUser()); - - const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); - - if (args.printmetrics != opt_bool::unspecified) - SetPrintMetrics(args.printmetrics == opt_bool::enabled); - if (args.sendmetrics != opt_bool::unspecified) - SetSendMetrics(args.sendmetrics == opt_bool::enabled); - - if (args.debug != opt_bool::unspecified) - { - g_debugging = (args.debug == opt_bool::enabled); - } - - if (g_debugging) - { - inner(args); - exit(EXIT_FAILURE); - } - - std::string exc_msg; - try - { - inner(args); - exit(EXIT_FAILURE); - } - catch (std::exception& e) - { - exc_msg = e.what(); - } - catch (...) - { - exc_msg = "unknown error(...)"; - } - TrackProperty("error", exc_msg); - std::cerr - << "vcpkg.exe has crashed.\n" - << "Please send an email to:\n" - << " " << Info::email() << "\n" - << "containing a brief summary of what you were trying to do and the following data blob:\n" - << "\n" - << "Version=" << Info::version() << "\n" - << "EXCEPTION='" << exc_msg << "'\n" - << "CMD=\n"; - for (int x = 0; x < argc; ++x) - std::cerr << Strings::utf16_to_utf8(argv[x]) << "|\n"; - std::cerr - << "\n"; -} diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp new file mode 100644 index 000000000..b78319167 --- /dev/null +++ b/toolsrc/src/vcpkg.cpp @@ -0,0 +1,249 @@ +#define WIN32_LEAN_AND_MEAN +#include + +#include +#include +#include +#include +#include "vcpkg_Commands.h" +#include "metrics.h" +#include +#include "vcpkg_Files.h" +#include "vcpkg_System.h" +#include "vcpkg_Input.h" +#include "Paragraphs.h" +#include "vcpkg_info.h" +#include "vcpkg_Strings.h" + +using namespace vcpkg; + +bool g_debugging = false; + +void invalid_command(const std::string& cmd) +{ + System::println(System::color::error, "invalid command: %s", cmd); + Commands::Help::print_usage(); + exit(EXIT_FAILURE); +} + +static void inner(const vcpkg_cmd_arguments& args) +{ + TrackProperty("command", args.command); + if (args.command.empty()) + { + Commands::Help::print_usage(); + exit(EXIT_FAILURE); + } + + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_c())) + { + return command_function(args); + } + + fs::path vcpkg_root_dir; + if (args.vcpkg_root_dir != nullptr) + { + vcpkg_root_dir = fs::absolute(Strings::utf8_to_utf16(*args.vcpkg_root_dir)); + } + else + { + auto vcpkg_root_dir_env = System::wdupenv_str(L"VCPKG_ROOT"); + + if (!vcpkg_root_dir_env.empty()) + { + vcpkg_root_dir = fs::absolute(vcpkg_root_dir_env); + } + else + { + vcpkg_root_dir = Files::find_file_recursively_up(fs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root"); + } + } + + Checks::check_exit(!vcpkg_root_dir.empty(), "Error: Could not detect vcpkg-root."); + + const expected expected_paths = vcpkg_paths::create(vcpkg_root_dir); + Checks::check_exit(!expected_paths.error_code(), "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error_code().message()); + const vcpkg_paths paths = expected_paths.get_or_throw(); + int exit_code = _wchdir(paths.root.c_str()); + Checks::check_exit(exit_code == 0, "Changing the working dir failed"); + + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b())) + { + return command_function(args, paths); + } + + triplet default_target_triplet; + if (args.target_triplet != nullptr) + { + default_target_triplet = triplet::from_canonical_name(*args.target_triplet); + } + else + { + const auto vcpkg_default_triplet_env = System::wdupenv_str(L"VCPKG_DEFAULT_TRIPLET"); + if (!vcpkg_default_triplet_env.empty()) + { + default_target_triplet = triplet::from_canonical_name(Strings::utf16_to_utf8(vcpkg_default_triplet_env)); + } + else + { + default_target_triplet = triplet::X86_WINDOWS; + } + } + + Input::check_triplet(default_target_triplet, paths); + + if (auto command_function = Commands::find(args.command, Commands::get_available_commands_type_a())) + { + return command_function(args, paths, default_target_triplet); + } + + return invalid_command(args.command); +} + +static void loadConfig() +{ + fs::path localappdata; + { + // Config path in AppDataLocal + wchar_t* localappdatapath = nullptr; + if (S_OK != SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localappdatapath)) + __fastfail(1); + localappdata = localappdatapath; + CoTaskMemFree(localappdatapath); + } + + try + { + std::string config_contents = Files::read_contents(localappdata / "vcpkg" / "config").get_or_throw(); + + std::unordered_map keys; + auto pghs = Paragraphs::parse_paragraphs(config_contents); + if (pghs.size() > 0) + keys = pghs[0]; + + for (size_t x = 1; x < pghs.size(); ++x) + { + for (auto&& p : pghs[x]) + keys.insert(p); + } + + auto user_id = keys["User-Id"]; + auto user_time = keys["User-Since"]; + Checks::check_throw(!user_id.empty() && !user_time.empty(), ""); // Use as goto to the catch statement + + SetUserInformation(user_id, user_time); + return; + } + catch (...) + { + } + + // config file not found, could not be read, or invalid + std::string user_id, user_time; + InitUserInformation(user_id, user_time); + SetUserInformation(user_id, user_time); + try + { + std::error_code ec; + fs::create_directory(localappdata / "vcpkg", ec); + std::ofstream(localappdata / "vcpkg" / "config", std::ios_base::out | std::ios_base::trunc) + << "User-Id: " << user_id << "\n" + << "User-Since: " << user_time << "\n"; + } + catch (...) + { + } +} + +static System::Stopwatch2 g_timer; + +static std::string trim_path_from_command_line(const std::string& full_command_line) +{ + Checks::check_exit(full_command_line.size() > 0, "Internal failure - cannot have empty command line"); + + if (full_command_line[0] == '"') + { + auto it = std::find(full_command_line.cbegin() + 1, full_command_line.cend(), '"'); + if (it != full_command_line.cend()) // Skip over the quote + ++it; + while (it != full_command_line.cend() && *it == ' ') // Skip over a space + ++it; + return std::string(it, full_command_line.cend()); + } + + auto it = std::find(full_command_line.cbegin(), full_command_line.cend(), ' '); + while (it != full_command_line.cend() && *it == ' ') + ++it; + return std::string(it, full_command_line.cend()); +} + +int wmain(const int argc, const wchar_t* const* const argv) +{ + if (argc == 0) + std::abort(); + + std::cout.sync_with_stdio(false); + std::cout.imbue(std::locale::classic()); + + g_timer.start(); + atexit([]() + { + g_timer.stop(); + TrackMetric("elapsed_us", g_timer.microseconds()); + Flush(); + }); + + TrackProperty("version", Info::version()); + + const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW())); + TrackProperty("cmdline", trimmed_command_line); + loadConfig(); + TrackProperty("sqmuser", GetSQMUser()); + + const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); + + if (args.printmetrics != opt_bool::unspecified) + SetPrintMetrics(args.printmetrics == opt_bool::enabled); + if (args.sendmetrics != opt_bool::unspecified) + SetSendMetrics(args.sendmetrics == opt_bool::enabled); + + if (args.debug != opt_bool::unspecified) + { + g_debugging = (args.debug == opt_bool::enabled); + } + + if (g_debugging) + { + inner(args); + exit(EXIT_FAILURE); + } + + std::string exc_msg; + try + { + inner(args); + exit(EXIT_FAILURE); + } + catch (std::exception& e) + { + exc_msg = e.what(); + } + catch (...) + { + exc_msg = "unknown error(...)"; + } + TrackProperty("error", exc_msg); + std::cerr + << "vcpkg.exe has crashed.\n" + << "Please send an email to:\n" + << " " << Info::email() << "\n" + << "containing a brief summary of what you were trying to do and the following data blob:\n" + << "\n" + << "Version=" << Info::version() << "\n" + << "EXCEPTION='" << exc_msg << "'\n" + << "CMD=\n"; + for (int x = 0; x < argc; ++x) + std::cerr << Strings::utf16_to_utf8(argv[x]) << "|\n"; + std::cerr + << "\n"; +} -- cgit v1.2.3 From 4be93bac78aaba43ea562b454dc14ca5a391e570 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 26 Jan 2017 13:08:35 -0800 Subject: [Stopwatch] Specify elapsedNanos = 0 on construction --- toolsrc/src/Stopwatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/Stopwatch.cpp b/toolsrc/src/Stopwatch.cpp index 550f1ebd8..b0e54e381 100644 --- a/toolsrc/src/Stopwatch.cpp +++ b/toolsrc/src/Stopwatch.cpp @@ -88,7 +88,7 @@ namespace vcpkg return Strings::format("%.4g ns", nanos_as_double); } - Stopwatch::Stopwatch() : m_isRunning(false), m_elapsedNanos(), m_startTick() + Stopwatch::Stopwatch() : m_isRunning(false), m_elapsedNanos(0), m_startTick() { } -- cgit v1.2.3 From 5d2f44859248f1ef32d4c79b6b22eec95b18db1a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 13:01:22 -0800 Subject: Use Strings::join() --- toolsrc/src/commands_install.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 6fc0e32f0..a8ddf35f4 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -153,12 +153,7 @@ namespace vcpkg::Commands::Install 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::println(""); - for (const std::string& s : intersection) - { - System::println(" %s", s); - } - System::println(""); + Strings::join(intersection, "\n "); exit(EXIT_FAILURE); } -- cgit v1.2.3 From a26c0288931f7fba284ef9bea5e7cbc655e127ba Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Mon, 30 Jan 2017 19:37:07 -0800 Subject: [vcpkg] Fixup 5d2f4485 --- toolsrc/src/commands_install.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index a8ddf35f4..69495bd62 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -153,7 +153,9 @@ namespace vcpkg::Commands::Install 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); - Strings::join(intersection, "\n "); + System::print("\n "); + System::println(Strings::join(intersection, "\n ")); + System::println(""); exit(EXIT_FAILURE); } -- cgit v1.2.3 From 9502d795bb325669df8e4e3b32f6ca60827813f1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 26 Jan 2017 14:25:36 -0800 Subject: Move & rename remove_plan_type enum --- toolsrc/src/commands_remove.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 4b53f4778..bf415d2c0 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -2,10 +2,13 @@ #include "vcpkglib.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" +#include "vcpkg_Dependencies.h" #include namespace vcpkg::Commands::Remove { + using Dependencies::remove_plan_type; + static const std::string OPTION_PURGE = "--purge"; static void delete_directory(const fs::path& directory) @@ -22,14 +25,7 @@ namespace vcpkg::Commands::Remove } } - enum class deinstall_plan - { - not_installed, - dependencies_not_satisfied, - should_deinstall - }; - - static deinstall_plan deinstall_package_plan( + static remove_plan_type deinstall_package_plan( const StatusParagraphs::iterator package_it, const StatusParagraphs& status_db, std::vector& dependencies_out) @@ -38,7 +34,7 @@ namespace vcpkg::Commands::Remove if (package_it == status_db.end() || (*package_it)->state == install_state_t::not_installed) { - return deinstall_plan::not_installed; + return remove_plan_type::NOT_INSTALLED; } auto& pkg = (*package_it)->package; @@ -59,9 +55,9 @@ namespace vcpkg::Commands::Remove } if (!dependencies_out.empty()) - return deinstall_plan::dependencies_not_satisfied; + return remove_plan_type::DEPENDENCIES_NOT_SATISFIED; - return deinstall_plan::should_deinstall; + return remove_plan_type::SHOULD_REMOVE; } static void deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db) @@ -79,17 +75,17 @@ namespace vcpkg::Commands::Remove auto plan = deinstall_package_plan(package_it, status_db, deps); switch (plan) { - case deinstall_plan::not_installed: + case remove_plan_type::NOT_INSTALLED: System::println(System::color::success, "Package %s is not installed", spec); return; - case deinstall_plan::dependencies_not_satisfied: + case remove_plan_type::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: + case remove_plan_type::SHOULD_REMOVE: break; default: Checks::unreachable(); -- cgit v1.2.3 From 33b46b1fee70996a23a7860f853e95ef80ff3978 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 26 Jan 2017 17:53:45 -0800 Subject: Create a remove plan. NOT used yet --- toolsrc/src/commands_remove.cpp | 8 ++++-- toolsrc/src/vcpkg_Dependencies.cpp | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index bf415d2c0..7b8286f9c 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -7,6 +7,7 @@ namespace vcpkg::Commands::Remove { + using Dependencies::package_spec_with_remove_plan; using Dependencies::remove_plan_type; static const std::string OPTION_PURGE = "--purge"; @@ -57,7 +58,7 @@ namespace vcpkg::Commands::Remove if (!dependencies_out.empty()) return remove_plan_type::DEPENDENCIES_NOT_SATISFIED; - return remove_plan_type::SHOULD_REMOVE; + return remove_plan_type::REMOVE; } static void deinstall_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs& status_db) @@ -85,7 +86,7 @@ namespace vcpkg::Commands::Remove System::println(" %s depends on %s", dep->package.displayname(), pkg.package.displayname()); } exit(EXIT_FAILURE); - case remove_plan_type::SHOULD_REMOVE: + case remove_plan_type::REMOVE: break; default: Checks::unreachable(); @@ -174,6 +175,9 @@ namespace vcpkg::Commands::Remove Input::check_triplets(specs, paths); bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); + const std::vector remove_plan = Dependencies::create_remove_plan(paths, specs, status_db); + Checks::check_exit(!remove_plan.empty(), "Remove plan cannot be empty"); + for (const package_spec& spec : specs) { deinstall_package(paths, spec, status_db); diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 1daa6de02..4468930c4 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -5,6 +5,7 @@ #include "package_spec.h" #include "StatusParagraphs.h" #include +#include #include "vcpkg_Maps.h" #include "vcpkg_Files.h" #include "vcpkglib.h" @@ -72,4 +73,61 @@ namespace vcpkg::Dependencies } return ret; } + + std::vector create_remove_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) + { + std::unordered_set specs_as_set(specs.cbegin(), specs.cend()); + + std::unordered_map was_examined; // Examine = we have checked its immediate (non-recursive) dependencies + Graphs::Graph graph; + graph.add_vertices(specs); + + std::vector examine_stack(specs); + while (!examine_stack.empty()) + { + const package_spec spec = examine_stack.back(); + examine_stack.pop_back(); + + if (was_examined.find(spec) != was_examined.end()) + { + continue; + } + + auto it = status_db.find(spec); + if (it == status_db.end() || (*it)->state == install_state_t::not_installed) + { + was_examined.emplace(spec, remove_plan_action{ remove_plan_type::NOT_INSTALLED, nullptr}); + continue; + } + + for (const std::unique_ptr& an_installed_package : status_db) + { + if (an_installed_package->want != want_t::install) + continue; + if (an_installed_package->package.spec.target_triplet() != spec.target_triplet()) + continue; + + const std::vector& deps = an_installed_package->package.depends; + if (std::find(deps.begin(), deps.end(), spec.name()) == deps.end()) + { + continue; + } + + graph.add_edge(spec, an_installed_package.get()->package.spec); + examine_stack.push_back(an_installed_package.get()->package.spec); + } + + const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED: remove_plan_type::REMOVE; + was_examined.emplace(spec, remove_plan_action{ type, std::make_unique(std::move((*it)->package))}); + } + + std::vector ret; + + const std::vector pkgs = graph.find_topological_sort(); + for (const package_spec& pkg : pkgs) + { + ret.push_back({ pkg, std::move(was_examined[pkg]) }); + } + return ret; + } } -- cgit v1.2.3 From 050e4a0f7a8156bd862f95c06ea298ab6697e147 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 12:49:09 -0800 Subject: Introduce precompiled headers --- toolsrc/src/BinaryParagraph.cpp | 1 + toolsrc/src/BuildInfo.cpp | 1 + toolsrc/src/MachineType.cpp | 1 + toolsrc/src/Paragraphs.cpp | 1 + toolsrc/src/SourceParagraph.cpp | 1 + toolsrc/src/StatusParagraph.cpp | 1 + toolsrc/src/StatusParagraphs.cpp | 2 +- toolsrc/src/Stopwatch.cpp | 1 + toolsrc/src/coff_file_reader.cpp | 4 +--- toolsrc/src/commands_available_commands.cpp | 1 + toolsrc/src/commands_build.cpp | 2 +- toolsrc/src/commands_build_external.cpp | 1 + toolsrc/src/commands_cache.cpp | 1 + toolsrc/src/commands_contact.cpp | 1 + toolsrc/src/commands_create.cpp | 1 + toolsrc/src/commands_edit.cpp | 1 + toolsrc/src/commands_hash.cpp | 1 + toolsrc/src/commands_help.cpp | 1 + toolsrc/src/commands_import.cpp | 2 +- toolsrc/src/commands_install.cpp | 1 + toolsrc/src/commands_integrate.cpp | 7 +------ toolsrc/src/commands_list.cpp | 1 + toolsrc/src/commands_owns.cpp | 1 + toolsrc/src/commands_portsdiff.cpp | 6 +----- toolsrc/src/commands_remove.cpp | 2 +- toolsrc/src/commands_search.cpp | 1 + toolsrc/src/commands_update.cpp | 1 + toolsrc/src/commands_version.cpp | 1 + toolsrc/src/metrics.cpp | 12 +----------- toolsrc/src/package_spec.cpp | 2 +- toolsrc/src/package_spec_parse_result.cpp | 4 ++-- toolsrc/src/pch.cpp | 1 + toolsrc/src/post_build_lint.cpp | 3 +-- toolsrc/src/triplet.cpp | 2 +- toolsrc/src/vcpkg_Checks.cpp | 3 +-- toolsrc/src/vcpkg_Dependencies.cpp | 5 +---- toolsrc/src/vcpkg_Environment.cpp | 3 +-- toolsrc/src/vcpkg_Files.cpp | 3 +-- toolsrc/src/vcpkg_Input.cpp | 1 + toolsrc/src/vcpkg_Strings.cpp | 8 +------- toolsrc/src/vcpkg_System.cpp | 4 +--- toolsrc/src/vcpkg_cmd_arguments.cpp | 4 +--- toolsrc/src/vcpkg_info.cpp | 1 + toolsrc/src/vcpkg_paths.cpp | 1 + toolsrc/src/vcpkglib.cpp | 10 +--------- toolsrc/src/vcpkglib_helpers.cpp | 3 +-- 46 files changed, 47 insertions(+), 69 deletions(-) create mode 100644 toolsrc/src/pch.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index ad85a1f8a..eed87eb81 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "BinaryParagraph.h" #include "vcpkglib_helpers.h" #include "vcpkg_Checks.h" diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index a45dc4b72..b401f9d44 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "BuildInfo.h" #include "vcpkg_Checks.h" #include "vcpkglib_helpers.h" diff --git a/toolsrc/src/MachineType.cpp b/toolsrc/src/MachineType.cpp index 0115f3e5e..81012234d 100644 --- a/toolsrc/src/MachineType.cpp +++ b/toolsrc/src/MachineType.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "MachineType.h" #include "vcpkg_Checks.h" diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index f4592afed..6dde5da7c 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Paragraphs.h" #include "vcpkg_Files.h" diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index bdf15a737..eef4a4734 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "SourceParagraph.h" #include "vcpkglib_helpers.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/StatusParagraph.cpp b/toolsrc/src/StatusParagraph.cpp index bf12ae89a..3f07689ca 100644 --- a/toolsrc/src/StatusParagraph.cpp +++ b/toolsrc/src/StatusParagraph.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "StatusParagraph.h" #include "vcpkglib_helpers.h" diff --git a/toolsrc/src/StatusParagraphs.cpp b/toolsrc/src/StatusParagraphs.cpp index 3e23c519a..c2398d2b8 100644 --- a/toolsrc/src/StatusParagraphs.cpp +++ b/toolsrc/src/StatusParagraphs.cpp @@ -1,5 +1,5 @@ +#include "pch.h" #include "StatusParagraphs.h" -#include #include "vcpkg_Checks.h" namespace vcpkg diff --git a/toolsrc/src/Stopwatch.cpp b/toolsrc/src/Stopwatch.cpp index b0e54e381..ec7af60b6 100644 --- a/toolsrc/src/Stopwatch.cpp +++ b/toolsrc/src/Stopwatch.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Stopwatch.h" #include "vcpkg_Checks.h" diff --git a/toolsrc/src/coff_file_reader.cpp b/toolsrc/src/coff_file_reader.cpp index 8ce714bbe..f48f912c1 100644 --- a/toolsrc/src/coff_file_reader.cpp +++ b/toolsrc/src/coff_file_reader.cpp @@ -1,8 +1,6 @@ +#include "pch.h" #include "coff_file_reader.h" -#include #include "vcpkg_Checks.h" -#include -#include using namespace std; diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp index 48239587d..56056218b 100644 --- a/toolsrc/src/commands_available_commands.cpp +++ b/toolsrc/src/commands_available_commands.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" namespace vcpkg::Commands diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 629cbbb5f..22f3af872 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "StatusParagraphs.h" #include "vcpkglib.h" @@ -8,7 +9,6 @@ #include "vcpkg_Environment.h" #include "metrics.h" #include "vcpkg_info.h" -#include namespace vcpkg::Commands::Build { diff --git a/toolsrc/src/commands_build_external.cpp b/toolsrc/src/commands_build_external.cpp index 51dc29e86..5c3fa9857 100644 --- a/toolsrc/src/commands_build_external.cpp +++ b/toolsrc/src/commands_build_external.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Environment.h" diff --git a/toolsrc/src/commands_cache.cpp b/toolsrc/src/commands_cache.cpp index 63bf32260..fa49a647f 100644 --- a/toolsrc/src/commands_cache.cpp +++ b/toolsrc/src/commands_cache.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Files.h" diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp index 3e3ebc2b4..2be468fb8 100644 --- a/toolsrc/src/commands_contact.cpp +++ b/toolsrc/src/commands_contact.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_info.h" diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index d842d3fab..5042ab97b 100644 --- a/toolsrc/src/commands_create.cpp +++ b/toolsrc/src/commands_create.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Environment.h" diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp index cb457a9e2..dff30f7ad 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp index 7048fb0d9..4c0028f53 100644 --- a/toolsrc/src/commands_hash.cpp +++ b/toolsrc/src/commands_hash.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp index e4769752c..6068c22fb 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 14e83e75f..7af2c7185 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -1,8 +1,8 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "Paragraphs.h" #include "StatusParagraph.h" #include "vcpkg_Files.h" -#include namespace vcpkg::Commands::Import { diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 69495bd62..2ae67a497 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkglib.h" #include "vcpkg_Environment.h" diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp index 2bd5027ec..03c51b5a7 100644 --- a/toolsrc/src/commands_integrate.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -1,10 +1,5 @@ -#define WIN32_LEAN_AND_MEAN -#include -#include +#include "pch.h" #include "vcpkg_Commands.h" -#include -#include -#include #include "vcpkg_Environment.h" #include "vcpkg_Checks.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp index 18e95d405..34a9c2fc8 100644 --- a/toolsrc/src/commands_list.cpp +++ b/toolsrc/src/commands_list.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkglib.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp index fe02b6224..6c4c20c44 100644 --- a/toolsrc/src/commands_owns.cpp +++ b/toolsrc/src/commands_owns.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkglib.h" diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 1665d7c47..e75633b3c 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -1,11 +1,7 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include -#include #include "vcpkg_Maps.h" -#include -#include -#include #include "Paragraphs.h" #include "SourceParagraph.h" #include "vcpkg_Environment.h" diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 7b8286f9c..9b37ff11f 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -1,9 +1,9 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkglib.h" #include "vcpkg_System.h" #include "vcpkg_Input.h" #include "vcpkg_Dependencies.h" -#include namespace vcpkg::Commands::Remove { diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp index 3f197b06b..3a3226e4b 100644 --- a/toolsrc/src/commands_search.cpp +++ b/toolsrc/src/commands_search.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "Paragraphs.h" diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index d7a554303..a42ae5341 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkglib.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp index e98251601..a521b2567 100644 --- a/toolsrc/src/commands_version.cpp +++ b/toolsrc/src/commands_version.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_info.h" diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index 1806dad87..263d6eb74 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -1,15 +1,5 @@ +#include "pch.h" #include "metrics.h" -#include -#include -#include -#include -#include -#include -#include -#define WIN32_LEAN_AND_MEAN -#include -#include -#include #include "filesystem_fs.h" #include "vcpkg_Strings.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/package_spec.cpp b/toolsrc/src/package_spec.cpp index 86d4393bd..9ba3bdf79 100644 --- a/toolsrc/src/package_spec.cpp +++ b/toolsrc/src/package_spec.cpp @@ -1,5 +1,5 @@ +#include "pch.h" #include "package_spec.h" -#include namespace vcpkg { diff --git a/toolsrc/src/package_spec_parse_result.cpp b/toolsrc/src/package_spec_parse_result.cpp index dc377f656..892232c2e 100644 --- a/toolsrc/src/package_spec_parse_result.cpp +++ b/toolsrc/src/package_spec_parse_result.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "pch.h" +#include "package_spec.h" #include "package_spec_parse_result.h" namespace vcpkg diff --git a/toolsrc/src/pch.cpp b/toolsrc/src/pch.cpp new file mode 100644 index 000000000..17305716a --- /dev/null +++ b/toolsrc/src/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" \ No newline at end of file diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index af76b7963..daf6f49ee 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -1,12 +1,11 @@ +#include "pch.h" #include "vcpkg_paths.h" #include "package_spec.h" #include "vcpkg_Files.h" -#include #include "vcpkg_System.h" #include "vcpkg_Environment.h" #include "coff_file_reader.h" #include "BuildInfo.h" -#include namespace vcpkg::PostBuildLint { diff --git a/toolsrc/src/triplet.cpp b/toolsrc/src/triplet.cpp index a6816b445..e1302d9ed 100644 --- a/toolsrc/src/triplet.cpp +++ b/toolsrc/src/triplet.cpp @@ -1,6 +1,6 @@ +#include "pch.h" #include "triplet.h" #include "vcpkg_Checks.h" -#include namespace vcpkg { diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index 46b28e55c..5c3fef27a 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/src/vcpkg_Checks.cpp @@ -1,6 +1,5 @@ +#include "pch.h" #include "vcpkg_Checks.h" - -#include #include "vcpkg_System.h" namespace vcpkg::Checks diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 4468930c4..3b6db5bbd 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -1,12 +1,9 @@ +#include "pch.h" #include "vcpkg_Dependencies.h" -#include #include "vcpkg_Graphs.h" #include "vcpkg_paths.h" #include "package_spec.h" #include "StatusParagraphs.h" -#include -#include -#include "vcpkg_Maps.h" #include "vcpkg_Files.h" #include "vcpkglib.h" diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp index 66d33edeb..1babdc547 100644 --- a/toolsrc/src/vcpkg_Environment.cpp +++ b/toolsrc/src/vcpkg_Environment.cpp @@ -1,5 +1,4 @@ -#include -#include +#include "pch.h" #include "vcpkg_Environment.h" #include "vcpkg_Commands.h" #include "metrics.h" diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 1d4faa773..87700238d 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -1,6 +1,5 @@ +#include "pch.h" #include "vcpkg_Files.h" -#include -#include #include "vcpkg_System.h" namespace vcpkg::Files diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index bf7ccd346..5720cadc0 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_Input.h" #include "vcpkg_System.h" #include "metrics.h" diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index b974b0a06..5b6d9967c 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -1,12 +1,6 @@ +#include "pch.h" #include "vcpkg_Strings.h" -#include -#include -#include -#include -#include -#include - namespace vcpkg::Strings::details { // To disambiguate between two overloads diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 405dfd1b8..754a26741 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -1,7 +1,5 @@ +#include "pch.h" #include "vcpkg_System.h" -#include -#include -#include namespace vcpkg::System { diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index aa1c35965..4a06128a4 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -1,8 +1,6 @@ -#define WIN32_LEAN_AND_MEAN -#include +#include "pch.h" #include "vcpkg_cmd_arguments.h" #include "vcpkg_Commands.h" -#include #include "metrics.h" #include "vcpkg_System.h" diff --git a/toolsrc/src/vcpkg_info.cpp b/toolsrc/src/vcpkg_info.cpp index 69bc6a355..f8e214998 100644 --- a/toolsrc/src/vcpkg_info.cpp +++ b/toolsrc/src/vcpkg_info.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "vcpkg_info.h" #include "metrics.h" diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 39e4c8986..8d7060a02 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "expected.h" #include "vcpkg_paths.h" #include "metrics.h" diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index 5cea0c585..06487684c 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/src/vcpkglib.cpp @@ -1,15 +1,7 @@ +#include "pch.h" #include "vcpkglib.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "vcpkg_Files.h" #include "Paragraphs.h" -#include #include "metrics.h" using namespace vcpkg; diff --git a/toolsrc/src/vcpkglib_helpers.cpp b/toolsrc/src/vcpkglib_helpers.cpp index fdc287507..6b96c25cb 100644 --- a/toolsrc/src/vcpkglib_helpers.cpp +++ b/toolsrc/src/vcpkglib_helpers.cpp @@ -1,7 +1,6 @@ +#include "pch.h" #include "vcpkg_Checks.h" #include "vcpkglib_helpers.h" -#include -#include namespace vcpkg::details { -- cgit v1.2.3 From 4059d4a6b9f9467ff5c58594f7304eef7ba79664 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 17:28:00 -0800 Subject: [package_spec] Make toString() a member function --- toolsrc/src/commands_build.cpp | 10 +++++----- toolsrc/src/commands_install.cpp | 4 ++-- toolsrc/src/package_spec.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 22f3af872..b6c3cea03 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -44,20 +44,20 @@ namespace vcpkg::Commands::Build timer.start(); int return_code = System::cmd_execute(command); timer.stop(); - TrackMetric("buildtimeus-" + to_string(spec), timer.microseconds()); + TrackMetric("buildtimeus-" + spec.toString(), timer.microseconds()); if (return_code != 0) { - System::println(System::color::error, "Error: building package %s failed", to_string(spec)); + System::println(System::color::error, "Error: building package %s failed", spec.toString()); System::println("Please ensure sure you're using the latest portfiles with `vcpkg update`, then\n" "submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n" " Package: %s\n" " Vcpkg version: %s\n" "\n" "Additionally, attach any relevant sections from the log files above." - , to_string(spec), Info::version()); + , spec.toString(), Info::version()); TrackProperty("error", "build failed"); - TrackProperty("build_error", to_string(spec)); + TrackProperty("build_error", spec.toString()); exit(EXIT_FAILURE); } @@ -118,7 +118,7 @@ namespace vcpkg::Commands::Build System::println(""); for (const package_spec_with_install_plan& p : unmet_dependencies) { - System::println(" %s", to_string(p.spec)); + System::println(" %s", p.spec.toString()); } System::println(""); exit(EXIT_FAILURE); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 2ae67a497..dabce44f6 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -192,11 +192,11 @@ namespace vcpkg::Commands::Install std::vector install_plan = Dependencies::create_install_plan(paths, specs, status_db); Checks::check_exit(!install_plan.empty(), "Install plan cannot be empty"); - std::string specs_string = to_string(install_plan[0].spec); + std::string specs_string = install_plan[0].spec.toString(); for (size_t i = 1; i < install_plan.size(); ++i) { specs_string.push_back(','); - specs_string.append(to_string(install_plan[i].spec)); + specs_string.append(install_plan[i].spec.toString()); } TrackProperty("installplan", specs_string); Environment::ensure_utilities_on_path(paths); diff --git a/toolsrc/src/package_spec.cpp b/toolsrc/src/package_spec.cpp index 9ba3bdf79..7d8d2681d 100644 --- a/toolsrc/src/package_spec.cpp +++ b/toolsrc/src/package_spec.cpp @@ -55,14 +55,14 @@ namespace vcpkg return Strings::format("%s_%s", this->m_name, this->m_target_triplet); } - std::string to_string(const package_spec& spec) + std::string package_spec::toString() const { - return Strings::format("%s:%s", spec.name(), spec.target_triplet()); + return Strings::format("%s:%s", this->name(), this->target_triplet()); } std::string to_printf_arg(const package_spec& spec) { - return to_string(spec); + return spec.toString(); } bool operator==(const package_spec& left, const package_spec& right) @@ -72,6 +72,6 @@ namespace vcpkg std::ostream& operator<<(std::ostream& os, const package_spec& spec) { - return os << to_string(spec); + return os << spec.toString(); } } -- cgit v1.2.3 From 0f0698dc18ec162666ed92b4ac181e512b439b83 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 20:09:40 -0800 Subject: Introduce Strings::Joiner --- toolsrc/src/SourceParagraph.cpp | 4 ++-- toolsrc/src/vcpkg_Strings.cpp | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index eef4a4734..8bfe8e84d 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -53,8 +53,8 @@ namespace vcpkg const std::vector remaining_fields = Maps::extract_keys(fields); const std::vector& valid_fields = get_list_of_valid_fields(); - const std::string remaining_fields_as_string = Strings::join(remaining_fields, "\n "); - const std::string valid_fields_as_string = Strings::join(valid_fields, "\n "); + const std::string remaining_fields_as_string = Strings::Joiner::on("\n ").join(remaining_fields); + const std::string valid_fields_as_string = Strings::Joiner::on("\n ").join(valid_fields); 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); diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 5b6d9967c..3b9d6a859 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -67,25 +67,38 @@ namespace vcpkg::Strings return output; } - std::string join(const std::vector& v, const std::string& delimiter) + std::string join(const std::vector& v, const std::string& prefix, const std::string& delimiter, const std::string& suffix) { - if (v.empty()) + return join(v, prefix, delimiter, suffix, [](const std::string& i) -> std::string { - return std::string(); - } + return i; + }); + } - std::string output; - size_t size = v.size(); + Joiner Joiner::on(const std::string& delimiter) + { + return Joiner(delimiter); + } - output.append(v.at(0)); + Joiner& Joiner::prefix(const std::string& prefix) + { + this->m_prefix = prefix; + return *this; + } - for (size_t i = 1; i < size; ++i) - { - output.append(delimiter); - output.append(v.at(i)); - } + Joiner& Joiner::suffix(const std::string& suffix) + { + this->m_suffix = suffix; + return *this; + } - return output; + std::string Joiner::join(const std::vector& v) const + { + return Strings::join(v, this->m_prefix, this->m_delimiter, this->m_suffix); + } + + Joiner::Joiner(const std::string& delimiter) : m_prefix(""), m_delimiter(delimiter), m_suffix("") + { } void trim(std::string* s) @@ -119,7 +132,7 @@ namespace vcpkg::Strings std::vector output; size_t i = 0; - for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos)) + for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos)) { output.push_back(s.substr(i, pos - i)); i = ++pos; -- cgit v1.2.3 From c1562f1d17bf48e96f31c2a61092dd7bc8c3d9d2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 20:22:33 -0800 Subject: Print remove plan. Fail if --recursive is not passed and there are dependencies --- toolsrc/src/commands_remove.cpp | 80 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 9b37ff11f..8e6a6c227 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -11,6 +11,7 @@ namespace vcpkg::Commands::Remove using Dependencies::remove_plan_type; static const std::string OPTION_PURGE = "--purge"; + static const std::string OPTION_RECURSIVE = "--recursive"; static void delete_directory(const fs::path& directory) { @@ -163,6 +164,67 @@ namespace vcpkg::Commands::Remove System::println(System::color::success, "Package %s was successfully removed", pkg.package.displayname()); } + static void sort_packages_by_name(std::vector* packages) + { + std::sort(packages->begin(), packages->end(), [](const package_spec_with_remove_plan* left, const package_spec_with_remove_plan* right) -> bool + { + return left->spec.name() < right->spec.name(); + }); + } + + static void print_plan(const std::vector& plan) + { + std::vector not_installed; + std::vector remove; + + for (const package_spec_with_remove_plan& i : plan) + { + if (i.plan.type == remove_plan_type::NOT_INSTALLED) + { + not_installed.push_back(&i); + continue; + } + + if (i.plan.type == remove_plan_type::REMOVE || i.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + { + remove.push_back(&i); + continue; + } + + Checks::unreachable(); + } + + //std::copy_if(plan.cbegin(), plan.cend(), std::back_inserter(not_installed), [](const package_spec_with_remove_plan& i) + // { + // return i.plan.type == remove_plan_type::NOT_INSTALLED; + // }); + + if (!not_installed.empty()) + { + sort_packages_by_name(¬_installed); + System::println("The following packages are not installed, so not removed:\n%s", + Strings::Joiner::on("\n ").prefix(" ").join(not_installed, [](const package_spec_with_remove_plan* p) + { + return p->spec.toString(); + })); + } + + if (!remove.empty()) + { + sort_packages_by_name(&remove); + System::println("The following packages will be removed:\n%s", + Strings::Joiner::on("\n").join(remove, [](const package_spec_with_remove_plan* p) + { + if (p->plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + { + return " " + p->spec.toString(); + } + + return " * " + p->spec.toString(); + })); + } + } + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) { static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); @@ -173,11 +235,27 @@ namespace vcpkg::Commands::Remove std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); Input::check_triplets(specs, paths); - bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); + const bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); + const bool isRecursive = options.find(OPTION_PURGE) != options.end(); const std::vector remove_plan = Dependencies::create_remove_plan(paths, specs, status_db); Checks::check_exit(!remove_plan.empty(), "Remove plan cannot be empty"); + print_plan(remove_plan); + + const bool has_non_user_requested_packages = std::find_if(remove_plan.cbegin(), remove_plan.cend(), [](const package_spec_with_remove_plan& package)-> bool + { + return package.plan.type == remove_plan_type::REMOVE; + }) != remove_plan.cend(); + + if (has_non_user_requested_packages && !isRecursive) + { + System::println(System::color::warning, "Additional packages (*) need to be removed to complete this operation.\n" + "If you are sure you want to remove them, run the command with the --recursive option"); + exit(EXIT_FAILURE); + } + + //exit(EXIT_SUCCESS); for (const package_spec& spec : specs) { deinstall_package(paths, spec, status_db); -- cgit v1.2.3 From 661776fe29344c431731e5ae464da4942b38bf79 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 12:34:36 -0800 Subject: Enable recursive `remove` command --- toolsrc/src/commands_remove.cpp | 110 ++++++++++--------------------------- toolsrc/src/vcpkg_Dependencies.cpp | 4 +- 2 files changed, 31 insertions(+), 83 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 8e6a6c227..d95fd7af9 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -27,72 +27,8 @@ namespace vcpkg::Commands::Remove } } - static remove_plan_type deinstall_package_plan( - const StatusParagraphs::iterator package_it, - const StatusParagraphs& status_db, - std::vector& dependencies_out) + static void remove_package(const vcpkg_paths& paths, StatusParagraph& pkg) { - dependencies_out.clear(); - - if (package_it == status_db.end() || (*package_it)->state == install_state_t::not_installed) - { - return remove_plan_type::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 remove_plan_type::DEPENDENCIES_NOT_SATISFIED; - - return remove_plan_type::REMOVE; - } - - 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 remove_plan_type::NOT_INSTALLED: - System::println(System::color::success, "Package %s is not installed", spec); - return; - case remove_plan_type::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 remove_plan_type::REMOVE: - break; - default: - Checks::unreachable(); - } - pkg.want = want_t::purge; pkg.state = install_state_t::half_installed; write_update(paths, pkg); @@ -185,7 +121,7 @@ namespace vcpkg::Commands::Remove continue; } - if (i.plan.type == remove_plan_type::REMOVE || i.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + if (i.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED || i.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) { remove.push_back(&i); continue; @@ -215,12 +151,15 @@ namespace vcpkg::Commands::Remove System::println("The following packages will be removed:\n%s", Strings::Joiner::on("\n").join(remove, [](const package_spec_with_remove_plan* p) { - if (p->plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + switch (p->plan.type) { - return " " + p->spec.toString(); + case remove_plan_type::REMOVE_USER_REQUESTED: + return " " + p->spec.toString(); + case remove_plan_type::REMOVE_AUTO_SELECTED: + return " * " + p->spec.toString(); + default: + Checks::unreachable(); } - - return " * " + p->spec.toString(); })); } } @@ -230,13 +169,13 @@ namespace vcpkg::Commands::Remove static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); - const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE}); + const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE, OPTION_RECURSIVE}); auto status_db = database_load_check(paths); std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); Input::check_triplets(specs, paths); const bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); - const bool isRecursive = options.find(OPTION_PURGE) != options.end(); + const bool isRecursive = options.find(OPTION_RECURSIVE) != options.end(); const std::vector remove_plan = Dependencies::create_remove_plan(paths, specs, status_db); Checks::check_exit(!remove_plan.empty(), "Remove plan cannot be empty"); @@ -245,27 +184,36 @@ namespace vcpkg::Commands::Remove const bool has_non_user_requested_packages = std::find_if(remove_plan.cbegin(), remove_plan.cend(), [](const package_spec_with_remove_plan& package)-> bool { - return package.plan.type == remove_plan_type::REMOVE; + return package.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED; }) != remove_plan.cend(); if (has_non_user_requested_packages && !isRecursive) { System::println(System::color::warning, "Additional packages (*) need to be removed to complete this operation.\n" - "If you are sure you want to remove them, run the command with the --recursive option"); + "If you are sure you want to remove them, run the command with the --recursive option"); exit(EXIT_FAILURE); } - //exit(EXIT_SUCCESS); - for (const package_spec& spec : specs) + for (const package_spec_with_remove_plan& action : remove_plan) { - deinstall_package(paths, spec, status_db); - - if (alsoRemoveFolderFromPackages) + if (action.plan.type == remove_plan_type::NOT_INSTALLED) { - const fs::path spec_package_dir = paths.packages / spec.dir(); - delete_directory(spec_package_dir); + System::println(System::color::success, "Package %s is not installed", action.spec); } + else if (action.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED || action.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + { + remove_package(paths, *action.plan.status_pgh); + + if (alsoRemoveFolderFromPackages) + { + const fs::path spec_package_dir = paths.packages / action.spec.dir(); + delete_directory(spec_package_dir); + } + } + else + Checks::unreachable(); } + exit(EXIT_SUCCESS); } } diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 3b6db5bbd..5de782e73 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -114,8 +114,8 @@ namespace vcpkg::Dependencies examine_stack.push_back(an_installed_package.get()->package.spec); } - const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED: remove_plan_type::REMOVE; - was_examined.emplace(spec, remove_plan_action{ type, std::make_unique(std::move((*it)->package))}); + const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED: remove_plan_type::REMOVE_AUTO_SELECTED; + was_examined.emplace(spec, remove_plan_action{ type, std::make_unique(std::move(**it))}); } std::vector ret; -- cgit v1.2.3 From 884cd176b05a76e7fbba924685a0d71c3dea0f9b Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 12:36:27 -0800 Subject: Renames and formatting --- toolsrc/src/commands_install.cpp | 4 ++-- toolsrc/src/vcpkg_Dependencies.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index dabce44f6..e5c5dd013 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -214,14 +214,14 @@ namespace vcpkg::Commands::Install } else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) { - Commands::Build::build_package(*action.plan.spgh, action.spec, paths, paths.port_dir(action.spec)); + Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); } else if (action.plan.type == install_plan_type::INSTALL) { - install_package(paths, *action.plan.bpgh, status_db); + install_package(paths, *action.plan.binary_pgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); } else diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 5de782e73..b0047a772 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -66,7 +66,7 @@ namespace vcpkg::Dependencies const std::vector pkgs = graph.find_topological_sort(); for (const package_spec& pkg : pkgs) { - ret.push_back({ pkg, std::move(was_examined[pkg]) }); + ret.push_back({pkg, std::move(was_examined[pkg])}); } return ret; } @@ -93,7 +93,7 @@ namespace vcpkg::Dependencies auto it = status_db.find(spec); if (it == status_db.end() || (*it)->state == install_state_t::not_installed) { - was_examined.emplace(spec, remove_plan_action{ remove_plan_type::NOT_INSTALLED, nullptr}); + was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, nullptr}); continue; } @@ -114,8 +114,8 @@ namespace vcpkg::Dependencies examine_stack.push_back(an_installed_package.get()->package.spec); } - const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED: remove_plan_type::REMOVE_AUTO_SELECTED; - was_examined.emplace(spec, remove_plan_action{ type, std::make_unique(std::move(**it))}); + const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED : remove_plan_type::REMOVE_AUTO_SELECTED; + was_examined.emplace(spec, remove_plan_action{type, std::make_unique(std::move(**it))}); } std::vector ret; @@ -123,7 +123,7 @@ namespace vcpkg::Dependencies const std::vector pkgs = graph.find_topological_sort(); for (const package_spec& pkg : pkgs) { - ret.push_back({ pkg, std::move(was_examined[pkg]) }); + ret.push_back({pkg, std::move(was_examined[pkg])}); } return ret; } -- cgit v1.2.3 From 4d104541674f1975b60c2ccd694d447e25a16359 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 12:45:26 -0800 Subject: Add package_spec::display_name() --- toolsrc/src/BinaryParagraph.cpp | 2 +- toolsrc/src/package_spec.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp index eed87eb81..f949677a3 100644 --- a/toolsrc/src/BinaryParagraph.cpp +++ b/toolsrc/src/BinaryParagraph.cpp @@ -71,7 +71,7 @@ namespace vcpkg std::string BinaryParagraph::displayname() const { - return Strings::format("%s:%s", this->spec.name(), this->spec.target_triplet()); + return this->spec.display_name(); } std::string BinaryParagraph::dir() const diff --git a/toolsrc/src/package_spec.cpp b/toolsrc/src/package_spec.cpp index 7d8d2681d..2713e219f 100644 --- a/toolsrc/src/package_spec.cpp +++ b/toolsrc/src/package_spec.cpp @@ -50,6 +50,11 @@ namespace vcpkg return this->m_target_triplet; } + std::string package_spec::display_name() const + { + return Strings::format("%s:%s", this->name(), this->target_triplet()); + } + std::string package_spec::dir() const { return Strings::format("%s_%s", this->m_name, this->m_target_triplet); @@ -57,7 +62,7 @@ namespace vcpkg std::string package_spec::toString() const { - return Strings::format("%s:%s", this->name(), this->target_triplet()); + return this->display_name(); } std::string to_printf_arg(const package_spec& spec) -- cgit v1.2.3 From b1f0a09af250296d7483aa28e3a014d2635600b5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 12:46:35 -0800 Subject: Remove commented-out code --- toolsrc/src/commands_remove.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index d95fd7af9..9a0b6950e 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -130,11 +130,6 @@ namespace vcpkg::Commands::Remove Checks::unreachable(); } - //std::copy_if(plan.cbegin(), plan.cend(), std::back_inserter(not_installed), [](const package_spec_with_remove_plan& i) - // { - // return i.plan.type == remove_plan_type::NOT_INSTALLED; - // }); - if (!not_installed.empty()) { sort_packages_by_name(¬_installed); -- cgit v1.2.3 From 82005ffe7474b5432bb043e3b4859bdd68ea6030 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 12:59:10 -0800 Subject: Improve messages from the `remove` command --- toolsrc/src/commands_remove.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 9a0b6950e..85154d356 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -97,7 +97,6 @@ namespace vcpkg::Commands::Remove pkg.state = install_state_t::not_installed; write_update(paths, pkg); - System::println(System::color::success, "Package %s was successfully removed", pkg.package.displayname()); } static void sort_packages_by_name(std::vector* packages) @@ -197,12 +196,17 @@ namespace vcpkg::Commands::Remove } else if (action.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED || action.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) { + const std::string display_name = action.spec.display_name(); + System::println("Removing package %s... ", display_name); remove_package(paths, *action.plan.status_pgh); + System::println(System::color::success, "Removing package %s... done", display_name); if (alsoRemoveFolderFromPackages) { const fs::path spec_package_dir = paths.packages / action.spec.dir(); + System::println("Purging package %s... ", display_name); delete_directory(spec_package_dir); + System::println(System::color::success, "Purging package %s... done", display_name); } } else -- cgit v1.2.3 From 9c87fcbd8b7e1cdee148d33ed272ae5ecc83fb60 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 13:37:00 -0800 Subject: Formatting --- toolsrc/src/commands_remove.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 85154d356..b28fe3283 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -183,7 +183,8 @@ namespace vcpkg::Commands::Remove if (has_non_user_requested_packages && !isRecursive) { - System::println(System::color::warning, "Additional packages (*) need to be removed to complete this operation.\n" + System::println(System::color::warning, + "Additional packages (*) need to be removed to complete this operation.\n" "If you are sure you want to remove them, run the command with the --recursive option"); exit(EXIT_FAILURE); } -- cgit v1.2.3 From e461467affad578d2e13a5c8f18cc37ee3007938 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 13:57:43 -0800 Subject: [Dependencies] User-requested vs autos-elected info is now in a separate enum --- toolsrc/src/commands_remove.cpp | 26 ++++++++++++++------------ toolsrc/src/vcpkg_Dependencies.cpp | 6 +++--- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index b28fe3283..2fc560275 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -114,13 +114,13 @@ namespace vcpkg::Commands::Remove for (const package_spec_with_remove_plan& i : plan) { - if (i.plan.type == remove_plan_type::NOT_INSTALLED) + if (i.plan.plan_type == remove_plan_type::NOT_INSTALLED) { not_installed.push_back(&i); continue; } - if (i.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED || i.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + if (i.plan.plan_type == remove_plan_type::REMOVE) { remove.push_back(&i); continue; @@ -145,15 +145,17 @@ namespace vcpkg::Commands::Remove System::println("The following packages will be removed:\n%s", Strings::Joiner::on("\n").join(remove, [](const package_spec_with_remove_plan* p) { - switch (p->plan.type) + if (p->plan.request_type == Dependencies::request_type::AUTO_SELECTED) { - case remove_plan_type::REMOVE_USER_REQUESTED: - return " " + p->spec.toString(); - case remove_plan_type::REMOVE_AUTO_SELECTED: - return " * " + p->spec.toString(); - default: - Checks::unreachable(); + return " * " + p->spec.toString(); } + + if (p->plan.request_type == Dependencies::request_type::USER_REQUESTED) + { + return " " + p->spec.toString(); + } + + Checks::unreachable(); })); } } @@ -178,7 +180,7 @@ namespace vcpkg::Commands::Remove const bool has_non_user_requested_packages = std::find_if(remove_plan.cbegin(), remove_plan.cend(), [](const package_spec_with_remove_plan& package)-> bool { - return package.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED; + return package.plan.plan_type == remove_plan_type::REMOVE_AUTO_SELECTED; }) != remove_plan.cend(); if (has_non_user_requested_packages && !isRecursive) @@ -191,11 +193,11 @@ namespace vcpkg::Commands::Remove for (const package_spec_with_remove_plan& action : remove_plan) { - if (action.plan.type == remove_plan_type::NOT_INSTALLED) + if (action.plan.plan_type == remove_plan_type::NOT_INSTALLED) { System::println(System::color::success, "Package %s is not installed", action.spec); } - else if (action.plan.type == remove_plan_type::REMOVE_AUTO_SELECTED || action.plan.type == remove_plan_type::REMOVE_USER_REQUESTED) + else if (action.plan.plan_type == remove_plan_type::REMOVE_AUTO_SELECTED || action.plan.plan_type == remove_plan_type::REMOVE_USER_REQUESTED) { const std::string display_name = action.spec.display_name(); System::println("Removing package %s... ", display_name); diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index b0047a772..669cdfc20 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -93,7 +93,7 @@ namespace vcpkg::Dependencies auto it = status_db.find(spec); if (it == status_db.end() || (*it)->state == install_state_t::not_installed) { - was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, nullptr}); + was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED, nullptr}); continue; } @@ -114,8 +114,8 @@ namespace vcpkg::Dependencies examine_stack.push_back(an_installed_package.get()->package.spec); } - const remove_plan_type type = specs_as_set.find(spec) != specs_as_set.end() ? remove_plan_type::REMOVE_USER_REQUESTED : remove_plan_type::REMOVE_AUTO_SELECTED; - was_examined.emplace(spec, remove_plan_action{type, std::make_unique(std::move(**it))}); + const request_type request_type = specs_as_set.find(spec) != specs_as_set.end() ? request_type::USER_REQUESTED : request_type::AUTO_SELECTED; + was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE, request_type,std::make_unique(std::move(**it))}); } std::vector ret; -- cgit v1.2.3 From b4e9322a11aa2d0d9b0f1c0f960d921ce51e1c0f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 13:58:58 -0800 Subject: Rename field --- toolsrc/src/commands_build.cpp | 2 +- toolsrc/src/commands_install.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index b6c3cea03..ccc3c8d9f 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -107,7 +107,7 @@ namespace vcpkg::Commands::Build unmet_dependencies.erase( std::remove_if(unmet_dependencies.begin(), unmet_dependencies.end(), [](const package_spec_with_install_plan& p) { - return p.plan.type == install_plan_type::ALREADY_INSTALLED; + return p.plan.plan_type == install_plan_type::ALREADY_INSTALLED; }), unmet_dependencies.end()); diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index e5c5dd013..0371cc6e5 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -205,21 +205,21 @@ namespace vcpkg::Commands::Install { try { - if (action.plan.type == install_plan_type::ALREADY_INSTALLED) + if (action.plan.plan_type == install_plan_type::ALREADY_INSTALLED) { if (std::find(specs.begin(), specs.end(), action.spec) != specs.end()) { System::println(System::color::success, "Package %s is already installed", action.spec); } } - else if (action.plan.type == install_plan_type::BUILD_AND_INSTALL) + else if (action.plan.plan_type == install_plan_type::BUILD_AND_INSTALL) { Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); install_package(paths, bpgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); } - else if (action.plan.type == install_plan_type::INSTALL) + else if (action.plan.plan_type == install_plan_type::INSTALL) { install_package(paths, *action.plan.binary_pgh, status_db); System::println(System::color::success, "Package %s is installed", action.spec); -- cgit v1.2.3 From a7be90f823d9a3b33e58568c28836be33bda5ac8 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 14:17:26 -0800 Subject: Fix usage of remove_plan_type --- toolsrc/src/commands_remove.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 2fc560275..b09790efc 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -9,6 +9,7 @@ namespace vcpkg::Commands::Remove { using Dependencies::package_spec_with_remove_plan; using Dependencies::remove_plan_type; + using Dependencies::request_type; static const std::string OPTION_PURGE = "--purge"; static const std::string OPTION_RECURSIVE = "--recursive"; @@ -180,7 +181,7 @@ namespace vcpkg::Commands::Remove const bool has_non_user_requested_packages = std::find_if(remove_plan.cbegin(), remove_plan.cend(), [](const package_spec_with_remove_plan& package)-> bool { - return package.plan.plan_type == remove_plan_type::REMOVE_AUTO_SELECTED; + return package.plan.request_type != request_type::USER_REQUESTED; }) != remove_plan.cend(); if (has_non_user_requested_packages && !isRecursive) @@ -197,7 +198,7 @@ namespace vcpkg::Commands::Remove { System::println(System::color::success, "Package %s is not installed", action.spec); } - else if (action.plan.plan_type == remove_plan_type::REMOVE_AUTO_SELECTED || action.plan.plan_type == remove_plan_type::REMOVE_USER_REQUESTED) + else if (action.plan.plan_type == remove_plan_type::REMOVE) { const std::string display_name = action.spec.display_name(); System::println("Removing package %s... ", display_name); @@ -206,9 +207,8 @@ namespace vcpkg::Commands::Remove if (alsoRemoveFolderFromPackages) { - const fs::path spec_package_dir = paths.packages / action.spec.dir(); System::println("Purging package %s... ", display_name); - delete_directory(spec_package_dir); + delete_directory(paths.packages / action.spec.dir()); System::println(System::color::success, "Purging package %s... done", display_name); } } -- cgit v1.2.3 From 836de4b0748617db6d06b0eef6fe9ccff9980b1f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 15:29:02 -0800 Subject: Fix remove_plan code --- toolsrc/src/vcpkg_Dependencies.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index 669cdfc20..bb2ecc666 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -90,7 +90,7 @@ namespace vcpkg::Dependencies continue; } - auto it = status_db.find(spec); + const StatusParagraphs::const_iterator it = status_db.find(spec); if (it == status_db.end() || (*it)->state == install_state_t::not_installed) { was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED, nullptr}); @@ -115,7 +115,7 @@ namespace vcpkg::Dependencies } const request_type request_type = specs_as_set.find(spec) != specs_as_set.end() ? request_type::USER_REQUESTED : request_type::AUTO_SELECTED; - was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE, request_type,std::make_unique(std::move(**it))}); + was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE, request_type,it->get()}); } std::vector ret; -- cgit v1.2.3 From 86a5ab7bccce5988682e69c4e1c14fedbf9a13a7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 16:40:09 -0800 Subject: Use pointer instead of reference for out param --- toolsrc/src/commands_install.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 0371cc6e5..439424d28 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -134,11 +134,11 @@ namespace vcpkg::Commands::Install return ImmutableSortedVector::create(std::move(installed_files)); } - void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db) + 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 triplet& triplet = binary_paragraph.spec.target_triplet(); - const std::vector pgh_and_files = get_installed_files(paths, status_db); + const std::vector pgh_and_files = get_installed_files(paths, *status_db); const ImmutableSortedVector package_files = build_list_of_package_files(package_dir); const ImmutableSortedVector installed_files = build_list_of_installed_files(pgh_and_files, triplet); @@ -166,19 +166,19 @@ namespace vcpkg::Commands::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()) + 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)); + 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)); + status_db->insert(std::make_unique(spgh)); } void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet) @@ -216,12 +216,12 @@ namespace vcpkg::Commands::Install { Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec)); const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw(); - install_package(paths, bpgh, status_db); + install_package(paths, bpgh, &status_db); System::println(System::color::success, "Package %s is installed", action.spec); } else if (action.plan.plan_type == install_plan_type::INSTALL) { - install_package(paths, *action.plan.binary_pgh, status_db); + install_package(paths, *action.plan.binary_pgh, &status_db); System::println(System::color::success, "Package %s is installed", action.spec); } else -- cgit v1.2.3 From 4252d9436e6d4104f6acc5560aef461046aae853 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 16:46:39 -0800 Subject: remove_plan now depends on the spec, instead of StatusParagraph --- toolsrc/src/commands_remove.cpp | 6 ++++-- toolsrc/src/vcpkg_Dependencies.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index b09790efc..5a9467b47 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -28,8 +28,10 @@ namespace vcpkg::Commands::Remove } } - static void remove_package(const vcpkg_paths& paths, StatusParagraph& pkg) + static void remove_package(const vcpkg_paths& paths, const package_spec& spec, StatusParagraphs* status_db) { + StatusParagraph& pkg = **status_db->find(spec.name(), spec.target_triplet()); + pkg.want = want_t::purge; pkg.state = install_state_t::half_installed; write_update(paths, pkg); @@ -202,7 +204,7 @@ namespace vcpkg::Commands::Remove { const std::string display_name = action.spec.display_name(); System::println("Removing package %s... ", display_name); - remove_package(paths, *action.plan.status_pgh); + remove_package(paths, action.spec, &status_db); System::println(System::color::success, "Removing package %s... done", display_name); if (alsoRemoveFolderFromPackages) diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index bb2ecc666..a534537d2 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -93,7 +93,7 @@ namespace vcpkg::Dependencies const StatusParagraphs::const_iterator it = status_db.find(spec); if (it == status_db.end() || (*it)->state == install_state_t::not_installed) { - was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED, nullptr}); + was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED}); continue; } @@ -115,7 +115,7 @@ namespace vcpkg::Dependencies } const request_type request_type = specs_as_set.find(spec) != specs_as_set.end() ? request_type::USER_REQUESTED : request_type::AUTO_SELECTED; - was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE, request_type,it->get()}); + was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE}); } std::vector ret; -- cgit v1.2.3 From 4e64dc598a53493a85d65f94c81a33c4862fc89a Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 17:52:53 -0800 Subject: [Dependencies] Specify constructors and fix bug with default remove_plan_action init --- toolsrc/src/vcpkg_Dependencies.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp index a534537d2..5bd6c3eb9 100644 --- a/toolsrc/src/vcpkg_Dependencies.cpp +++ b/toolsrc/src/vcpkg_Dependencies.cpp @@ -9,6 +9,32 @@ namespace vcpkg::Dependencies { + install_plan_action::install_plan_action() : plan_type(install_plan_type::UNKNOWN), binary_pgh(nullptr), source_pgh(nullptr) + { + } + + install_plan_action::install_plan_action(const install_plan_type& plan_type, optional binary_pgh, optional source_pgh) + : plan_type(std::move(plan_type)), binary_pgh(std::move(binary_pgh)), source_pgh(std::move(source_pgh)) + { + } + + package_spec_with_install_plan::package_spec_with_install_plan(const package_spec& spec, install_plan_action&& plan) : spec(spec), plan(std::move(plan)) + { + } + + remove_plan_action::remove_plan_action() : plan_type(remove_plan_type::UNKNOWN), request_type(request_type::UNKNOWN) + { + } + + remove_plan_action::remove_plan_action(const remove_plan_type& plan_type, const Dependencies::request_type& request_type) : plan_type(plan_type), request_type(request_type) + { + } + + package_spec_with_remove_plan::package_spec_with_remove_plan(const package_spec& spec, remove_plan_action&& plan) + : spec(spec), plan(std::move(plan)) + { + } + std::vector create_install_plan(const vcpkg_paths& paths, const std::vector& specs, const StatusParagraphs& status_db) { std::unordered_map was_examined; // Examine = we have checked its immediate (non-recursive) dependencies @@ -66,7 +92,7 @@ namespace vcpkg::Dependencies const std::vector pkgs = graph.find_topological_sort(); for (const package_spec& pkg : pkgs) { - ret.push_back({pkg, std::move(was_examined[pkg])}); + ret.push_back(package_spec_with_install_plan(pkg, std::move(was_examined[pkg]))); } return ret; } @@ -93,7 +119,7 @@ namespace vcpkg::Dependencies const StatusParagraphs::const_iterator it = status_db.find(spec); if (it == status_db.end() || (*it)->state == install_state_t::not_installed) { - was_examined.emplace(spec, remove_plan_action{remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED}); + was_examined.emplace(spec, remove_plan_action(remove_plan_type::NOT_INSTALLED, request_type::USER_REQUESTED)); continue; } @@ -115,7 +141,7 @@ namespace vcpkg::Dependencies } const request_type request_type = specs_as_set.find(spec) != specs_as_set.end() ? request_type::USER_REQUESTED : request_type::AUTO_SELECTED; - was_examined.emplace(spec, remove_plan_action{remove_plan_type::REMOVE}); + was_examined.emplace(spec, remove_plan_action(remove_plan_type::REMOVE, request_type)); } std::vector ret; @@ -123,7 +149,7 @@ namespace vcpkg::Dependencies const std::vector pkgs = graph.find_topological_sort(); for (const package_spec& pkg : pkgs) { - ret.push_back({pkg, std::move(was_examined[pkg])}); + ret.push_back(package_spec_with_remove_plan(pkg, std::move(was_examined[pkg]))); } return ret; } -- cgit v1.2.3 From 5c01fc4af871ed1cc1481a53957be1460142a6f2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 22:04:04 -0800 Subject: Change --recursive option to --recurse --- toolsrc/src/commands_remove.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 5a9467b47..7e8608e72 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -12,7 +12,7 @@ namespace vcpkg::Commands::Remove using Dependencies::request_type; static const std::string OPTION_PURGE = "--purge"; - static const std::string OPTION_RECURSIVE = "--recursive"; + static const std::string OPTION_RECURSE = "--recurse"; static void delete_directory(const fs::path& directory) { @@ -168,13 +168,13 @@ namespace vcpkg::Commands::Remove static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost"); args.check_min_arg_count(1, example); - const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE, OPTION_RECURSIVE}); + const std::unordered_set options = args.check_and_get_optional_command_arguments({OPTION_PURGE, OPTION_RECURSE}); auto status_db = database_load_check(paths); std::vector specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example); Input::check_triplets(specs, paths); const bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end(); - const bool isRecursive = options.find(OPTION_RECURSIVE) != options.end(); + const bool isRecursive = options.find(OPTION_RECURSE) != options.end(); const std::vector remove_plan = Dependencies::create_remove_plan(paths, specs, status_db); Checks::check_exit(!remove_plan.empty(), "Remove plan cannot be empty"); @@ -190,7 +190,7 @@ namespace vcpkg::Commands::Remove { System::println(System::color::warning, "Additional packages (*) need to be removed to complete this operation.\n" - "If you are sure you want to remove them, run the command with the --recursive option"); + "If you are sure you want to remove them, run the command with the --recurse option"); exit(EXIT_FAILURE); } -- cgit v1.2.3 From e6e325b1cd92bf0b1aa05c84a2a757713f17fa08 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 30 Jan 2017 22:10:08 -0800 Subject: Fix usage of Strings::Joiner --- toolsrc/src/commands_install.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp index 439424d28..1f5a2234d 100644 --- a/toolsrc/src/commands_install.cpp +++ b/toolsrc/src/commands_install.cpp @@ -155,7 +155,7 @@ namespace vcpkg::Commands::Install triplet_install_path.generic_string(), binary_paragraph.spec); System::print("\n "); - System::println(Strings::join(intersection, "\n ")); + System::println(Strings::Joiner::on("\n ").join(intersection)); System::println(""); exit(EXIT_FAILURE); } -- cgit v1.2.3 From 2a83c5eda6288cba46cb723996f95b0f6b21e61f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Jan 2017 12:59:20 -0800 Subject: [opt_bool] Make members ALL_CAPS --- toolsrc/src/vcpkg.cpp | 12 ++++++------ toolsrc/src/vcpkg_cmd_arguments.cpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index b78319167..36bd0a40a 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -202,14 +202,14 @@ int wmain(const int argc, const wchar_t* const* const argv) const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); - if (args.printmetrics != opt_bool::unspecified) - SetPrintMetrics(args.printmetrics == opt_bool::enabled); - if (args.sendmetrics != opt_bool::unspecified) - SetSendMetrics(args.sendmetrics == opt_bool::enabled); + if (args.printmetrics != opt_bool::UNSPECIFIED) + SetPrintMetrics(args.printmetrics == opt_bool::ENABLED); + if (args.sendmetrics != opt_bool::UNSPECIFIED) + SetSendMetrics(args.sendmetrics == opt_bool::ENABLED); - if (args.debug != opt_bool::unspecified) + if (args.debug != opt_bool::UNSPECIFIED) { - g_debugging = (args.debug == opt_bool::enabled); + g_debugging = (args.debug == opt_bool::ENABLED); } if (g_debugging) diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index 4a06128a4..e0d307077 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -36,7 +36,7 @@ namespace vcpkg const std::string& option_name, opt_bool& option_field) { - if (option_field != opt_bool::unspecified && option_field != new_setting) + if (option_field != opt_bool::UNSPECIFIED && option_field != new_setting) { System::println(System::color::error, "Error: conflicting values specified for --%s", option_name); TrackProperty("error", "error conflicting switches"); @@ -94,27 +94,27 @@ namespace vcpkg } if (arg == "--debug") { - parse_switch(opt_bool::enabled, "debug", args.debug); + parse_switch(opt_bool::ENABLED, "debug", args.debug); continue; } if (arg == "--sendmetrics") { - parse_switch(opt_bool::enabled, "sendmetrics", args.sendmetrics); + parse_switch(opt_bool::ENABLED, "sendmetrics", args.sendmetrics); continue; } if (arg == "--printmetrics") { - parse_switch(opt_bool::enabled, "printmetrics", args.printmetrics); + parse_switch(opt_bool::ENABLED, "printmetrics", args.printmetrics); continue; } if (arg == "--no-sendmetrics") { - parse_switch(opt_bool::disabled, "sendmetrics", args.sendmetrics); + parse_switch(opt_bool::DISABLED, "sendmetrics", args.sendmetrics); continue; } if (arg == "--no-printmetrics") { - parse_switch(opt_bool::disabled, "printmetrics", args.printmetrics); + parse_switch(opt_bool::DISABLED, "printmetrics", args.printmetrics); continue; } -- cgit v1.2.3 From bd1a10e5b97b073731cbb97e26611edf317c16d5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Jan 2017 13:31:45 -0800 Subject: Enhance the opt_bool type --- toolsrc/src/opt_bool.cpp | 29 +++++++++++++++++++++++++++++ toolsrc/src/vcpkg.cpp | 12 ++++++------ toolsrc/src/vcpkg_cmd_arguments.cpp | 16 ++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 toolsrc/src/opt_bool.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/opt_bool.cpp b/toolsrc/src/opt_bool.cpp new file mode 100644 index 000000000..324936fb4 --- /dev/null +++ b/toolsrc/src/opt_bool.cpp @@ -0,0 +1,29 @@ +#include "pch.h" +#include "opt_bool.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::opt_bool +{ + static const std::string UNSPECIFIED_NAME = "unspecified"; + static const std::string ENABLED_NAME = "enabled"; + static const std::string DISABLED_NAME = "disabled"; + type parse(const std::string& s) + { + if (s == UNSPECIFIED_NAME) + { + return opt_bool_t::UNSPECIFIED; + } + + if (s == ENABLED_NAME) + { + return opt_bool_t::ENABLED; + } + + if (s == DISABLED_NAME) + { + return opt_bool_t::DISABLED; + } + + Checks::exit_with_message("Could not convert string [%s] to opt_bool", s); + } +} diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index 36bd0a40a..3e313c702 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -202,14 +202,14 @@ int wmain(const int argc, const wchar_t* const* const argv) const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); - if (args.printmetrics != opt_bool::UNSPECIFIED) - SetPrintMetrics(args.printmetrics == opt_bool::ENABLED); - if (args.sendmetrics != opt_bool::UNSPECIFIED) - SetSendMetrics(args.sendmetrics == opt_bool::ENABLED); + if (args.printmetrics != opt_bool_t::UNSPECIFIED) + SetPrintMetrics(args.printmetrics == opt_bool_t::ENABLED); + if (args.sendmetrics != opt_bool_t::UNSPECIFIED) + SetSendMetrics(args.sendmetrics == opt_bool_t::ENABLED); - if (args.debug != opt_bool::UNSPECIFIED) + if (args.debug != opt_bool_t::UNSPECIFIED) { - g_debugging = (args.debug == opt_bool::ENABLED); + g_debugging = (args.debug == opt_bool_t::ENABLED); } if (g_debugging) diff --git a/toolsrc/src/vcpkg_cmd_arguments.cpp b/toolsrc/src/vcpkg_cmd_arguments.cpp index e0d307077..fdeb6e877 100644 --- a/toolsrc/src/vcpkg_cmd_arguments.cpp +++ b/toolsrc/src/vcpkg_cmd_arguments.cpp @@ -32,11 +32,11 @@ namespace vcpkg } static void parse_switch( - opt_bool new_setting, + opt_bool_t new_setting, const std::string& option_name, - opt_bool& option_field) + opt_bool_t& option_field) { - if (option_field != opt_bool::UNSPECIFIED && option_field != new_setting) + if (option_field != opt_bool_t::UNSPECIFIED && option_field != new_setting) { System::println(System::color::error, "Error: conflicting values specified for --%s", option_name); TrackProperty("error", "error conflicting switches"); @@ -94,27 +94,27 @@ namespace vcpkg } if (arg == "--debug") { - parse_switch(opt_bool::ENABLED, "debug", args.debug); + parse_switch(opt_bool_t::ENABLED, "debug", args.debug); continue; } if (arg == "--sendmetrics") { - parse_switch(opt_bool::ENABLED, "sendmetrics", args.sendmetrics); + parse_switch(opt_bool_t::ENABLED, "sendmetrics", args.sendmetrics); continue; } if (arg == "--printmetrics") { - parse_switch(opt_bool::ENABLED, "printmetrics", args.printmetrics); + parse_switch(opt_bool_t::ENABLED, "printmetrics", args.printmetrics); continue; } if (arg == "--no-sendmetrics") { - parse_switch(opt_bool::DISABLED, "sendmetrics", args.sendmetrics); + parse_switch(opt_bool_t::DISABLED, "sendmetrics", args.sendmetrics); continue; } if (arg == "--no-printmetrics") { - parse_switch(opt_bool::DISABLED, "printmetrics", args.printmetrics); + parse_switch(opt_bool_t::DISABLED, "printmetrics", args.printmetrics); continue; } -- cgit v1.2.3 From 459999786960483f6d46229524500543459968ed Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Jan 2017 17:09:48 -0800 Subject: Introduce BuildPolicies (not used by the post_build checks yet) --- toolsrc/src/BuildInfo.cpp | 16 +++++++++++--- toolsrc/src/BuildPolicies.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 toolsrc/src/BuildPolicies.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp index b401f9d44..82243ebac 100644 --- a/toolsrc/src/BuildInfo.cpp +++ b/toolsrc/src/BuildInfo.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "BuildInfo.h" #include "vcpkg_Checks.h" +#include "opt_bool.h" #include "vcpkglib_helpers.h" namespace vcpkg::PostBuildLint @@ -44,11 +45,20 @@ namespace vcpkg::PostBuildLint static const std::string LIBRARY_LINKAGE = "LibraryLinkage"; } - BuildInfo BuildInfo::create(const std::unordered_map& pgh) + BuildInfo BuildInfo::create(std::unordered_map pgh) { BuildInfo build_info; - build_info.crt_linkage = details::required_field(pgh, BuildInfoRequiredField::CRT_LINKAGE); - build_info.library_linkage = details::required_field(pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); + build_info.crt_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); + build_info.library_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); + + // The remaining entries are policies + for (const std::unordered_map::value_type& p : pgh) + { + const BuildPolicies::type policy = BuildPolicies::parse(p.first); + Checks::check_exit(policy != BuildPolicies::UNKNOWN, "Unknown policy found: %s", p.first); + const opt_bool_t status = opt_bool::parse(p.second); + build_info.policies.emplace(policy, status); + } return build_info; } diff --git a/toolsrc/src/BuildPolicies.cpp b/toolsrc/src/BuildPolicies.cpp new file mode 100644 index 000000000..0f7c3c492 --- /dev/null +++ b/toolsrc/src/BuildPolicies.cpp @@ -0,0 +1,49 @@ +#include "pch.h" +#include "BuildPolicies.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint::BuildPolicies +{ + static const std::string NAME_UNKNOWN = "PolicyUnknown"; + static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs"; + + const std::string& type::toString() const + { + switch (this->backing_enum) + { + case DLLS_WITHOUT_LIBS: + return NAME_DLLS_WITHOUT_LIBS; + case UNKNOWN: + return NAME_UNKNOWN; + default: + Checks::unreachable(); + } + } + + const std::string& type::cmake_variable() const + { + static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS"; + + switch (this->backing_enum) + { + case DLLS_WITHOUT_LIBS: + return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; + case UNKNOWN: + Checks::exit_with_message("No CMake command corresponds to UNKNOWN"); + default: + Checks::unreachable(); + } + } + + type::type(): backing_enum(backing_enum_t::UNKNOWN) {} + + type parse(const std::string& s) + { + if (s == NAME_DLLS_WITHOUT_LIBS) + { + return BuildPolicies::DLLS_WITHOUT_LIBS; + } + + return BuildPolicies::UNKNOWN; + } +} -- cgit v1.2.3 From cd0b7d644b2ba61618b70ae58f50d2e880dbe509 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Jan 2017 18:31:19 -0800 Subject: Add PolicyDLLsWithoutLIBs policy --- toolsrc/src/post_build_lint.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp index daf6f49ee..009f8019c 100644 --- a/toolsrc/src/post_build_lint.cpp +++ b/toolsrc/src/post_build_lint.cpp @@ -368,11 +368,20 @@ namespace vcpkg::PostBuildLint return lint_status::ERROR_DETECTED; } - static lint_status check_lib_files_are_available_if_dlls_are_available(const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) + static lint_status check_lib_files_are_available_if_dlls_are_available(const std::map& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) { + auto it = policies.find(BuildPolicies::DLLS_WITHOUT_LIBS); + if (it != policies.cend() && it->second == opt_bool_t::DISABLED) + { + return lint_status::SUCCESS; + } + if (lib_count == 0 && dll_count != 0) { System::println(System::color::warning, "Import libs were not present in %s", lib_dir.generic_string()); + System::println(System::color::warning, + "If this is intended, add the following line in the portfile:\n" + " SET(%s disabled)", BuildPolicies::DLLS_WITHOUT_LIBS.cmake_variable()); return lint_status::ERROR_DETECTED; } @@ -616,8 +625,8 @@ namespace vcpkg::PostBuildLint error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls); - error_count += check_lib_files_are_available_if_dlls_are_available(debug_libs.size(), debug_dlls.size(), debug_lib_dir); - error_count += check_lib_files_are_available_if_dlls_are_available(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 dlls; dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); -- cgit v1.2.3 From c595fac0ffb8de45f390ab591fbc76fa12ca0442 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 31 Jan 2017 18:55:14 -0800 Subject: Add BuildPolicies::values() --- toolsrc/src/BuildPolicies.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildPolicies.cpp b/toolsrc/src/BuildPolicies.cpp index 0f7c3c492..ed0f76c38 100644 --- a/toolsrc/src/BuildPolicies.cpp +++ b/toolsrc/src/BuildPolicies.cpp @@ -26,17 +26,23 @@ namespace vcpkg::PostBuildLint::BuildPolicies switch (this->backing_enum) { - case DLLS_WITHOUT_LIBS: - return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; - case UNKNOWN: - Checks::exit_with_message("No CMake command corresponds to UNKNOWN"); - default: - Checks::unreachable(); + case DLLS_WITHOUT_LIBS: + return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; + case UNKNOWN: + Checks::exit_with_message("No CMake command corresponds to UNKNOWN"); + default: + Checks::unreachable(); } } type::type(): backing_enum(backing_enum_t::UNKNOWN) {} + const std::vector& values() + { + static const std::vector& v = {UNKNOWN, DLLS_WITHOUT_LIBS}; + return v; + } + type parse(const std::string& s) { if (s == NAME_DLLS_WITHOUT_LIBS) -- cgit v1.2.3 From 9086fcebdf43ad01892c8f96afc5e676f9b72135 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 13:24:06 -0800 Subject: Rename files in PostBuildLint namespace --- toolsrc/src/BuildInfo.cpp | 175 ------- toolsrc/src/BuildPolicies.cpp | 55 --- toolsrc/src/PostBuildLint.cpp | 680 ++++++++++++++++++++++++++++ toolsrc/src/PostBuildLint_BuildInfo.cpp | 175 +++++++ toolsrc/src/PostBuildLint_BuildPolicies.cpp | 55 +++ toolsrc/src/commands_build.cpp | 2 +- toolsrc/src/post_build_lint.cpp | 680 ---------------------------- 7 files changed, 911 insertions(+), 911 deletions(-) delete mode 100644 toolsrc/src/BuildInfo.cpp delete mode 100644 toolsrc/src/BuildPolicies.cpp create mode 100644 toolsrc/src/PostBuildLint.cpp create mode 100644 toolsrc/src/PostBuildLint_BuildInfo.cpp create mode 100644 toolsrc/src/PostBuildLint_BuildPolicies.cpp delete mode 100644 toolsrc/src/post_build_lint.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/BuildInfo.cpp b/toolsrc/src/BuildInfo.cpp deleted file mode 100644 index 82243ebac..000000000 --- a/toolsrc/src/BuildInfo.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "pch.h" -#include "BuildInfo.h" -#include "vcpkg_Checks.h" -#include "opt_bool.h" -#include "vcpkglib_helpers.h" - -namespace vcpkg::PostBuildLint -{ - const ConfigurationType& BuildType::config() const - { - return this->m_config; - } - - const LinkageType& BuildType::linkage() const - { - return this->m_linkage; - } - - std::regex BuildType::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - std::string BuildType::toString() const - { - const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); - return s; - } - - bool operator==(const BuildType& lhs, const BuildType& rhs) - { - return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); - } - - bool operator!=(const BuildType& lhs, const BuildType& rhs) - { - return !(lhs == rhs); - } - - // - namespace BuildInfoRequiredField - { - static const std::string CRT_LINKAGE = "CRTLinkage"; - static const std::string LIBRARY_LINKAGE = "LibraryLinkage"; - } - - BuildInfo BuildInfo::create(std::unordered_map pgh) - { - BuildInfo build_info; - build_info.crt_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); - build_info.library_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); - - // The remaining entries are policies - for (const std::unordered_map::value_type& p : pgh) - { - const BuildPolicies::type policy = BuildPolicies::parse(p.first); - Checks::check_exit(policy != BuildPolicies::UNKNOWN, "Unknown policy found: %s", p.first); - const opt_bool_t status = opt_bool::parse(p.second); - build_info.policies.emplace(policy, status); - } - - return build_info; - } - - const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); - const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); - const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); - const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); - - LinkageType linkage_type_value_of(const std::string& as_string) - - { - if (as_string == "dynamic") - { - return LinkageType::DYNAMIC; - } - - if (as_string == "static") - { - return LinkageType::STATIC; - } - - return LinkageType::UNKNOWN; - } - - std::string to_string(const LinkageType& build_info) - { - switch (build_info) - { - case LinkageType::STATIC: - return "static"; - case LinkageType::DYNAMIC: - return "dynamic"; - default: - Checks::unreachable(); - } - } - - std::string to_string(const ConfigurationType& conf) - { - switch (conf) - { - case ConfigurationType::DEBUG: - return "Debug"; - case ConfigurationType::RELEASE: - return "Release"; - default: - Checks::unreachable(); - } - } - - BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) - { - if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) - { - return DEBUG_STATIC; - } - - if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) - { - return DEBUG_DYNAMIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) - { - return RELEASE_STATIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) - { - return RELEASE_DYNAMIC; - } - - Checks::unreachable(); - } - - BuildInfo read_build_info(const fs::path& filepath) - { - const std::vector> pghs = Paragraphs::get_paragraphs(filepath); - Checks::check_exit(pghs.size() == 1, "Invalid BUILD_INFO file for package"); - - return BuildInfo::create(pghs[0]); - } - - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; - - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; - - std::regex OutdatedDynamicCrt::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - const std::string& OutdatedDynamicCrt::toString() const - { - return this->m_dll_name; - } -} diff --git a/toolsrc/src/BuildPolicies.cpp b/toolsrc/src/BuildPolicies.cpp deleted file mode 100644 index ed0f76c38..000000000 --- a/toolsrc/src/BuildPolicies.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "pch.h" -#include "BuildPolicies.h" -#include "vcpkg_Checks.h" - -namespace vcpkg::PostBuildLint::BuildPolicies -{ - static const std::string NAME_UNKNOWN = "PolicyUnknown"; - static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs"; - - const std::string& type::toString() const - { - switch (this->backing_enum) - { - case DLLS_WITHOUT_LIBS: - return NAME_DLLS_WITHOUT_LIBS; - case UNKNOWN: - return NAME_UNKNOWN; - default: - Checks::unreachable(); - } - } - - const std::string& type::cmake_variable() const - { - static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS"; - - switch (this->backing_enum) - { - case DLLS_WITHOUT_LIBS: - return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; - case UNKNOWN: - Checks::exit_with_message("No CMake command corresponds to UNKNOWN"); - default: - Checks::unreachable(); - } - } - - type::type(): backing_enum(backing_enum_t::UNKNOWN) {} - - const std::vector& values() - { - static const std::vector& v = {UNKNOWN, DLLS_WITHOUT_LIBS}; - return v; - } - - type parse(const std::string& s) - { - if (s == NAME_DLLS_WITHOUT_LIBS) - { - return BuildPolicies::DLLS_WITHOUT_LIBS; - } - - return BuildPolicies::UNKNOWN; - } -} diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp new file mode 100644 index 000000000..e7e976383 --- /dev/null +++ b/toolsrc/src/PostBuildLint.cpp @@ -0,0 +1,680 @@ +#include "pch.h" +#include "vcpkg_paths.h" +#include "package_spec.h" +#include "vcpkg_Files.h" +#include "vcpkg_System.h" +#include "vcpkg_Environment.h" +#include "coff_file_reader.h" +#include "PostBuildLint_BuildInfo.h" + +namespace vcpkg::PostBuildLint +{ + enum class lint_status + { + SUCCESS = 0, + ERROR_DETECTED = 1 + }; + + static lint_status check_for_files_in_include_directory(const fs::path& package_dir) + { + 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."); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_for_files_in_debug_include_directory(const fs::path& package_dir) + { + const fs::path debug_include_dir = package_dir / "debug" / "include"; + std::vector 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()) + { + 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 lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_for_files_in_debug_share_directory(const fs::path& package_dir) + { + const fs::path debug_share = package_dir / "debug" / "share"; + + if (fs::exists(debug_share) && !fs::is_empty(debug_share)) + { + System::println(System::color::warning, "No files should be present in /debug/share"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_folder_lib_cmake(const fs::path& package_dir) + { + 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 moved to just /cmake"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_for_misplaced_cmake_files(const fs::path& package_dir, const package_spec& spec) + { + std::vector 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()) + { + 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 lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_folder_debug_lib_cmake(const fs::path& package_dir) + { + 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 moved to just /debug/cmake"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_for_dlls_in_lib_dirs(const fs::path& package_dir) + { + std::vector 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()) + { + System::println(System::color::warning, "\nThe following dlls were found in /lib and /debug/lib. Please move them to /bin or /debug/bin, respectively."); + Files::print_paths(dlls); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_for_copyright_file(const package_spec& spec, const vcpkg_paths& paths) + { + const fs::path packages_dir = paths.packages / spec.dir(); + const fs::path copyright_file = packages_dir / "share" / spec.name() / "copyright"; + if (fs::exists(copyright_file)) + { + return lint_status::SUCCESS; + } + const fs::path current_buildtrees_dir = paths.buildtrees / spec.name(); + const fs::path current_buildtrees_dir_src = current_buildtrees_dir / "src"; + + std::vector potential_copyright_files; + // Only searching one level deep + for (auto it = fs::recursive_directory_iterator(current_buildtrees_dir_src); it != fs::recursive_directory_iterator(); ++it) + { + if (it.depth() > 1) + { + continue; + } + + const std::string filename = it->path().filename().string(); + if (filename == "LICENSE" || filename == "LICENSE.txt" || filename == "COPYING") + { + potential_copyright_files.push_back(it->path()); + } + } + + 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()); + return lint_status::ERROR_DETECTED; + } + + if (potential_copyright_files.size() > 1) + { + System::println(System::color::warning, "The following files are potential copyright files:"); + Files::print_paths(potential_copyright_files); + } + + System::println(" %s/share/%s/copyright", packages_dir.generic_string(), spec.name()); + return lint_status::ERROR_DETECTED; + } + + static lint_status check_for_exes(const fs::path& package_dir) + { + std::vector 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()) + { + System::println(System::color::warning, "The following EXEs were found in /bin and /debug/bin. EXEs are not valid distribution targets."); + Files::print_paths(exes); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_exports_of_dlls(const std::vector& dlls, const fs::path& dumpbin_exe) + { + std::vector 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()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(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) + { + dlls_with_no_exports.push_back(dll); + } + } + + if (!dlls_with_no_exports.empty()) + { + System::println(System::color::warning, "The following DLLs have 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; + } + + return lint_status::SUCCESS; + } + + static lint_status check_uwp_bit_of_dlls(const std::string& expected_system_name, const std::vector& dlls, const fs::path dumpbin_exe) + { + if (expected_system_name != "uwp") + { + return lint_status::SUCCESS; + } + + std::vector 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()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(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) + { + dlls_with_improper_uwp_bit.push_back(dll); + } + } + + if (!dlls_with_improper_uwp_bit.empty()) + { + System::println(System::color::warning, "The following DLLs do not have the App Container bit set:"); + 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; + } + + return lint_status::SUCCESS; + } + + struct file_and_arch + { + fs::path file; + std::string actual_arch; + }; + + static std::string get_actual_architecture(const MachineType& machine_type) + { + switch (machine_type) + { + case MachineType::AMD64: + 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(machine_type)); + } + } + + static void print_invalid_architecture_files(const std::string& expected_architecture, std::vector binaries_with_invalid_architecture) + { + System::println(System::color::warning, "The following files were built for an incorrect architecture:"); + System::println(""); + for (const file_and_arch& b : binaries_with_invalid_architecture) + { + System::println(" %s", b.file.generic_string()); + System::println("Expected %s, but was: %s", expected_architecture, b.actual_arch); + System::println(""); + } + } + + static lint_status check_dll_architecture(const std::string& expected_architecture, const std::vector& files) + { + std::vector binaries_with_invalid_architecture; + + for (const fs::path& file : files) + { + Checks::check_exit(file.extension() == ".dll", "The file extension was not .dll: %s", file.generic_string()); + COFFFileReader::dll_info info = COFFFileReader::read_dll(file); + const std::string actual_architecture = get_actual_architecture(info.machine_type); + + if (expected_architecture != actual_architecture) + { + binaries_with_invalid_architecture.push_back({file, actual_architecture}); + } + } + + if (!binaries_with_invalid_architecture.empty()) + { + print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_lib_architecture(const std::string& expected_architecture, const std::vector& files) + { + std::vector binaries_with_invalid_architecture; + + for (const fs::path& file : files) + { + Checks::check_exit(file.extension() == ".lib", "The file extension was not .lib: %s", file.generic_string()); + COFFFileReader::lib_info info = COFFFileReader::read_lib(file); + Checks::check_exit(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) + { + binaries_with_invalid_architecture.push_back({file, actual_architecture}); + } + } + + if (!binaries_with_invalid_architecture.empty()) + { + print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_no_dlls_present(const std::vector& dlls) + { + if (dlls.empty()) + { + return lint_status::SUCCESS; + } + + 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 lint_status::ERROR_DETECTED; + } + + static lint_status check_matching_debug_and_release_binaries(const std::vector& debug_binaries, const std::vector& release_binaries) + { + const size_t debug_count = debug_binaries.size(); + const size_t release_count = release_binaries.size(); + if (debug_count == release_count) + { + return lint_status::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("Debug binaries"); + Files::print_paths(debug_binaries); + + System::println("Release binaries"); + Files::print_paths(release_binaries); + + if (debug_count == 0) + { + System::println(System::color::warning, "Debug binaries were not found"); + } + if (release_count == 0) + { + System::println(System::color::warning, "Release binaries were not found"); + } + + System::println(""); + + return lint_status::ERROR_DETECTED; + } + + static lint_status check_lib_files_are_available_if_dlls_are_available(const std::map& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) + { + auto it = policies.find(BuildPolicies::DLLS_WITHOUT_LIBS); + if (it != policies.cend() && it->second == opt_bool_t::DISABLED) + { + return lint_status::SUCCESS; + } + + if (lib_count == 0 && dll_count != 0) + { + System::println(System::color::warning, "Import libs were not present in %s", lib_dir.generic_string()); + System::println(System::color::warning, + "If this is intended, add the following line in the portfile:\n" + " SET(%s disabled)", BuildPolicies::DLLS_WITHOUT_LIBS.cmake_variable()); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_no_subdirectories(const fs::path& dir) + { + const std::vector subdirectories = Files::recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) + { + return fs::is_directory(current); + }); + + if (!subdirectories.empty()) + { + System::println(System::color::warning, "Directory %s should have no subdirectories", dir.generic_string()); + System::println("The following subdirectories were found: "); + Files::print_paths(subdirectories); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_bin_folders_are_not_present_in_static_build(const fs::path& package_dir) + { + const fs::path bin = package_dir / "bin"; + const fs::path debug_bin = package_dir / "debug" / "bin"; + + if (!fs::exists(bin) && !fs::exists(debug_bin)) + { + return lint_status::SUCCESS; + } + + 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.generic_string()); + } + + 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.generic_string()); + } + + 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 lint_status::ERROR_DETECTED; + } + + static lint_status check_no_empty_folders(const fs::path& dir) + { + 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()) + { + 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"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + struct BuildType_and_file + { + fs::path file; + BuildType build_type; + }; + + static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs, const fs::path dumpbin_exe) + { + std::vector bad_build_types = BuildType::values(); + bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end()); + + std::vector 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()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(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) + { + if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex())) + { + libs_with_invalid_crt.push_back({lib, bad_build_type}); + break; + } + } + } + + 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.toString()); + System::println(""); + for (const BuildType_and_file btf : libs_with_invalid_crt) + { + System::println(" %s: %s", btf.file.generic_string(), btf.build_type.toString()); + } + System::println(""); + + System::println(System::color::warning, "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + struct OutdatedDynamicCrt_and_file + { + fs::path file; + OutdatedDynamicCrt outdated_crt; + }; + + static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls, const fs::path dumpbin_exe) + { + const std::vector& outdated_crts = OutdatedDynamicCrt::values(); + + std::vector dlls_with_outdated_crt; + + for (const fs::path& dll : dlls) + { + const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native()); + System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); + Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); + + for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) + { + if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.crt_regex())) + { + dlls_with_outdated_crt.push_back({dll, outdated_crt}); + break; + } + } + } + + if (!dlls_with_outdated_crt.empty()) + { + System::println(System::color::warning, "Detected outdated dynamic CRT in the following files:"); + System::println(""); + for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt) + { + System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.toString()); + } + System::println(""); + + System::println(System::color::warning, "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static lint_status check_no_files_in_package_dir_and_debug_dir(const fs::path& package_dir) + { + std::vector 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"; + Files::non_recursive_find_all_files_in_dir(debug_dir, &misplaced_files); + + 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()); + Files::print_paths(misplaced_files); + System::println(System::color::warning, "Files cannot be present in those directories.\n"); + return lint_status::ERROR_DETECTED; + } + + return lint_status::SUCCESS; + } + + static void operator +=(size_t& left, const lint_status& right) + { + left += static_cast(right); + } + + void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) + { + const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths); + + System::println("-- Performing post-build validation"); + + BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); + const fs::path package_dir = paths.package_dir(spec); + + size_t error_count = 0; + error_count += check_for_files_in_include_directory(package_dir); + error_count += check_for_files_in_debug_include_directory(package_dir); + error_count += check_for_files_in_debug_share_directory(package_dir); + error_count += check_folder_lib_cmake(package_dir); + error_count += check_for_misplaced_cmake_files(package_dir, spec); + error_count += check_folder_debug_lib_cmake(package_dir); + error_count += check_for_dlls_in_lib_dirs(package_dir); + 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 = 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); + + std::vector libs; + libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); + libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); + + error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); + + switch (linkage_type_value_of(build_info.library_linkage)) + { + case LinkageType::DYNAMIC: + { + 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); + + 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 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, dumpbin_exe); + error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); + error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); + + error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); + break; + } + case LinkageType::STATIC: + { + std::vector 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); + + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); + break; + } + case LinkageType::UNKNOWN: + { + error_count += 1; + System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); + break; + } + default: + Checks::unreachable(); + } +#if 0 + 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); + error_count += check_no_files_in_package_dir_and_debug_dir(package_dir); + + 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()); + exit(EXIT_FAILURE); + } + + System::println("-- Performing post-build validation done"); + } +} diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp new file mode 100644 index 000000000..59896e168 --- /dev/null +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -0,0 +1,175 @@ +#include "pch.h" +#include "PostBuildLint_BuildInfo.h" +#include "vcpkg_Checks.h" +#include "opt_bool.h" +#include "vcpkglib_helpers.h" + +namespace vcpkg::PostBuildLint +{ + const ConfigurationType& BuildType::config() const + { + return this->m_config; + } + + const LinkageType& BuildType::linkage() const + { + return this->m_linkage; + } + + std::regex BuildType::crt_regex() const + { + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + std::string BuildType::toString() const + { + const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); + return s; + } + + bool operator==(const BuildType& lhs, const BuildType& rhs) + { + return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); + } + + bool operator!=(const BuildType& lhs, const BuildType& rhs) + { + return !(lhs == rhs); + } + + // + namespace BuildInfoRequiredField + { + static const std::string CRT_LINKAGE = "CRTLinkage"; + static const std::string LIBRARY_LINKAGE = "LibraryLinkage"; + } + + BuildInfo BuildInfo::create(std::unordered_map pgh) + { + BuildInfo build_info; + build_info.crt_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE); + build_info.library_linkage = details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE); + + // The remaining entries are policies + for (const std::unordered_map::value_type& p : pgh) + { + const BuildPolicies::type policy = BuildPolicies::parse(p.first); + Checks::check_exit(policy != BuildPolicies::UNKNOWN, "Unknown policy found: %s", p.first); + const opt_bool_t status = opt_bool::parse(p.second); + build_info.policies.emplace(policy, status); + } + + return build_info; + } + + const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); + const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); + const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); + const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); + + LinkageType linkage_type_value_of(const std::string& as_string) + + { + if (as_string == "dynamic") + { + return LinkageType::DYNAMIC; + } + + if (as_string == "static") + { + return LinkageType::STATIC; + } + + return LinkageType::UNKNOWN; + } + + std::string to_string(const LinkageType& build_info) + { + switch (build_info) + { + case LinkageType::STATIC: + return "static"; + case LinkageType::DYNAMIC: + return "dynamic"; + default: + Checks::unreachable(); + } + } + + std::string to_string(const ConfigurationType& conf) + { + switch (conf) + { + case ConfigurationType::DEBUG: + return "Debug"; + case ConfigurationType::RELEASE: + return "Release"; + default: + Checks::unreachable(); + } + } + + BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) + { + if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) + { + return DEBUG_STATIC; + } + + if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) + { + return DEBUG_DYNAMIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) + { + return RELEASE_STATIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) + { + return RELEASE_DYNAMIC; + } + + Checks::unreachable(); + } + + BuildInfo read_build_info(const fs::path& filepath) + { + const std::vector> pghs = Paragraphs::get_paragraphs(filepath); + Checks::check_exit(pghs.size() == 1, "Invalid BUILD_INFO file for package"); + + return BuildInfo::create(pghs[0]); + } + + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; + + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; + + std::regex OutdatedDynamicCrt::crt_regex() const + { + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + const std::string& OutdatedDynamicCrt::toString() const + { + return this->m_dll_name; + } +} diff --git a/toolsrc/src/PostBuildLint_BuildPolicies.cpp b/toolsrc/src/PostBuildLint_BuildPolicies.cpp new file mode 100644 index 000000000..d7d67c991 --- /dev/null +++ b/toolsrc/src/PostBuildLint_BuildPolicies.cpp @@ -0,0 +1,55 @@ +#include "pch.h" +#include "PostBuildLint_BuildPolicies.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint::BuildPolicies +{ + static const std::string NAME_UNKNOWN = "PolicyUnknown"; + static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs"; + + const std::string& type::toString() const + { + switch (this->backing_enum) + { + case DLLS_WITHOUT_LIBS: + return NAME_DLLS_WITHOUT_LIBS; + case UNKNOWN: + return NAME_UNKNOWN; + default: + Checks::unreachable(); + } + } + + const std::string& type::cmake_variable() const + { + static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS"; + + switch (this->backing_enum) + { + case DLLS_WITHOUT_LIBS: + return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; + case UNKNOWN: + Checks::exit_with_message("No CMake command corresponds to UNKNOWN"); + default: + Checks::unreachable(); + } + } + + type::type(): backing_enum(backing_enum_t::UNKNOWN) {} + + const std::vector& values() + { + static const std::vector& v = {UNKNOWN, DLLS_WITHOUT_LIBS}; + return v; + } + + type parse(const std::string& s) + { + if (s == NAME_DLLS_WITHOUT_LIBS) + { + return BuildPolicies::DLLS_WITHOUT_LIBS; + } + + return BuildPolicies::UNKNOWN; + } +} diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index ccc3c8d9f..c5a278450 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -3,7 +3,7 @@ #include "StatusParagraphs.h" #include "vcpkglib.h" #include "vcpkg_Input.h" -#include "post_build_lint.h" +#include "PostBuildLint.h" #include "vcpkg_Dependencies.h" #include "vcpkg_System.h" #include "vcpkg_Environment.h" diff --git a/toolsrc/src/post_build_lint.cpp b/toolsrc/src/post_build_lint.cpp deleted file mode 100644 index 009f8019c..000000000 --- a/toolsrc/src/post_build_lint.cpp +++ /dev/null @@ -1,680 +0,0 @@ -#include "pch.h" -#include "vcpkg_paths.h" -#include "package_spec.h" -#include "vcpkg_Files.h" -#include "vcpkg_System.h" -#include "vcpkg_Environment.h" -#include "coff_file_reader.h" -#include "BuildInfo.h" - -namespace vcpkg::PostBuildLint -{ - enum class lint_status - { - SUCCESS = 0, - ERROR_DETECTED = 1 - }; - - static lint_status check_for_files_in_include_directory(const fs::path& package_dir) - { - 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."); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_for_files_in_debug_include_directory(const fs::path& package_dir) - { - const fs::path debug_include_dir = package_dir / "debug" / "include"; - std::vector 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()) - { - 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 lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_for_files_in_debug_share_directory(const fs::path& package_dir) - { - const fs::path debug_share = package_dir / "debug" / "share"; - - if (fs::exists(debug_share) && !fs::is_empty(debug_share)) - { - System::println(System::color::warning, "No files should be present in /debug/share"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_folder_lib_cmake(const fs::path& package_dir) - { - 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 moved to just /cmake"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_for_misplaced_cmake_files(const fs::path& package_dir, const package_spec& spec) - { - std::vector 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()) - { - 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 lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_folder_debug_lib_cmake(const fs::path& package_dir) - { - 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 moved to just /debug/cmake"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_for_dlls_in_lib_dirs(const fs::path& package_dir) - { - std::vector 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()) - { - System::println(System::color::warning, "\nThe following dlls were found in /lib and /debug/lib. Please move them to /bin or /debug/bin, respectively."); - Files::print_paths(dlls); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_for_copyright_file(const package_spec& spec, const vcpkg_paths& paths) - { - const fs::path packages_dir = paths.packages / spec.dir(); - const fs::path copyright_file = packages_dir / "share" / spec.name() / "copyright"; - if (fs::exists(copyright_file)) - { - return lint_status::SUCCESS; - } - const fs::path current_buildtrees_dir = paths.buildtrees / spec.name(); - const fs::path current_buildtrees_dir_src = current_buildtrees_dir / "src"; - - std::vector potential_copyright_files; - // Only searching one level deep - for (auto it = fs::recursive_directory_iterator(current_buildtrees_dir_src); it != fs::recursive_directory_iterator(); ++it) - { - if (it.depth() > 1) - { - continue; - } - - const std::string filename = it->path().filename().string(); - if (filename == "LICENSE" || filename == "LICENSE.txt" || filename == "COPYING") - { - potential_copyright_files.push_back(it->path()); - } - } - - 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()); - return lint_status::ERROR_DETECTED; - } - - if (potential_copyright_files.size() > 1) - { - System::println(System::color::warning, "The following files are potential copyright files:"); - Files::print_paths(potential_copyright_files); - } - - System::println(" %s/share/%s/copyright", packages_dir.generic_string(), spec.name()); - return lint_status::ERROR_DETECTED; - } - - static lint_status check_for_exes(const fs::path& package_dir) - { - std::vector 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()) - { - System::println(System::color::warning, "The following EXEs were found in /bin and /debug/bin. EXEs are not valid distribution targets."); - Files::print_paths(exes); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_exports_of_dlls(const std::vector& dlls, const fs::path& dumpbin_exe) - { - std::vector 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()); - System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(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) - { - dlls_with_no_exports.push_back(dll); - } - } - - if (!dlls_with_no_exports.empty()) - { - System::println(System::color::warning, "The following DLLs have 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; - } - - return lint_status::SUCCESS; - } - - static lint_status check_uwp_bit_of_dlls(const std::string& expected_system_name, const std::vector& dlls, const fs::path dumpbin_exe) - { - if (expected_system_name != "uwp") - { - return lint_status::SUCCESS; - } - - std::vector 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()); - System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(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) - { - dlls_with_improper_uwp_bit.push_back(dll); - } - } - - if (!dlls_with_improper_uwp_bit.empty()) - { - System::println(System::color::warning, "The following DLLs do not have the App Container bit set:"); - 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; - } - - return lint_status::SUCCESS; - } - - struct file_and_arch - { - fs::path file; - std::string actual_arch; - }; - - static std::string get_actual_architecture(const MachineType& machine_type) - { - switch (machine_type) - { - case MachineType::AMD64: - 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(machine_type)); - } - } - - static void print_invalid_architecture_files(const std::string& expected_architecture, std::vector binaries_with_invalid_architecture) - { - System::println(System::color::warning, "The following files were built for an incorrect architecture:"); - System::println(""); - for (const file_and_arch& b : binaries_with_invalid_architecture) - { - System::println(" %s", b.file.generic_string()); - System::println("Expected %s, but was: %s", expected_architecture, b.actual_arch); - System::println(""); - } - } - - static lint_status check_dll_architecture(const std::string& expected_architecture, const std::vector& files) - { - std::vector binaries_with_invalid_architecture; - - for (const fs::path& file : files) - { - Checks::check_exit(file.extension() == ".dll", "The file extension was not .dll: %s", file.generic_string()); - COFFFileReader::dll_info info = COFFFileReader::read_dll(file); - const std::string actual_architecture = get_actual_architecture(info.machine_type); - - if (expected_architecture != actual_architecture) - { - binaries_with_invalid_architecture.push_back({file, actual_architecture}); - } - } - - if (!binaries_with_invalid_architecture.empty()) - { - print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_lib_architecture(const std::string& expected_architecture, const std::vector& files) - { - std::vector binaries_with_invalid_architecture; - - for (const fs::path& file : files) - { - Checks::check_exit(file.extension() == ".lib", "The file extension was not .lib: %s", file.generic_string()); - COFFFileReader::lib_info info = COFFFileReader::read_lib(file); - Checks::check_exit(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) - { - binaries_with_invalid_architecture.push_back({file, actual_architecture}); - } - } - - if (!binaries_with_invalid_architecture.empty()) - { - print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_no_dlls_present(const std::vector& dlls) - { - if (dlls.empty()) - { - return lint_status::SUCCESS; - } - - 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 lint_status::ERROR_DETECTED; - } - - static lint_status check_matching_debug_and_release_binaries(const std::vector& debug_binaries, const std::vector& release_binaries) - { - const size_t debug_count = debug_binaries.size(); - const size_t release_count = release_binaries.size(); - if (debug_count == release_count) - { - return lint_status::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("Debug binaries"); - Files::print_paths(debug_binaries); - - System::println("Release binaries"); - Files::print_paths(release_binaries); - - if (debug_count == 0) - { - System::println(System::color::warning, "Debug binaries were not found"); - } - if (release_count == 0) - { - System::println(System::color::warning, "Release binaries were not found"); - } - - System::println(""); - - return lint_status::ERROR_DETECTED; - } - - static lint_status check_lib_files_are_available_if_dlls_are_available(const std::map& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir) - { - auto it = policies.find(BuildPolicies::DLLS_WITHOUT_LIBS); - if (it != policies.cend() && it->second == opt_bool_t::DISABLED) - { - return lint_status::SUCCESS; - } - - if (lib_count == 0 && dll_count != 0) - { - System::println(System::color::warning, "Import libs were not present in %s", lib_dir.generic_string()); - System::println(System::color::warning, - "If this is intended, add the following line in the portfile:\n" - " SET(%s disabled)", BuildPolicies::DLLS_WITHOUT_LIBS.cmake_variable()); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_no_subdirectories(const fs::path& dir) - { - const std::vector subdirectories = Files::recursive_find_matching_paths_in_dir(dir, [&](const fs::path& current) - { - return fs::is_directory(current); - }); - - if (!subdirectories.empty()) - { - System::println(System::color::warning, "Directory %s should have no subdirectories", dir.generic_string()); - System::println("The following subdirectories were found: "); - Files::print_paths(subdirectories); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_bin_folders_are_not_present_in_static_build(const fs::path& package_dir) - { - const fs::path bin = package_dir / "bin"; - const fs::path debug_bin = package_dir / "debug" / "bin"; - - if (!fs::exists(bin) && !fs::exists(debug_bin)) - { - return lint_status::SUCCESS; - } - - 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.generic_string()); - } - - 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.generic_string()); - } - - 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 lint_status::ERROR_DETECTED; - } - - static lint_status check_no_empty_folders(const fs::path& dir) - { - 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()) - { - 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"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - struct BuildType_and_file - { - fs::path file; - BuildType build_type; - }; - - static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector& libs, const fs::path dumpbin_exe) - { - std::vector bad_build_types = BuildType::values(); - bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end()); - - std::vector 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()); - System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(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) - { - if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex())) - { - libs_with_invalid_crt.push_back({lib, bad_build_type}); - break; - } - } - } - - 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.toString()); - System::println(""); - for (const BuildType_and_file btf : libs_with_invalid_crt) - { - System::println(" %s: %s", btf.file.generic_string(), btf.build_type.toString()); - } - System::println(""); - - System::println(System::color::warning, "To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - struct OutdatedDynamicCrt_and_file - { - fs::path file; - OutdatedDynamicCrt outdated_crt; - }; - - static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls, const fs::path dumpbin_exe) - { - const std::vector& outdated_crts = OutdatedDynamicCrt::values(); - - std::vector dlls_with_outdated_crt; - - for (const fs::path& dll : dlls) - { - const std::wstring cmd_line = Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native()); - System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line); - Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line)); - - for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) - { - if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.crt_regex())) - { - dlls_with_outdated_crt.push_back({dll, outdated_crt}); - break; - } - } - } - - if (!dlls_with_outdated_crt.empty()) - { - System::println(System::color::warning, "Detected outdated dynamic CRT in the following files:"); - System::println(""); - for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt) - { - System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.toString()); - } - System::println(""); - - System::println(System::color::warning, "To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static lint_status check_no_files_in_package_dir_and_debug_dir(const fs::path& package_dir) - { - std::vector 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"; - Files::non_recursive_find_all_files_in_dir(debug_dir, &misplaced_files); - - 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()); - Files::print_paths(misplaced_files); - System::println(System::color::warning, "Files cannot be present in those directories.\n"); - return lint_status::ERROR_DETECTED; - } - - return lint_status::SUCCESS; - } - - static void operator +=(size_t& left, const lint_status& right) - { - left += static_cast(right); - } - - void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) - { - const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths); - - System::println("-- Performing post-build validation"); - - BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); - const fs::path package_dir = paths.package_dir(spec); - - size_t error_count = 0; - error_count += check_for_files_in_include_directory(package_dir); - error_count += check_for_files_in_debug_include_directory(package_dir); - error_count += check_for_files_in_debug_share_directory(package_dir); - error_count += check_folder_lib_cmake(package_dir); - error_count += check_for_misplaced_cmake_files(package_dir, spec); - error_count += check_folder_debug_lib_cmake(package_dir); - error_count += check_for_dlls_in_lib_dirs(package_dir); - 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 = 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); - - std::vector libs; - libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend()); - libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend()); - - error_count += check_lib_architecture(spec.target_triplet().architecture(), libs); - - switch (linkage_type_value_of(build_info.library_linkage)) - { - case LinkageType::DYNAMIC: - { - 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); - - 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 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, dumpbin_exe); - error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); - error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); - - error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); - break; - } - case LinkageType::STATIC: - { - std::vector 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); - - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); - break; - } - case LinkageType::UNKNOWN: - { - error_count += 1; - System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); - break; - } - default: - Checks::unreachable(); - } -#if 0 - 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); - error_count += check_no_files_in_package_dir_and_debug_dir(package_dir); - - 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()); - exit(EXIT_FAILURE); - } - - System::println("-- Performing post-build validation done"); - } -} -- cgit v1.2.3 From 7a04aff33e596b843fba2162ab9b05180fc5169c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 13:38:02 -0800 Subject: Split LinkageType into separate h/cpp --- toolsrc/src/PostBuildLint_BuildInfo.cpp | 29 -------------------------- toolsrc/src/PostBuildLint_LinkageType.cpp | 34 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 toolsrc/src/PostBuildLint_LinkageType.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index 59896e168..e15e2ca73 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -68,35 +68,6 @@ namespace vcpkg::PostBuildLint const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); - LinkageType linkage_type_value_of(const std::string& as_string) - - { - if (as_string == "dynamic") - { - return LinkageType::DYNAMIC; - } - - if (as_string == "static") - { - return LinkageType::STATIC; - } - - return LinkageType::UNKNOWN; - } - - std::string to_string(const LinkageType& build_info) - { - switch (build_info) - { - case LinkageType::STATIC: - return "static"; - case LinkageType::DYNAMIC: - return "dynamic"; - default: - Checks::unreachable(); - } - } - std::string to_string(const ConfigurationType& conf) { switch (conf) diff --git a/toolsrc/src/PostBuildLint_LinkageType.cpp b/toolsrc/src/PostBuildLint_LinkageType.cpp new file mode 100644 index 000000000..8a3f35be8 --- /dev/null +++ b/toolsrc/src/PostBuildLint_LinkageType.cpp @@ -0,0 +1,34 @@ +#include "pch.h" +#include "PostBuildLint_LinkageType.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint +{ + LinkageType linkage_type_value_of(const std::string& as_string) + { + if (as_string == "dynamic") + { + return LinkageType::DYNAMIC; + } + + if (as_string == "static") + { + return LinkageType::STATIC; + } + + return LinkageType::UNKNOWN; + } + + std::string to_string(const LinkageType& build_info) + { + switch (build_info) + { + case LinkageType::STATIC: + return "static"; + case LinkageType::DYNAMIC: + return "dynamic"; + default: + Checks::unreachable(); + } + } +} -- cgit v1.2.3 From 4aef2485b9d5cf2dfbb30543963e5714dcc411c4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 13:43:29 -0800 Subject: Split ConfigurationType into separate h/cpp --- toolsrc/src/PostBuildLint_BuildInfo.cpp | 13 ------------- toolsrc/src/PostBuildLint_ConfigurationType.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 toolsrc/src/PostBuildLint_ConfigurationType.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index e15e2ca73..c67c8754f 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -68,19 +68,6 @@ namespace vcpkg::PostBuildLint const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); - std::string to_string(const ConfigurationType& conf) - { - switch (conf) - { - case ConfigurationType::DEBUG: - return "Debug"; - case ConfigurationType::RELEASE: - return "Release"; - default: - Checks::unreachable(); - } - } - BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) { if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) diff --git a/toolsrc/src/PostBuildLint_ConfigurationType.cpp b/toolsrc/src/PostBuildLint_ConfigurationType.cpp new file mode 100644 index 000000000..9c3499cac --- /dev/null +++ b/toolsrc/src/PostBuildLint_ConfigurationType.cpp @@ -0,0 +1,19 @@ +#include "pch.h" +#include "PostBuildLint_ConfigurationType.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint +{ + std::string to_string(const ConfigurationType& conf) + { + switch (conf) + { + case ConfigurationType::DEBUG: + return "Debug"; + case ConfigurationType::RELEASE: + return "Release"; + default: + Checks::unreachable(); + } + } +} -- cgit v1.2.3 From 0a0a17b7f9eb2aca7f999de1c4b8c63428e1eadf Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 13:49:28 -0800 Subject: Split BuildType into separate h/cpp --- toolsrc/src/PostBuildLint_BuildInfo.cpp | 62 ------------------------------ toolsrc/src/PostBuiltLint_BuildType.cpp | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 62 deletions(-) create mode 100644 toolsrc/src/PostBuiltLint_BuildType.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index c67c8754f..1d6d45e10 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -6,38 +6,6 @@ namespace vcpkg::PostBuildLint { - const ConfigurationType& BuildType::config() const - { - return this->m_config; - } - - const LinkageType& BuildType::linkage() const - { - return this->m_linkage; - } - - std::regex BuildType::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - std::string BuildType::toString() const - { - const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); - return s; - } - - bool operator==(const BuildType& lhs, const BuildType& rhs) - { - return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); - } - - bool operator!=(const BuildType& lhs, const BuildType& rhs) - { - return !(lhs == rhs); - } - // namespace BuildInfoRequiredField { @@ -63,36 +31,6 @@ namespace vcpkg::PostBuildLint return build_info; } - const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); - const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); - const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); - const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); - - BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) - { - if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) - { - return DEBUG_STATIC; - } - - if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) - { - return DEBUG_DYNAMIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) - { - return RELEASE_STATIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) - { - return RELEASE_DYNAMIC; - } - - Checks::unreachable(); - } - BuildInfo read_build_info(const fs::path& filepath) { const std::vector> pghs = Paragraphs::get_paragraphs(filepath); diff --git a/toolsrc/src/PostBuiltLint_BuildType.cpp b/toolsrc/src/PostBuiltLint_BuildType.cpp new file mode 100644 index 000000000..b4e199aee --- /dev/null +++ b/toolsrc/src/PostBuiltLint_BuildType.cpp @@ -0,0 +1,68 @@ +#include "pch.h" +#include "PostBuildLint_BuildType.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint +{ + const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); + const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); + const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); + const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); + + BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) + { + if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) + { + return DEBUG_STATIC; + } + + if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) + { + return DEBUG_DYNAMIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) + { + return RELEASE_STATIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) + { + return RELEASE_DYNAMIC; + } + + Checks::unreachable(); + } + + const ConfigurationType& BuildType::config() const + { + return this->m_config; + } + + const LinkageType& BuildType::linkage() const + { + return this->m_linkage; + } + + std::regex BuildType::crt_regex() const + { + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + std::string BuildType::toString() const + { + const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); + return s; + } + + bool operator==(const BuildType& lhs, const BuildType& rhs) + { + return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); + } + + bool operator!=(const BuildType& lhs, const BuildType& rhs) + { + return !(lhs == rhs); + } +} -- cgit v1.2.3 From 1d34facb84812bd478f2320857a5a7a3ed327bbf Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 13:54:08 -0800 Subject: Split OutdatedDynamicCrt into separate h/cpp --- toolsrc/src/PostBuildLint.cpp | 2 ++ toolsrc/src/PostBuildLint_BuildInfo.cpp | 29 -------------------- toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp | 35 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index e7e976383..5954089e9 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -6,6 +6,8 @@ #include "vcpkg_Environment.h" #include "coff_file_reader.h" #include "PostBuildLint_BuildInfo.h" +#include "PostBuildLint_BuildType.h" +#include "PostBuildLint_OutdatedDynamicCrt.h" namespace vcpkg::PostBuildLint { diff --git a/toolsrc/src/PostBuildLint_BuildInfo.cpp b/toolsrc/src/PostBuildLint_BuildInfo.cpp index 1d6d45e10..63107acd1 100644 --- a/toolsrc/src/PostBuildLint_BuildInfo.cpp +++ b/toolsrc/src/PostBuildLint_BuildInfo.cpp @@ -39,33 +39,4 @@ namespace vcpkg::PostBuildLint return BuildInfo::create(pghs[0]); } - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; - - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; - - std::regex OutdatedDynamicCrt::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - const std::string& OutdatedDynamicCrt::toString() const - { - return this->m_dll_name; - } } diff --git a/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp b/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp new file mode 100644 index 000000000..67965cd93 --- /dev/null +++ b/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp @@ -0,0 +1,35 @@ +#include "pch.h" +#include "PostBuildLint_OutdatedDynamicCrt.h" + +namespace vcpkg::PostBuildLint +{ + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; + + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; + const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; + + std::regex OutdatedDynamicCrt::crt_regex() const + { + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + const std::string& OutdatedDynamicCrt::toString() const + { + return this->m_dll_name; + } +} -- cgit v1.2.3 From fdc885fb06cb6dcb201099b6520a73fb5034da34 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 1 Feb 2017 18:20:49 -0800 Subject: Fix filename --- toolsrc/src/PostBuildLint_BuildType.cpp | 68 +++++++++++++++++++++++++++++++++ toolsrc/src/PostBuiltLint_BuildType.cpp | 68 --------------------------------- 2 files changed, 68 insertions(+), 68 deletions(-) create mode 100644 toolsrc/src/PostBuildLint_BuildType.cpp delete mode 100644 toolsrc/src/PostBuiltLint_BuildType.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint_BuildType.cpp b/toolsrc/src/PostBuildLint_BuildType.cpp new file mode 100644 index 000000000..b4e199aee --- /dev/null +++ b/toolsrc/src/PostBuildLint_BuildType.cpp @@ -0,0 +1,68 @@ +#include "pch.h" +#include "PostBuildLint_BuildType.h" +#include "vcpkg_Checks.h" + +namespace vcpkg::PostBuildLint +{ + const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); + const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); + const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); + const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); + + BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) + { + if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) + { + return DEBUG_STATIC; + } + + if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) + { + return DEBUG_DYNAMIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) + { + return RELEASE_STATIC; + } + + if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) + { + return RELEASE_DYNAMIC; + } + + Checks::unreachable(); + } + + const ConfigurationType& BuildType::config() const + { + return this->m_config; + } + + const LinkageType& BuildType::linkage() const + { + return this->m_linkage; + } + + std::regex BuildType::crt_regex() const + { + const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); + return r; + } + + std::string BuildType::toString() const + { + const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); + return s; + } + + bool operator==(const BuildType& lhs, const BuildType& rhs) + { + return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); + } + + bool operator!=(const BuildType& lhs, const BuildType& rhs) + { + return !(lhs == rhs); + } +} diff --git a/toolsrc/src/PostBuiltLint_BuildType.cpp b/toolsrc/src/PostBuiltLint_BuildType.cpp deleted file mode 100644 index b4e199aee..000000000 --- a/toolsrc/src/PostBuiltLint_BuildType.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "pch.h" -#include "PostBuildLint_BuildType.h" -#include "vcpkg_Checks.h" - -namespace vcpkg::PostBuildLint -{ - const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)"); - const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)"); - const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])"); - const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])"); - - BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage) - { - if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC) - { - return DEBUG_STATIC; - } - - if (config == ConfigurationType::DEBUG && linkage == LinkageType::DYNAMIC) - { - return DEBUG_DYNAMIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::STATIC) - { - return RELEASE_STATIC; - } - - if (config == ConfigurationType::RELEASE && linkage == LinkageType::DYNAMIC) - { - return RELEASE_DYNAMIC; - } - - Checks::unreachable(); - } - - const ConfigurationType& BuildType::config() const - { - return this->m_config; - } - - const LinkageType& BuildType::linkage() const - { - return this->m_linkage; - } - - std::regex BuildType::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - std::string BuildType::toString() const - { - const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage)); - return s; - } - - bool operator==(const BuildType& lhs, const BuildType& rhs) - { - return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage(); - } - - bool operator!=(const BuildType& lhs, const BuildType& rhs) - { - return !(lhs == rhs); - } -} -- cgit v1.2.3 From 5fa7aba4d21ce35b65da02243697319bd23bf2f6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 3 Feb 2017 18:25:43 -0800 Subject: [vcpkg remove] Fix remove --purge not applying to not-installed packages --- toolsrc/src/commands_remove.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp index 7e8608e72..f49104d1e 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -196,26 +196,29 @@ namespace vcpkg::Commands::Remove for (const package_spec_with_remove_plan& action : remove_plan) { - if (action.plan.plan_type == remove_plan_type::NOT_INSTALLED) + const std::string display_name = action.spec.display_name(); + + switch (action.plan.plan_type) { - System::println(System::color::success, "Package %s is not installed", action.spec); + case remove_plan_type::NOT_INSTALLED: + System::println(System::color::success, "Package %s is not installed", display_name); + break; + case remove_plan_type::REMOVE: + System::println("Removing package %s... ", display_name); + remove_package(paths, action.spec, &status_db); + System::println(System::color::success, "Removing package %s... done", display_name); + break; + case remove_plan_type::UNKNOWN: + default: + Checks::unreachable(); } - else if (action.plan.plan_type == remove_plan_type::REMOVE) - { - const std::string display_name = action.spec.display_name(); - System::println("Removing package %s... ", display_name); - remove_package(paths, action.spec, &status_db); - System::println(System::color::success, "Removing package %s... done", display_name); - if (alsoRemoveFolderFromPackages) - { - System::println("Purging package %s... ", display_name); - delete_directory(paths.packages / action.spec.dir()); - System::println(System::color::success, "Purging package %s... done", display_name); - } + if (alsoRemoveFolderFromPackages) + { + System::println("Purging package %s... ", display_name); + delete_directory(paths.packages / action.spec.dir()); + System::println(System::color::success, "Purging package %s... done", display_name); } - else - Checks::unreachable(); } exit(EXIT_SUCCESS); -- cgit v1.2.3 From f9616c6994ccf66e2a64e2d62e6a1408694c190c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 7 Feb 2017 17:02:57 -0800 Subject: Add new Policy: Empty Package --- toolsrc/src/PostBuildLint.cpp | 92 +++++++++++++++++------------ toolsrc/src/PostBuildLint_BuildPolicies.cpp | 13 +++- 2 files changed, 65 insertions(+), 40 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 5954089e9..533e28fcf 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -582,16 +582,21 @@ namespace vcpkg::PostBuildLint left += static_cast(right); } - void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) + static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths) { const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths); - System::println("-- Performing post-build validation"); - BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); const fs::path package_dir = paths.package_dir(spec); size_t error_count = 0; + + auto it = build_info.policies.find(BuildPolicies::EMPTY_PACKAGE); + if (it != build_info.policies.cend() && it->second == opt_bool_t::ENABLED) + { + return error_count; + } + error_count += check_for_files_in_include_directory(package_dir); error_count += check_for_files_in_debug_include_directory(package_dir); error_count += check_for_files_in_debug_share_directory(package_dir); @@ -620,56 +625,65 @@ namespace vcpkg::PostBuildLint switch (linkage_type_value_of(build_info.library_linkage)) { - case LinkageType::DYNAMIC: - { - 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"); + case LinkageType::DYNAMIC: + { + 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); + 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 dlls; - dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); - dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); + std::vector 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, dumpbin_exe); - error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); - error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); + error_count += check_exports_of_dlls(dlls, dumpbin_exe); + error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); + error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); - error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); - break; - } - case LinkageType::STATIC: - { - std::vector dlls; - Files::recursive_find_files_with_extension_in_dir(package_dir, ".dll", &dlls); - error_count += check_no_dlls_present(dlls); + error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); + break; + } + case LinkageType::STATIC: + { + std::vector 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); + error_count += check_bin_folders_are_not_present_in_static_build(package_dir); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); - break; - } - case LinkageType::UNKNOWN: - { - error_count += 1; - System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); - break; - } - default: - Checks::unreachable(); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); + break; + } + case LinkageType::UNKNOWN: + { + error_count += 1; + System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); + break; + } + default: + 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); error_count += check_no_files_in_package_dir_and_debug_dir(package_dir); + return error_count; + } + + void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths) + { + System::println("-- Performing post-build validation"); + + const size_t error_count = perform_all_checks_and_return_error_count(spec, paths); + if (error_count != 0) { const fs::path portfile = paths.ports / spec.name() / "portfile.cmake"; diff --git a/toolsrc/src/PostBuildLint_BuildPolicies.cpp b/toolsrc/src/PostBuildLint_BuildPolicies.cpp index d7d67c991..4e5ac3cea 100644 --- a/toolsrc/src/PostBuildLint_BuildPolicies.cpp +++ b/toolsrc/src/PostBuildLint_BuildPolicies.cpp @@ -5,12 +5,15 @@ namespace vcpkg::PostBuildLint::BuildPolicies { static const std::string NAME_UNKNOWN = "PolicyUnknown"; + static const std::string NAME_EMPTY_PACKAGE = "PolicyEmptyPackage"; static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs"; const std::string& type::toString() const { switch (this->backing_enum) { + case EMPTY_PACKAGE: + return NAME_EMPTY_PACKAGE; case DLLS_WITHOUT_LIBS: return NAME_DLLS_WITHOUT_LIBS; case UNKNOWN: @@ -22,10 +25,13 @@ namespace vcpkg::PostBuildLint::BuildPolicies const std::string& type::cmake_variable() const { + static const std::string CMAKE_VARIABLE_EMPTY_PACKAGE = "VCPKG_POLICY_EMPTY_PACKAGE"; static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS"; switch (this->backing_enum) { + case EMPTY_PACKAGE: + return CMAKE_VARIABLE_EMPTY_PACKAGE; case DLLS_WITHOUT_LIBS: return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS; case UNKNOWN: @@ -39,12 +45,17 @@ namespace vcpkg::PostBuildLint::BuildPolicies const std::vector& values() { - static const std::vector& v = {UNKNOWN, DLLS_WITHOUT_LIBS}; + static const std::vector& v = {UNKNOWN, EMPTY_PACKAGE, DLLS_WITHOUT_LIBS}; return v; } type parse(const std::string& s) { + if (s == NAME_EMPTY_PACKAGE) + { + return BuildPolicies::EMPTY_PACKAGE; + } + if (s == NAME_DLLS_WITHOUT_LIBS) { return BuildPolicies::DLLS_WITHOUT_LIBS; -- cgit v1.2.3 From d36a1b7cb0b8be59e7826a7a699d9951e91abc2c Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 7 Feb 2017 22:57:37 -0800 Subject: Remove OutdatedDynamicCrt enum. Replace with vector --- toolsrc/src/PostBuildLint.cpp | 107 +++++++++++++++-------- toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp | 35 -------- 2 files changed, 69 insertions(+), 73 deletions(-) delete mode 100644 toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 533e28fcf..7986d913a 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -7,7 +7,6 @@ #include "coff_file_reader.h" #include "PostBuildLint_BuildInfo.h" #include "PostBuildLint_BuildType.h" -#include "PostBuildLint_OutdatedDynamicCrt.h" namespace vcpkg::PostBuildLint { @@ -17,6 +16,38 @@ namespace vcpkg::PostBuildLint ERROR_DETECTED = 1 }; + struct OutdatedDynamicCrt + { + std::string name; + std::regex regex; + }; + + const std::vector& get_outdated_dynamic_crts() + { + static const std::vector v = { + {"msvcp100.dll", std::regex(R"(msvcp100\.dll)")}, + {"msvcp100d.dll", std::regex(R"(msvcp100d\.dll)")}, + {"msvcp110.dll", std::regex(R"(msvcp110\.dll)")}, + {"msvcp110_win.dll", std::regex(R"(msvcp110_win\.dll)")}, + {"msvcp120.dll", std::regex(R"(msvcp120\.dll)")}, + {"msvcp120_clr0400.dll", std::regex(R"(msvcp120_clr0400\.dll)")}, + {"msvcp60.dll", std::regex(R"(msvcp60\.dll)")}, + {"msvcp60.dll", std::regex(R"(msvcp60\.dll)")}, + + {"msvcr100.dll", std::regex(R"(msvcr100\.dll)")}, + {"msvcr100d.dll", std::regex(R"(msvcr100d\.dll)")}, + {"msvcr100_clr0400.dll", std::regex(R"(msvcr100_clr0400\.dll)")}, + {"msvcr110.dll", std::regex(R"(msvcr110\.dll)")}, + {"msvcr120.dll", std::regex(R"(msvcr120\.dll)")}, + {"msvcr120_clr0400.dll", std::regex(R"(msvcr120_clr0400\.dll)")}, + {"msvcrt.dll", std::regex(R"(msvcrt\.dll)")}, + {"msvcrt20.dll", std::regex(R"(msvcrt20\.dll)")}, + {"msvcrt40.dll", std::regex(R"(msvcrt40\.dll)")} + }; + + return v; + } + static lint_status check_for_files_in_include_directory(const fs::path& package_dir) { const fs::path include_dir = package_dir / "include"; @@ -516,7 +547,7 @@ namespace vcpkg::PostBuildLint static lint_status check_outdated_crt_linkage_of_dlls(const std::vector& dlls, const fs::path dumpbin_exe) { - const std::vector& outdated_crts = OutdatedDynamicCrt::values(); + const std::vector& outdated_crts = get_outdated_dynamic_crts(); std::vector dlls_with_outdated_crt; @@ -528,7 +559,7 @@ namespace vcpkg::PostBuildLint for (const OutdatedDynamicCrt& outdated_crt : outdated_crts) { - if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.crt_regex())) + if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.regex)) { dlls_with_outdated_crt.push_back({dll, outdated_crt}); break; @@ -542,7 +573,7 @@ namespace vcpkg::PostBuildLint System::println(""); for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt) { - System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.toString()); + System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.name); } System::println(""); @@ -625,47 +656,47 @@ namespace vcpkg::PostBuildLint switch (linkage_type_value_of(build_info.library_linkage)) { - case LinkageType::DYNAMIC: - { - 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"); + case LinkageType::DYNAMIC: + { + 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); + 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 dlls; - dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); - dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); + std::vector 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, dumpbin_exe); - error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); - error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); + error_count += check_exports_of_dlls(dlls, dumpbin_exe); + error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); + error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); - error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); - break; - } - case LinkageType::STATIC: - { - std::vector dlls; - Files::recursive_find_files_with_extension_in_dir(package_dir, ".dll", &dlls); - error_count += check_no_dlls_present(dlls); + error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); + break; + } + case LinkageType::STATIC: + { + std::vector 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); + error_count += check_bin_folders_are_not_present_in_static_build(package_dir); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); - break; - } - case LinkageType::UNKNOWN: - { - error_count += 1; - System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); - break; - } - default: - Checks::unreachable(); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, linkage_type_value_of(build_info.crt_linkage)), debug_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, linkage_type_value_of(build_info.crt_linkage)), release_libs, dumpbin_exe); + break; + } + case LinkageType::UNKNOWN: + { + error_count += 1; + System::println(System::color::warning, "Unknown library_linkage architecture: [ %s ]", build_info.library_linkage); + break; + } + default: + Checks::unreachable(); } #if 0 error_count += check_no_subdirectories(package_dir / "lib"); diff --git a/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp b/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp deleted file mode 100644 index 67965cd93..000000000 --- a/toolsrc/src/PostBuildLint_OutdatedDynamicCrt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "pch.h" -#include "PostBuildLint_OutdatedDynamicCrt.h" - -namespace vcpkg::PostBuildLint -{ - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100_DLL = OutdatedDynamicCrt("msvcp100.dll", R"(msvcp100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP100D_DLL = OutdatedDynamicCrt("msvcp100d.dll", R"(msvcp100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_DLL = OutdatedDynamicCrt("msvcp110.dll", R"(msvcp110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP110_WIN_DLL = OutdatedDynamicCrt("msvcp110_win.dll", R"(msvcp110_win\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_DLL = OutdatedDynamicCrt("msvcp120.dll", R"(msvcp120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP120_CLR0400_DLL = OutdatedDynamicCrt("msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP60_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCP_WIN_DLL = OutdatedDynamicCrt("msvcp60.dll", R"(msvcp60\.dll)");; - - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_DLL = OutdatedDynamicCrt("msvcr100.dll", R"(msvcr100\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100D_DLL = OutdatedDynamicCrt("msvcr100d.dll", R"(msvcr100d\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR100_CLR0400_DLL = OutdatedDynamicCrt("msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR110_DLL = OutdatedDynamicCrt("msvcr110.dll", R"(msvcr110\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_DLL = OutdatedDynamicCrt("msvcr120.dll", R"(msvcr120\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCR120_CLR0400_DLL = OutdatedDynamicCrt("msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT_DLL = OutdatedDynamicCrt("msvcrt.dll", R"(msvcrt\.dll)"); - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT20_DLL = OutdatedDynamicCrt("msvcrt20.dll", R"(msvcrt20\.dll)");; - const OutdatedDynamicCrt OutdatedDynamicCrt::MSVCRT40_DLL = OutdatedDynamicCrt("msvcrt40.dll", R"(msvcrt40\.dll)");; - - std::regex OutdatedDynamicCrt::crt_regex() const - { - const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase); - return r; - } - - const std::string& OutdatedDynamicCrt::toString() const - { - return this->m_dll_name; - } -} -- cgit v1.2.3 From a9f7fc6e90feaad50c1221ef9bd56e2620302215 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 8 Feb 2017 12:36:32 -0800 Subject: Make regex for OutdatedDyanmicCRTs case insensitive --- toolsrc/src/PostBuildLint.cpp | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 7986d913a..90bd55843 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -20,29 +20,32 @@ namespace vcpkg::PostBuildLint { std::string name; 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)) {} }; const std::vector& get_outdated_dynamic_crts() { static const std::vector v = { - {"msvcp100.dll", std::regex(R"(msvcp100\.dll)")}, - {"msvcp100d.dll", std::regex(R"(msvcp100d\.dll)")}, - {"msvcp110.dll", std::regex(R"(msvcp110\.dll)")}, - {"msvcp110_win.dll", std::regex(R"(msvcp110_win\.dll)")}, - {"msvcp120.dll", std::regex(R"(msvcp120\.dll)")}, - {"msvcp120_clr0400.dll", std::regex(R"(msvcp120_clr0400\.dll)")}, - {"msvcp60.dll", std::regex(R"(msvcp60\.dll)")}, - {"msvcp60.dll", std::regex(R"(msvcp60\.dll)")}, - - {"msvcr100.dll", std::regex(R"(msvcr100\.dll)")}, - {"msvcr100d.dll", std::regex(R"(msvcr100d\.dll)")}, - {"msvcr100_clr0400.dll", std::regex(R"(msvcr100_clr0400\.dll)")}, - {"msvcr110.dll", std::regex(R"(msvcr110\.dll)")}, - {"msvcr120.dll", std::regex(R"(msvcr120\.dll)")}, - {"msvcr120_clr0400.dll", std::regex(R"(msvcr120_clr0400\.dll)")}, - {"msvcrt.dll", std::regex(R"(msvcrt\.dll)")}, - {"msvcrt20.dll", std::regex(R"(msvcrt20\.dll)")}, - {"msvcrt40.dll", std::regex(R"(msvcrt40\.dll)")} + {"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; -- cgit v1.2.3