mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 03:27:12 +01:00
[vcpkg] Replace explicit bulk operations with fmap
This commit is contained in:
parent
74fbd3acd5
commit
74f788d04f
@ -5,11 +5,10 @@
|
||||
|
||||
namespace vcpkg::Input
|
||||
{
|
||||
package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text);
|
||||
|
||||
std::vector<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const std::string& example_text);
|
||||
package_spec check_and_get_package_spec(
|
||||
const std::string& package_spec_as_string,
|
||||
const triplet& default_target_triplet,
|
||||
cstring_view example_text);
|
||||
|
||||
void check_triplet(const triplet& t, const vcpkg_paths& paths);
|
||||
|
||||
void check_triplets(const std::vector<package_spec>& triplets, const vcpkg_paths& paths);
|
||||
}
|
||||
|
24
toolsrc/include/vcpkg_Util.h
Normal file
24
toolsrc/include/vcpkg_Util.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace vcpkg::Util
|
||||
{
|
||||
template<class Cont, class Func>
|
||||
using FmapOut = decltype(std::declval<Func>()(std::declval<Cont>()[0]));
|
||||
|
||||
template<class Cont, class Func, class Out = FmapOut<Cont, Func>>
|
||||
std::vector<Out> fmap(const Cont& xs, Func&& f)
|
||||
{
|
||||
using O = decltype(f(xs[0]));
|
||||
|
||||
std::vector<O> ret;
|
||||
ret.reserve(xs.size());
|
||||
|
||||
for (auto&& x : xs)
|
||||
ret.push_back(f(x));
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
#include "vcpkg_System.h"
|
||||
#include "vcpkg_Dependencies.h"
|
||||
#include "vcpkg_Input.h"
|
||||
#include "vcpkg_Util.h"
|
||||
#include "Paragraphs.h"
|
||||
|
||||
namespace vcpkg::Commands::Install
|
||||
@ -185,16 +186,25 @@ namespace vcpkg::Commands::Install
|
||||
|
||||
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
|
||||
{
|
||||
// input sanitization
|
||||
static const std::string example = Commands::Help::create_example_string("install zlib zlib:x64-windows curl boost");
|
||||
args.check_min_arg_count(1, example);
|
||||
std::vector<package_spec> specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example);
|
||||
Input::check_triplets(specs, paths);
|
||||
|
||||
auto specs = Util::fmap(args.command_arguments, [&](auto&& arg)
|
||||
{
|
||||
auto spec = Input::check_and_get_package_spec(arg, default_target_triplet, example);
|
||||
Input::check_triplet(spec.target_triplet(), paths);
|
||||
return spec;
|
||||
});
|
||||
|
||||
args.check_and_get_optional_command_arguments({});
|
||||
|
||||
// create the plan
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
std::vector<package_spec_with_install_plan> install_plan = Dependencies::create_install_plan(paths, specs, status_db);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
|
||||
|
||||
// log the plan
|
||||
std::string specs_string = install_plan[0].spec.toString();
|
||||
for (size_t i = 1; i < install_plan.size(); ++i)
|
||||
{
|
||||
@ -203,6 +213,7 @@ namespace vcpkg::Commands::Install
|
||||
}
|
||||
TrackProperty("installplan", specs_string);
|
||||
|
||||
// execute the plan
|
||||
for (const package_spec_with_install_plan& action : install_plan)
|
||||
{
|
||||
try
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "vcpkg_System.h"
|
||||
#include "vcpkg_Input.h"
|
||||
#include "vcpkg_Dependencies.h"
|
||||
#include "vcpkg_Util.h"
|
||||
|
||||
namespace vcpkg::Commands::Remove
|
||||
{
|
||||
@ -168,8 +169,14 @@ namespace vcpkg::Commands::Remove
|
||||
{
|
||||
static const std::string example = Commands::Help::create_example_string("remove zlib zlib:x64-windows curl boost");
|
||||
args.check_min_arg_count(1, example);
|
||||
std::vector<package_spec> specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example);
|
||||
Input::check_triplets(specs, paths);
|
||||
|
||||
auto specs = Util::fmap(args.command_arguments, [&](auto&& arg)
|
||||
{
|
||||
auto spec = Input::check_and_get_package_spec(arg, default_target_triplet, example);
|
||||
Input::check_triplet(spec.target_triplet(), paths);
|
||||
return spec;
|
||||
});
|
||||
|
||||
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({ OPTION_PURGE, OPTION_RECURSE, OPTION_DRY_RUN });
|
||||
const bool alsoRemoveFolderFromPackages = options.find(OPTION_PURGE) != options.end();
|
||||
const bool isRecursive = options.find(OPTION_RECURSE) != options.end();
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace vcpkg::Input
|
||||
{
|
||||
package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text)
|
||||
package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, cstring_view example_text)
|
||||
{
|
||||
const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string);
|
||||
expected<package_spec> expected_spec = package_spec::from_string(as_lowercase, default_target_triplet);
|
||||
@ -21,17 +21,6 @@ namespace vcpkg::Input
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
std::vector<package_spec> check_and_get_package_specs(const std::vector<std::string>& package_specs_as_strings, const triplet& default_target_triplet, const std::string& example_text)
|
||||
{
|
||||
std::vector<package_spec> specs;
|
||||
for (const std::string& spec : package_specs_as_strings)
|
||||
{
|
||||
specs.push_back(check_and_get_package_spec(spec, default_target_triplet, example_text));
|
||||
}
|
||||
|
||||
return specs;
|
||||
}
|
||||
|
||||
void check_triplet(const triplet& t, const vcpkg_paths& paths)
|
||||
{
|
||||
if (!paths.is_valid_triplet(t))
|
||||
@ -42,12 +31,4 @@ namespace vcpkg::Input
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
void check_triplets(const std::vector<package_spec>& triplets, const vcpkg_paths& paths)
|
||||
{
|
||||
for (const package_spec& spec : triplets)
|
||||
{
|
||||
check_triplet(spec.target_triplet(), paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,6 +178,7 @@
|
||||
<ClInclude Include="..\include\vcpkg_paths.h" />
|
||||
<ClInclude Include="..\include\vcpkg_Strings.h" />
|
||||
<ClInclude Include="..\include\vcpkg_System.h" />
|
||||
<ClInclude Include="..\include\vcpkg_Util.h" />
|
||||
<ClInclude Include="..\include\version_t.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -308,5 +308,8 @@
|
||||
<ClInclude Include="..\include\version_t.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\vcpkg_Util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user