aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_install.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-04-27 18:08:52 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-04-27 18:59:57 -0700
commit1e9471a1489156720362ef12e1ec6849ea9b45b6 (patch)
tree46f0f35093ecd18034c9f9463d6f8b7aa590ade0 /toolsrc/src/commands_install.cpp
parent75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f (diff)
downloadvcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.tar.gz
vcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.zip
Run clang-format over the cpp files
Diffstat (limited to 'toolsrc/src/commands_install.cpp')
-rw-r--r--toolsrc/src/commands_install.cpp173
1 files changed, 92 insertions, 81 deletions
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index d1d9cec5f..bc77d6a9f 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -1,13 +1,14 @@
#include "pch.h"
-#include "vcpkg_Commands.h"
-#include "vcpkglib.h"
+
+#include "Paragraphs.h"
#include "metrics.h"
-#include "vcpkg_Files.h"
-#include "vcpkg_System.h"
+#include "vcpkg_Commands.h"
#include "vcpkg_Dependencies.h"
+#include "vcpkg_Files.h"
#include "vcpkg_Input.h"
+#include "vcpkg_System.h"
#include "vcpkg_Util.h"
-#include "Paragraphs.h"
+#include "vcpkglib.h"
namespace vcpkg::Commands::Install
{
@@ -26,22 +27,15 @@ namespace vcpkg::Commands::Install
return dirs;
}
- const fs::path& InstallDir::destination() const
- {
- return this->m_destination;
- }
+ const fs::path& InstallDir::destination() const { return this->m_destination; }
- const std::string& InstallDir::destination_subdirectory() const
- {
- return this->m_destination_subdirectory;
- }
+ const std::string& InstallDir::destination_subdirectory() const { return this->m_destination_subdirectory; }
- const fs::path& InstallDir::listfile() const
- {
- return this->m_listfile;
- }
+ const fs::path& InstallDir::listfile() const { return this->m_listfile; }
- void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& destination_dir)
+ void install_files_and_write_listfile(Files::Filesystem& fs,
+ const fs::path& source_dir,
+ const InstallDir& destination_dir)
{
std::vector<std::string> output;
std::error_code ec;
@@ -51,12 +45,15 @@ namespace vcpkg::Commands::Install
const std::string& destination_subdirectory = destination_dir.destination_subdirectory();
const fs::path& listfile = destination_dir.listfile();
- Checks::check_exit(VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string());
+ Checks::check_exit(
+ VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string());
fs.create_directories(destination, ec);
- Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string());
+ Checks::check_exit(
+ VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string());
const fs::path listfile_parent = listfile.parent_path();
fs.create_directories(listfile_parent, ec);
- Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string());
+ Checks::check_exit(
+ VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string());
output.push_back(Strings::format(R"(%s/)", destination_subdirectory));
auto files = fs.get_files_recursive(source_dir);
@@ -70,7 +67,8 @@ namespace vcpkg::Commands::Install
}
const std::string filename = file.filename().generic_string();
- if (fs::is_regular_file(status) && (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0))
+ if (fs::is_regular_file(status) &&
+ (_stricmp(filename.c_str(), "CONTROL") == 0 || _stricmp(filename.c_str(), "BUILD_INFO") == 0))
{
// Do not copy the control file
continue;
@@ -96,7 +94,10 @@ namespace vcpkg::Commands::Install
{
if (fs.exists(target))
{
- System::println(System::Color::warning, "File %s was already present and will be overwritten", target.u8string(), ec.message());
+ System::println(System::Color::warning,
+ "File %s was already present and will be overwritten",
+ target.u8string(),
+ ec.message());
}
fs.copy_file(file, target, fs::copy_options::overwrite_existing, ec);
if (ec)
@@ -129,7 +130,8 @@ namespace vcpkg::Commands::Install
}
};
- static std::vector<std::string> extract_files_in_triplet(const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet)
+ static std::vector<std::string> extract_files_in_triplet(
+ const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet)
{
std::vector<std::string> output;
for (const StatusParagraphAndAssociatedFiles& t : pgh_and_files)
@@ -146,21 +148,22 @@ namespace vcpkg::Commands::Install
return output;
}
- static SortedVector<std::string> build_list_of_package_files(const Files::Filesystem& fs, const fs::path& package_dir)
+ static SortedVector<std::string> build_list_of_package_files(const Files::Filesystem& fs,
+ const fs::path& package_dir)
{
const std::vector<fs::path> package_file_paths = fs.get_files_recursive(package_dir);
const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash
- auto package_files = Util::fmap(package_file_paths, [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);
- });
+ auto package_files = Util::fmap(package_file_paths, [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 SortedVector<std::string>(std::move(package_files));
}
- static SortedVector<std::string> build_list_of_installed_files(const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet)
+ static SortedVector<std::string> build_list_of_installed_files(
+ const std::vector<StatusParagraphAndAssociatedFiles>& pgh_and_files, const Triplet& triplet)
{
std::vector<std::string> 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
@@ -171,7 +174,9 @@ namespace vcpkg::Commands::Install
static void print_plan(const std::map<InstallPlanType, std::vector<const InstallPlanAction*>>& group_by_plan_type)
{
- static constexpr std::array<InstallPlanType, 3> order = { InstallPlanType::ALREADY_INSTALLED, InstallPlanType::BUILD_AND_INSTALL, InstallPlanType::INSTALL };
+ static constexpr std::array<InstallPlanType, 3> order = { InstallPlanType::ALREADY_INSTALLED,
+ InstallPlanType::BUILD_AND_INSTALL,
+ InstallPlanType::INSTALL };
for (const InstallPlanType plan_type : order)
{
@@ -183,10 +188,9 @@ namespace vcpkg::Commands::Install
std::vector<const InstallPlanAction*> cont = it->second;
std::sort(cont.begin(), cont.end(), &InstallPlanAction::compare_by_name);
- const std::string as_string = Strings::join("\n", cont, [](const InstallPlanAction* p)
- {
- return Dependencies::to_output_string(p->request_type, p->spec.to_string());
- });
+ const std::string as_string = Strings::join("\n", cont, [](const InstallPlanAction* p) {
+ return Dependencies::to_output_string(p->request_type, p->spec.to_string());
+ });
switch (plan_type)
{
@@ -199,8 +203,7 @@ namespace vcpkg::Commands::Install
case InstallPlanType::INSTALL:
System::println("The following packages will be installed:\n%s", as_string);
continue;
- default:
- Checks::unreachable(VCPKG_LINE_INFO);
+ default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
}
@@ -211,18 +214,22 @@ namespace vcpkg::Commands::Install
const Triplet& triplet = binary_paragraph.spec.triplet();
const std::vector<StatusParagraphAndAssociatedFiles> pgh_and_files = get_installed_files(paths, *status_db);
- const SortedVector<std::string> package_files = build_list_of_package_files(paths.get_filesystem(), package_dir);
+ const SortedVector<std::string> package_files =
+ build_list_of_package_files(paths.get_filesystem(), package_dir);
const SortedVector<std::string> installed_files = build_list_of_installed_files(pgh_and_files, triplet);
std::vector<std::string> intersection;
- std::set_intersection(package_files.begin(), package_files.end(),
- installed_files.begin(), installed_files.end(),
+ std::set_intersection(package_files.begin(),
+ package_files.end(),
+ installed_files.begin(),
+ installed_files.end(),
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",
+ 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::print("\n ");
@@ -245,9 +252,8 @@ namespace vcpkg::Commands::Install
write_update(paths, source_paragraph);
status_db->insert(std::make_unique<StatusParagraph>(source_paragraph));
- const InstallDir install_dir = InstallDir::from_destination_root(paths.installed,
- triplet.to_string(),
- paths.listfile_path(binary_paragraph));
+ const InstallDir install_dir = InstallDir::from_destination_root(
+ paths.installed, triplet.to_string(), paths.listfile_path(binary_paragraph));
install_files_and_write_listfile(paths.get_filesystem(), package_dir, install_dir);
@@ -261,17 +267,18 @@ namespace vcpkg::Commands::Install
static const std::string OPTION_DRY_RUN = "--dry-run";
// input sanitization
- static const std::string example = Commands::Help::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);
- const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg)
- {
- return Input::check_and_get_package_spec(arg, default_triplet, example);
- });
+ const std::vector<PackageSpec> specs = Util::fmap(args.command_arguments, [&](auto&& arg) {
+ return Input::check_and_get_package_spec(arg, default_triplet, example);
+ });
for (auto&& spec : specs)
Input::check_triplet(spec.triplet(), paths);
- const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_DRY_RUN });
+ const std::unordered_set<std::string> options =
+ args.check_and_get_optional_command_arguments({ OPTION_DRY_RUN });
const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend();
// create the plan
@@ -280,21 +287,23 @@ namespace vcpkg::Commands::Install
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
// log the plan
- const std::string specs_string = Strings::join(",", install_plan, [](const InstallPlanAction& plan) { return plan.spec.to_string(); });
+ const std::string specs_string =
+ Strings::join(",", install_plan, [](const InstallPlanAction& plan) { return plan.spec.to_string(); });
Metrics::track_property("installplan", specs_string);
std::map<InstallPlanType, std::vector<const InstallPlanAction*>> group_by_plan_type;
Util::group_by(install_plan, &group_by_plan_type, [](const InstallPlanAction& p) { return p.plan_type; });
print_plan(group_by_plan_type);
- const bool has_non_user_requested_packages = Util::find_if(install_plan, [](const InstallPlanAction& package)-> bool
- {
- return package.request_type != RequestType::USER_REQUESTED;
- }) != install_plan.cend();
+ const bool has_non_user_requested_packages =
+ Util::find_if(install_plan, [](const InstallPlanAction& package) -> bool {
+ return package.request_type != RequestType::USER_REQUESTED;
+ }) != install_plan.cend();
if (has_non_user_requested_packages)
{
- System::println(System::Color::warning, "Additional packages (*) need to be installed to complete this operation.");
+ System::println(System::Color::warning,
+ "Additional packages (*) need to be installed to complete this operation.");
}
if (dryRun)
@@ -315,36 +324,38 @@ namespace vcpkg::Commands::Install
System::println(System::Color::success, "Package %s is already installed", display_name);
break;
case InstallPlanType::BUILD_AND_INSTALL:
+ {
+ System::println("Building package %s... ", display_name);
+ const auto result = Commands::Build::build_package(
+ action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
+ action.spec,
+ paths,
+ paths.port_dir(action.spec),
+ status_db);
+ if (result.code != Build::BuildResult::SUCCEEDED)
{
- System::println("Building package %s... ", display_name);
- const auto result = Commands::Build::build_package(
- action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
- action.spec,
- paths,
- paths.port_dir(action.spec),
- status_db);
- if (result.code != Build::BuildResult::SUCCEEDED)
- {
- System::println(System::Color::error, Build::create_error_message(result.code, action.spec));
- System::println(Build::create_user_troubleshooting_message(action.spec));
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- System::println(System::Color::success, "Building package %s... done", display_name);
-
- const BinaryParagraph bpgh = Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name);
- install_package(paths, bpgh, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
+ System::println(System::Color::error,
+ Build::create_error_message(result.code, action.spec));
+ System::println(Build::create_user_troubleshooting_message(action.spec));
+ Checks::exit_fail(VCPKG_LINE_INFO);
}
+ System::println(System::Color::success, "Building package %s... done", display_name);
+
+ const BinaryParagraph bpgh =
+ Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
+ System::println("Installing package %s... ", display_name);
+ install_package(paths, bpgh, &status_db);
+ System::println(System::Color::success, "Installing package %s... done", display_name);
+ break;
+ }
case InstallPlanType::INSTALL:
System::println("Installing package %s... ", display_name);
- install_package(paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
+ install_package(
+ paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
System::println(System::Color::success, "Installing package %s... done", display_name);
break;
case InstallPlanType::UNKNOWN:
- default:
- Checks::unreachable(VCPKG_LINE_INFO);
+ default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
catch (const std::exception& e)