Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More expressive checks in triplet #1379

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vcpkg/base/json.h>
#include <vcpkg/base/path.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/stringview.h>

#include <vcpkg/paragraphparser.h>
Expand Down Expand Up @@ -209,6 +210,10 @@ namespace vcpkg
SchemedVersion schemed_version() const { return {scheme(), to_version()}; }
VersionSpec to_version_spec() const { return source_control_file->to_version_spec(); }
Path port_directory() const { return control_path.parent_path(); }
bool is_overlay_port(const Path& default_port_dir) const
Thomas1664 marked this conversation as resolved.
Show resolved Hide resolved
{
return !Strings::starts_with(control_path, default_port_dir);
}

std::unique_ptr<SourceControlFile> source_control_file;
Path control_path;
Expand Down
4 changes: 4 additions & 0 deletions include/vcpkg/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ namespace vcpkg

Path get_triplet_file_path(Triplet triplet) const;
bool is_valid_triplet_name(StringView name) const;
bool is_community_triplet_path(const Path& triplet_dir) const;
bool is_community_triplet(Triplet triplet) const;
bool is_overlay_triplet_path(const Path& triplet_dir) const;
bool is_overlay_triplet(Triplet triplet) const;
bool is_valid_triplet_canonical_name(StringView name) const;
};
}
6 changes: 3 additions & 3 deletions src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,15 +916,15 @@ namespace vcpkg
const auto& triplet_db = paths.get_triplet_db();
const auto& triplet_file_path = triplet_db.get_triplet_file_path(triplet);

if (Strings::starts_with(triplet_file_path, triplet_db.community_triplet_directory))
if (triplet_db.is_community_triplet_path(triplet_file_path))
{
msg::print(LocalizedString::from_raw(triplet_file_path)
.append_raw(": ")
.append_raw(InfoPrefix)
.append(msgLoadedCommunityTriplet)
.append_raw('\n'));
}
else if (!Strings::starts_with(triplet_file_path, triplet_db.default_triplet_directory))
else if (triplet_db.is_overlay_triplet_path(triplet_file_path))
{
msg::print(LocalizedString::from_raw(triplet_file_path)
.append_raw(": ")
Expand All @@ -933,7 +933,7 @@ namespace vcpkg
.append_raw('\n'));
}

if (!Strings::starts_with(scfl.control_path, paths.builtin_ports_directory()))
if (scfl.is_overlay_port(paths.builtin_ports_directory()))
{
msg::print(LocalizedString::from_raw(scfl.port_directory())
.append_raw(": ")
Expand Down
20 changes: 20 additions & 0 deletions src/vcpkg/triplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,26 @@ namespace vcpkg
return is_valid_triplet_canonical_name(Strings::ascii_to_lowercase(name));
}

bool TripletDatabase::is_community_triplet_path(const Path& path) const
{
return Strings::starts_with(path, community_triplet_directory);
}

bool TripletDatabase::is_community_triplet(Triplet triplet) const
{
return is_community_triplet_path(get_triplet_file_path(triplet));
}

bool TripletDatabase::is_overlay_triplet_path(const Path& path) const
{
return !Strings::starts_with(path, default_triplet_directory) && !is_community_triplet_path(path);
}

bool TripletDatabase::is_overlay_triplet(Triplet triplet) const
{
return is_overlay_triplet_path(get_triplet_file_path(triplet));
}

bool TripletDatabase::is_valid_triplet_canonical_name(StringView name) const
{
return Util::any_of(available_triplets, [=](const TripletFile& tf) { return tf.name == name; });
Expand Down
Loading