diff options
| author | sdcb <sdflysha@qq.com> | 2017-01-14 10:55:19 +0800 |
|---|---|---|
| committer | sdcb <sdflysha@qq.com> | 2017-01-14 10:55:19 +0800 |
| commit | beec44ae8d09b31a6c137bd580bd05111adc3077 (patch) | |
| tree | e444c555f550471800becec72001ce4428b95a89 /toolsrc/src | |
| parent | c104c8966f7bf2fa6576d25cc3631894008c94e1 (diff) | |
| parent | 1e4e45ffcee2774a6cbe87527c140fa2107bd29d (diff) | |
| download | vcpkg-beec44ae8d09b31a6c137bd580bd05111adc3077.tar.gz vcpkg-beec44ae8d09b31a6c137bd580bd05111adc3077.zip | |
Merge remote-tracking branch 'refs/remotes/upstream/master'
Diffstat (limited to 'toolsrc/src')
24 files changed, 349 insertions, 317 deletions
diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp new file mode 100644 index 000000000..48239587d --- /dev/null +++ b/toolsrc/src/commands_available_commands.cpp @@ -0,0 +1,44 @@ +#include "vcpkg_Commands.h" + +namespace vcpkg::Commands +{ + const std::vector<package_name_and_function<command_type_a>>& get_available_commands_type_a() + { + static std::vector<package_name_and_function<command_type_a>> t = { + {"install", &Install::perform_and_exit}, + {"remove", &Remove::perform_and_exit}, + {"build", &Build::perform_and_exit}, + {"build_external", &BuildExternal::perform_and_exit} + }; + return t; + } + + const std::vector<package_name_and_function<command_type_b>>& get_available_commands_type_b() + { + static std::vector<package_name_and_function<command_type_b>> t = { + {"/?", &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; + } + + const std::vector<package_name_and_function<command_type_c>>& get_available_commands_type_c() + { + static std::vector<package_name_and_function<command_type_c>> t = { + {"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 new file mode 100644 index 000000000..72ebb264b --- /dev/null +++ b/toolsrc/src/commands_build.cpp @@ -0,0 +1,128 @@ +#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 <fstream> + +namespace vcpkg::Commands::Build +{ + 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; + } + + 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(); + + 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 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("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<std::string> 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<SourceParagraph> 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<std::string> first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); + + std::vector<package_spec> 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<package_spec_with_install_plan> 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_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 new file mode 100644 index 000000000..09a9256d7 --- /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::Commands::BuildExternal +{ + 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(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)"); + args.check_exact_arg_count(2, example); + + expected<package_spec> 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<SourceParagraph> maybe_spgh = try_load_port(port_dir); + if (auto spgh = maybe_spgh.get()) + { + 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::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 1a10b93cf..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 +namespace vcpkg::Commands::Cache { static std::vector<BinaryParagraph> read_all_binary_paragraphs(const vcpkg_paths& paths) { @@ -34,10 +34,10 @@ namespace vcpkg 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", 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<BinaryParagraph> binary_paragraphs = read_all_binary_paragraphs(paths); diff --git a/toolsrc/src/commands_contact.cpp b/toolsrc/src/commands_contact.cpp new file mode 100644 index 000000000..3e3ebc2b4 --- /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::Contact +{ + 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()); + exit(EXIT_SUCCESS); + } +} diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp index ad00cd676..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 +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 = 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 fbf4eab62..3297b5295 100644 --- a/toolsrc/src/commands_edit.cpp +++ b/toolsrc/src/commands_edit.cpp @@ -2,15 +2,16 @@ #include "vcpkg_System.h" #include "vcpkg_Input.h" -namespace vcpkg +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 = 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); 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"); @@ -27,7 +28,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_hash.cpp b/toolsrc/src/commands_hash.cpp index 0e3e8a77c..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 +namespace vcpkg::Commands::Hash { static void do_file_hash(fs::path const& path, std::wstring const& hashType) { @@ -23,10 +23,10 @@ namespace vcpkg 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", 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 fd02d948e..e4769752c 100644 --- a/toolsrc/src/commands_help.cpp +++ b/toolsrc/src/commands_help.cpp @@ -1,20 +1,69 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include "vcpkg_info.h" -namespace vcpkg +namespace vcpkg::Commands::Help { - void version_command(const vcpkg_cmd_arguments& args) + void help_topic_valid_triplet(const vcpkg_paths& paths) { - 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); + 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 help_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void print_usage() + { + System::println( + "Commands:\n" + " vcpkg search [pat] Search for packages available to be built\n" + " vcpkg install <pkg> Install a package\n" + " vcpkg remove <pkg> Uninstall a package. \n" + " vcpkg remove --purge <pkg> Uninstall and delete a package. \n" + " vcpkg list List installed packages\n" + " vcpkg update Display list of packages for updating\n" + " vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512\n" + "\n" + "%s" // Integration help + "\n" + " vcpkg edit <pkg> Open up a port for editing (uses %%EDITOR%%, default 'code')\n" + " vcpkg import <pkg> Import a pre-built library\n" + " vcpkg create <pkg> <url>\n" + " [archivename] Create a new package\n" + " vcpkg owns <pat> 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 <controlfile>\n" + //" --create-binary-control <controlfile>\n" + //"\n" + "Options:\n" + " --triplet <t> Specify the target architecture triplet.\n" + " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" + "\n" + " --vcpkg-root <path> Specify the vcpkg root directory\n" + " (default: %%VCPKG_ROOT%%)\n" + "\n" + "For more help (including examples) see the accompanying README.md." + , Integrate::INTEGRATE_COMMAND_HELPSTRING); + } + + 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()) @@ -35,21 +84,4 @@ namespace vcpkg } 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:"); - 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 new file mode 100644 index 000000000..0c7ce15bb --- /dev/null +++ b/toolsrc/src/commands_helpers.cpp @@ -0,0 +1,7 @@ +#include "vcpkg_Commands.h" +#include "vcpkg_System.h" + +namespace vcpkg::Commands::Helpers +{ + +} diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index 3832f0e7b..14e83e75f 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Files.h" #include <fstream> -namespace vcpkg +namespace vcpkg::Commands::Import { struct Binaries { @@ -75,9 +75,9 @@ namespace vcpkg 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 = 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_installation.cpp b/toolsrc/src/commands_install.cpp index c239bf06c..ff517d9b1 100644 --- a/toolsrc/src/commands_installation.cpp +++ b/toolsrc/src/commands_install.cpp @@ -1,72 +1,17 @@ #include "vcpkg_Commands.h" #include "vcpkg.h" -#include <fstream> #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 +namespace vcpkg::Commands::Install { 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<std::string> output; @@ -238,9 +183,9 @@ namespace vcpkg status_db.insert(std::make_unique<StatusParagraph>(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 = 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); @@ -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::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); @@ -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<std::string> 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<SourceParagraph> 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<std::string> first_level_deps = filter_dependencies(spgh.depends, spec.target_triplet()); - - std::vector<package_spec> 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<package_spec_with_install_plan> 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<package_spec> 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<SourceParagraph> 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); - } } diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integrate.cpp index e7e5b2d8d..2bd5027ec 100644 --- a/toolsrc/src/commands_integration.cpp +++ b/toolsrc/src/commands_integrate.cpp @@ -10,7 +10,7 @@ #include "vcpkg_System.h" #include "vcpkg_Files.h" -namespace vcpkg +namespace vcpkg::Commands::Integrate { static const std::array<fs::path, 2> 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 cc51232e9..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 +namespace vcpkg::Commands::List { static void do_print(const StatusParagraph& pgh) { @@ -13,10 +13,10 @@ namespace vcpkg 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", 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_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 <pkg> Install a package\n" - " vcpkg remove <pkg> Uninstall a package. \n" - " vcpkg remove --purge <pkg> Uninstall and delete a package. \n" - " vcpkg list List installed packages\n" - " vcpkg update Display list of packages for updating\n" - " vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512\n" - "\n" - "%s" // Integration help - "\n" - " vcpkg edit <pkg> Open up a port for editing (uses %%EDITOR%%, default 'code')\n" - " vcpkg import <pkg> Import a pre-built library\n" - " vcpkg create <pkg> <url>\n" - " [archivename] Create a new package\n" - " vcpkg owns <pat> 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 <controlfile>\n" - //" --create-binary-control <controlfile>\n" - //"\n" - "Options:\n" - " --triplet <t> Specify the target architecture triplet.\n" - " (default: %%VCPKG_DEFAULT_TRIPLET%%, see 'vcpkg help triplet')\n" - "\n" - " --vcpkg-root <path> Specify the vcpkg root directory\n" - " (default: %%VCPKG_ROOT%%)\n" - "\n" - "For more help (including examples) see the accompanying README.md." - , INTEGRATE_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<package_name_and_function<command_type_a>>& get_available_commands_type_a() - { - static std::vector<package_name_and_function<command_type_a>> t = { - {"install", install_command}, - {"remove", remove_command}, - {"build", build_command}, - {"build_external", build_external_command} - }; - return t; - } - - const std::vector<package_name_and_function<command_type_b>>& get_available_commands_type_b() - { - static std::vector<package_name_and_function<command_type_b>> 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<package_name_and_function<command_type_c>>& get_available_commands_type_c() - { - static std::vector<package_name_and_function<command_type_c>> 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..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 +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 } } - 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", 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 46c6c90c7..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 +namespace vcpkg::Commands::PortsDiff { static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, std::string>& names_and_versions) { @@ -97,9 +97,9 @@ namespace vcpkg 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", 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 445213fc2..23d981fc1 100644 --- a/toolsrc/src/commands_remove.cpp +++ b/toolsrc/src/commands_remove.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Input.h" #include <fstream> -namespace vcpkg +namespace vcpkg::Commands::Remove { static const std::string OPTION_PURGE = "--purge"; @@ -166,9 +166,9 @@ namespace vcpkg 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 = 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<std::string> 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..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 +namespace vcpkg::Commands::Search { static std::vector<SourceParagraph> read_all_source_paragraphs(const vcpkg_paths& paths) { @@ -40,9 +40,10 @@ namespace vcpkg 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", create_example_string("search png")); + static const std::string example = Strings::format("The argument should be a substring to search for, or no argument to display all libraries.\n%s", + Commands::Help::create_example_string("search png")); args.check_max_arg_count(1, example); const std::vector<SourceParagraph> source_paragraphs = read_all_source_paragraphs(paths); diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index a4ab7c6e7..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 +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 new file mode 100644 index 000000000..e98251601 --- /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::Version +{ + void perform_and_exit(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); + } +} diff --git a/toolsrc/src/main.cpp b/toolsrc/src/main.cpp index 7703c541f..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); - print_usage(); + Commands::Help::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::Help::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..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()); - 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 a3648668f..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"); - 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"); - 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"); - print_usage(); + Commands::Help::print_usage(); exit(EXIT_FAILURE); } option_field = new_setting; |
