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/commands_installation.cpp') 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 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/commands_installation.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'toolsrc/src/commands_installation.cpp') 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")", -- 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/commands_installation.cpp') 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/commands_installation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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/commands_installation.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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 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/commands_installation.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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."); -- 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/commands_installation.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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) { -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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."); -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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) { -- 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_installation.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); -- 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 ++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 47 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); } -- 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 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); -- 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 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); -- 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/commands_installation.cpp') 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 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/commands_installation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); } -- 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 ++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'toolsrc/src/commands_installation.cpp') 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"); -- 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/commands_installation.cpp') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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(), -- 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_installation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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()) -- 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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}); -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_installation.cpp') 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); } } -- 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/commands_installation.cpp') 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 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/commands_installation.cpp') 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 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 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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) -- 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/commands_installation.cpp') 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 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/commands_installation.cpp') 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_installation.cpp | 141 +--------------------------------- 1 file changed, 1 insertion(+), 140 deletions(-) (limited to 'toolsrc/src/commands_installation.cpp') 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_installation.cpp | 241 ---------------------------------- 1 file changed, 241 deletions(-) delete mode 100644 toolsrc/src/commands_installation.cpp (limited to 'toolsrc/src/commands_installation.cpp') 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