Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/vcpkg-test/mockcmakevarprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace vcpkg::Test
void load_generic_triplet_vars(Triplet triplet) const override;
void load_dep_info_vars(View<PackageSpec> specs, Triplet) const override;
void load_tag_vars(View<FullPackageSpec> specs, Triplet host_triplet) const override;
Optional<const SMap&> get_generic_triplet_vars(Triplet triplet) const override;
Optional<const SMap&> get_dep_info_vars(const PackageSpec& spec) const override;
Optional<const SMap&> get_tag_vars(const PackageSpec& spec) const override;
const SMap* get_generic_triplet_vars(Triplet triplet) const override;
const SMap* get_dep_info_vars(const PackageSpec& spec) const override;
const SMap* get_tag_vars(const PackageSpec& spec) const override;

mutable std::unordered_map<PackageSpec, SMap> dep_info_vars;
mutable std::unordered_map<PackageSpec, SMap> tag_vars;
Expand Down
10 changes: 3 additions & 7 deletions include/vcpkg/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,11 @@ namespace vcpkg::Util
}

template<class Map, class Key>
Optional<const typename Map::mapped_type&> lookup_value(const Map& map, Key&& key)
const typename Map::mapped_type* lookup_value(const Map& map, Key&& key)
{
const auto it = map.find(static_cast<Key&&>(key));
if (it == map.end())
{
return nullopt;
}

return it->second;
if (it == map.end()) return nullptr;
return &it->second;
}

template<class Map, class Key>
Expand Down
6 changes: 3 additions & 3 deletions include/vcpkg/cmakevars.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace vcpkg::CMakeVars
{
virtual ~CMakeVarProvider() = default;

virtual Optional<const CMakeVars&> get_generic_triplet_vars(Triplet triplet) const = 0;
virtual const CMakeVars* get_generic_triplet_vars(Triplet triplet) const = 0;

virtual Optional<const CMakeVars&> get_dep_info_vars(const PackageSpec& spec) const = 0;
virtual const CMakeVars* get_dep_info_vars(const PackageSpec& spec) const = 0;

const CMakeVars& get_or_load_dep_info_vars(const PackageSpec& spec, Triplet host_triplet) const;

virtual Optional<const CMakeVars&> get_tag_vars(const PackageSpec& spec) const = 0;
virtual const CMakeVars* get_tag_vars(const PackageSpec& spec) const = 0;

virtual void load_generic_triplet_vars(Triplet triplet) const = 0;

Expand Down
6 changes: 3 additions & 3 deletions include/vcpkg/commands.build.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ namespace vcpkg
{
// These should always be known if an AbiInfo exists
std::unique_ptr<PreBuildInfo> pre_build_info;
Optional<const Toolset&> toolset;
const Toolset* toolset = nullptr;
// These might not be known if compiler tracking is turned off or the port is --editable
Optional<const CompilerInfo&> compiler_info;
Optional<const std::string&> triplet_abi;
const CompilerInfo* compiler_info = nullptr;
const std::string* triplet_abi = nullptr;
std::string package_abi;
Optional<Path> abi_tag_file;
std::vector<Path> relative_port_files;
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace vcpkg

RequestType request_type;

Optional<const BinaryParagraph&> core_paragraph() const;
const BinaryParagraph* core_paragraph() const;
std::vector<PackageSpec> dependencies() const;

private:
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/portfileprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace vcpkg
struct IOverlayProvider
{
virtual ~IOverlayProvider() = default;
virtual Optional<const SourceControlFileAndLocation&> get_control_file(StringView port_name) const = 0;
virtual const SourceControlFileAndLocation* get_control_file(StringView port_name) const = 0;
};

struct IFullOverlayProvider : IOverlayProvider
Expand Down
4 changes: 2 additions & 2 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ namespace vcpkg
std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs;
Json::Object extra_features_info;

Optional<const FeatureParagraph&> find_feature(StringView featurename) const;
Optional<const std::vector<Dependency>&> find_dependencies_for_feature(const std::string& featurename) const;
const FeatureParagraph* find_feature(StringView featurename) const;
const std::vector<Dependency>* find_dependencies_for_feature(const std::string& featurename) const;
bool has_qualified_dependencies() const;

ExpectedL<Unit> check_against_feature_flags(const Path& origin,
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace vcpkg
ExpectedL<Unit> git_read_tree(const Path& destination, StringView tree, const Path& dot_git_dir) const;
ExpectedL<Path> git_extract_tree_from_remote_registry(StringView tree) const;

Optional<const ManifestAndPath&> get_manifest() const;
const ManifestAndPath* get_manifest() const;
bool manifest_mode_enabled() const;
const ConfigurationAndSource& get_configuration() const;
std::unique_ptr<RegistrySet> make_registry_set() const;
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ Build-Depends: bzip
ipa.abi_info = AbiInfo{};
ipa.abi_info.get()->package_abi = "packageabi";
std::string tripletabi("tripletabi");
ipa.abi_info.get()->triplet_abi = tripletabi;
ipa.abi_info.get()->triplet_abi = &tripletabi;
CompilerInfo compiler_info;
compiler_info.hash = "compilerhash";
compiler_info.id = "compilerid";
compiler_info.version = "compilerversion";
ipa.abi_info.get()->compiler_info = compiler_info;
ipa.abi_info.get()->compiler_info = &compiler_info;

FeedReference ref2 = make_nugetref(ipa, "prefix_");

Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ struct MockOverlayProvider : IOverlayProvider
MockOverlayProvider(const MockOverlayProvider&) = delete;
MockOverlayProvider& operator=(const MockOverlayProvider&) = delete;

virtual Optional<const SourceControlFileAndLocation&> get_control_file(StringView name) const override
virtual const SourceControlFileAndLocation* get_control_file(StringView name) const override
{
auto it = mappings.find(name);
if (it == mappings.end())
{
return nullopt;
return nullptr;
}

return it->second;
return &it->second;
}

SourceControlFileAndLocation& emplace(const std::string& name,
Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg-test/mockcmakevarsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ namespace vcpkg::Test
}
}

Optional<const std::unordered_map<std::string, std::string>&> MockCMakeVarProvider::get_generic_triplet_vars(
const std::unordered_map<std::string, std::string>* MockCMakeVarProvider::get_generic_triplet_vars(
Triplet triplet) const
{
return Util::lookup_value(generic_triplet_vars, triplet);
}

Optional<const std::unordered_map<std::string, std::string>&> MockCMakeVarProvider::get_dep_info_vars(
const std::unordered_map<std::string, std::string>* MockCMakeVarProvider::get_dep_info_vars(
const PackageSpec& spec) const
{
return Util::lookup_value(dep_info_vars, spec);
}

Optional<const std::unordered_map<std::string, std::string>&> MockCMakeVarProvider::get_tag_vars(
const std::unordered_map<std::string, std::string>* MockCMakeVarProvider::get_tag_vars(
const PackageSpec& spec) const
{
return Util::lookup_value(tag_vars, spec);
Expand Down
14 changes: 7 additions & 7 deletions src/vcpkg-test/plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ TEST_CASE ("basic export scheme", "[plan]")

REQUIRE(plan.size() == 1);
REQUIRE(plan.at(0).spec.name() == "a");
REQUIRE(plan.at(0).core_paragraph().has_value());
REQUIRE(plan.at(0).core_paragraph() != nullptr);
}

TEST_CASE ("basic export scheme with recurse", "[plan]")
Expand All @@ -1431,10 +1431,10 @@ TEST_CASE ("basic export scheme with recurse", "[plan]")

REQUIRE(plan.size() == 2);
REQUIRE(plan.at(0).spec.name() == "a");
REQUIRE(plan.at(0).core_paragraph().has_value());
REQUIRE(plan.at(0).core_paragraph() != nullptr);

REQUIRE(plan.at(1).spec.name() == "b");
REQUIRE(plan.at(1).core_paragraph().has_value());
REQUIRE(plan.at(1).core_paragraph() != nullptr);
}

TEST_CASE ("basic export scheme with bystander", "[plan]")
Expand All @@ -1452,7 +1452,7 @@ TEST_CASE ("basic export scheme with bystander", "[plan]")

REQUIRE(plan.size() == 1);
REQUIRE(plan.at(0).spec.name() == "a");
REQUIRE(plan.at(0).core_paragraph().has_value());
REQUIRE(plan.at(0).core_paragraph() != nullptr);
}

TEST_CASE ("basic export scheme with missing", "[plan]")
Expand All @@ -1466,7 +1466,7 @@ TEST_CASE ("basic export scheme with missing", "[plan]")

REQUIRE(plan.size() == 1);
REQUIRE(plan.at(0).spec.name() == "a");
REQUIRE(!plan.at(0).core_paragraph().has_value());
REQUIRE(plan.at(0).core_paragraph() == nullptr);
}

TEST_CASE ("basic export scheme with features", "[plan]")
Expand All @@ -1485,8 +1485,8 @@ TEST_CASE ("basic export scheme with features", "[plan]")
REQUIRE(plan.size() == 2);

REQUIRE(plan.at(0).spec.name() == "b");
REQUIRE(plan.at(0).core_paragraph().has_value());
REQUIRE(plan.at(0).core_paragraph() != nullptr);

REQUIRE(plan.at(1).spec.name() == "a");
REQUIRE(plan.at(1).core_paragraph().has_value());
REQUIRE(plan.at(1).core_paragraph() != nullptr);
}
6 changes: 4 additions & 2 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,9 @@ std::string vcpkg::generate_nuspec(const Path& package_dir,
auto& scf = *action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO).source_control_file;
auto& version = scf.core_paragraph->version;
const auto& abi_info = action.abi_info.value_or_exit(VCPKG_LINE_INFO);
const auto& compiler_info = abi_info.compiler_info.value_or_exit(VCPKG_LINE_INFO);
Checks::check_exit(VCPKG_LINE_INFO, abi_info.compiler_info != nullptr);
const auto& compiler_info = *abi_info.compiler_info;
Checks::check_exit(VCPKG_LINE_INFO, abi_info.triplet_abi != nullptr);
auto ref = make_nugetref(action, id_prefix);
std::string description =
Strings::concat("NOT FOR DIRECT USE. Automatically generated cache package.\n\n",
Expand All @@ -3271,7 +3273,7 @@ std::string vcpkg::generate_nuspec(const Path& package_dir,
"\nCXX Compiler version: ",
compiler_info.version,
"\nTriplet/Compiler hash: ",
abi_info.triplet_abi.value_or_exit(VCPKG_LINE_INFO),
*abi_info.triplet_abi,
"\nFeatures:",
Strings::join(",", action.feature_list, [](const std::string& s) { return " " + s; }),
"\nDependencies:\n");
Expand Down
23 changes: 12 additions & 11 deletions src/vcpkg/cmakevars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ namespace vcpkg::CMakeVars
const std::unordered_map<std::string, std::string>& CMakeVarProvider::get_or_load_dep_info_vars(
const PackageSpec& spec, Triplet host_triplet) const
{
auto maybe_vars = get_dep_info_vars(spec);
if (!maybe_vars.has_value())
auto vars = get_dep_info_vars(spec);
if (!vars)
{
load_dep_info_vars({&spec, 1}, host_triplet);
maybe_vars = get_dep_info_vars(spec);
vars = get_dep_info_vars(spec);
Checks::check_exit(VCPKG_LINE_INFO, vars != nullptr);
}
return maybe_vars.value_or_exit(VCPKG_LINE_INFO);

return *vars;
}

namespace
Expand All @@ -53,14 +55,13 @@ namespace vcpkg::CMakeVars

void load_tag_vars(View<FullPackageSpec> specs, Triplet host_triplet) const override;

Optional<const std::unordered_map<std::string, std::string>&> get_generic_triplet_vars(
const std::unordered_map<std::string, std::string>* get_generic_triplet_vars(
Triplet triplet) const override;

Optional<const std::unordered_map<std::string, std::string>&> get_dep_info_vars(
const std::unordered_map<std::string, std::string>* get_dep_info_vars(
const PackageSpec& spec) const override;

Optional<const std::unordered_map<std::string, std::string>&> get_tag_vars(
const PackageSpec& spec) const override;
const std::unordered_map<std::string, std::string>* get_tag_vars(const PackageSpec& spec) const override;

public:
Path create_tag_extraction_file(const View<FullPackageSpec> spec_abi_settings) const;
Expand Down Expand Up @@ -380,19 +381,19 @@ endfunction()
}
}

Optional<const std::unordered_map<std::string, std::string>&> TripletCMakeVarProvider::get_generic_triplet_vars(
const std::unordered_map<std::string, std::string>* TripletCMakeVarProvider::get_generic_triplet_vars(
Triplet triplet) const
{
return Util::lookup_value(generic_triplet_vars, triplet);
}

Optional<const std::unordered_map<std::string, std::string>&> TripletCMakeVarProvider::get_dep_info_vars(
const std::unordered_map<std::string, std::string>* TripletCMakeVarProvider::get_dep_info_vars(
const PackageSpec& spec) const
{
return Util::lookup_value(dep_resolution_vars, spec);
}

Optional<const std::unordered_map<std::string, std::string>&> TripletCMakeVarProvider::get_tag_vars(
const std::unordered_map<std::string, std::string>* TripletCMakeVarProvider::get_tag_vars(
const PackageSpec& spec) const
{
return Util::lookup_value(tag_vars, spec);
Expand Down
3 changes: 1 addition & 2 deletions src/vcpkg/commands.acquire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace vcpkg
std::vector<std::string> ecmascript_args;
ecmascript_args.emplace_back("acquire");
forward_common_artifacts_arguments(ecmascript_args, parsed);
auto maybe_versions = Util::lookup_value(parsed.multisettings, SwitchVersion);
if (auto versions = maybe_versions.get())
if (const auto* versions = Util::lookup_value(parsed.multisettings, SwitchVersion))
{
if (versions->size() != parsed.command_arguments.size())
{
Expand Down
5 changes: 2 additions & 3 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ namespace vcpkg
std::vector<std::string> ecmascript_args;
ecmascript_args.emplace_back("add");
ecmascript_args.emplace_back(artifact_name);
auto maybe_version = Util::lookup_value(parsed.settings, SwitchVersion);
if (auto version = maybe_version.get())
if (const auto* version = Util::lookup_value(parsed.settings, SwitchVersion))
{
ecmascript_args.emplace_back("--version");
ecmascript_args.emplace_back(*version);
Expand All @@ -65,7 +64,7 @@ namespace vcpkg

if (selector == "port")
{
auto manifest = paths.get_manifest().get();
const auto* manifest = paths.get_manifest();
if (!manifest)
{
Checks::msg_exit_with_message(
Expand Down
Loading
Loading