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

Allow vcpkg remove, vcpkg export, etc. without overlays. #1110

Merged
merged 12 commits into from
Jul 7, 2023
Merged
39 changes: 37 additions & 2 deletions azure-pipelines/end-to-end-tests-dir/overlays.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ $env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env-overlays"
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-ports=$manifestRoot/cli-overlays `
--overlay-triplets=$manifestRoot/my-triplets `
--x-install-root=$installRoot
--x-install-root=$installRoot `
--triplet fancy-triplet
Throw-IfFailed

# Tests overlays configured in env and cli on a project with configuration embedded on the manifest file
Expand All @@ -22,7 +23,8 @@ $env:VCPKG_OVERLAY_PORTS = "$manifestRoot/env-overlays"
Run-Vcpkg install --x-manifest-root=$manifestRoot `
--overlay-ports=$manifestRoot/cli-overlays `
--overlay-triplets=$manifestRoot/my-triplets `
--x-install-root=$installRoot
--x-install-root=$installRoot `
--triplet fancy-config-embedded-triplet
Throw-IfFailed

# Config with bad paths
Expand All @@ -47,3 +49,36 @@ $notEqual = @(Compare-Object $overlaysBefore $overlaysAfter -SyncWindow 0).Lengt
if ($notEqual) {
Throw "Overlay triplets paths changed after x-update-baseline"
}

# Test that removals can happen without the overlay triplets
Remove-Item env:VCPKG_OVERLAY_PORTS
Refresh-TestRoot
Run-Vcpkg install another-vcpkg-empty-port:fancy-triplet `
--overlay-ports=$PSScriptRoot/../e2e_projects/overlays-project-with-config/cli-overlays `
--overlay-triplets=$PSScriptRoot/../e2e_projects/overlays-project-with-config/my-triplets
Throw-IfFailed

Run-Vcpkg remove another-vcpkg-empty-port:fancy-triplet `
--overlay-ports=$PSScriptRoot/../e2e_projects/overlays-project-with-config/cli-overlays
Throw-IfFailed

# ... or ports
Refresh-TestRoot
Run-Vcpkg install another-vcpkg-empty-port:fancy-triplet `
--overlay-ports=$PSScriptRoot/../e2e_projects/overlays-project-with-config/cli-overlays `
--overlay-triplets=$PSScriptRoot/../e2e_projects/overlays-project-with-config/my-triplets
Throw-IfFailed

Run-Vcpkg remove another-vcpkg-empty-port:fancy-triplet `
--overlay-triplets=$PSScriptRoot/../e2e_projects/overlays-project-with-config/my-triplets
Throw-IfFailed

# ... or either
Refresh-TestRoot
Run-Vcpkg install another-vcpkg-empty-port:fancy-triplet `
--overlay-ports=$PSScriptRoot/../e2e_projects/overlays-project-with-config/cli-overlays `
--overlay-triplets=$PSScriptRoot/../e2e_projects/overlays-project-with-config/my-triplets
Throw-IfFailed

Run-Vcpkg remove another-vcpkg-empty-port:fancy-triplet
Throw-IfFailed
4 changes: 2 additions & 2 deletions include/vcpkg/base/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ namespace vcpkg::Strings

void inplace_ascii_to_lowercase(char* first, char* last);
void inplace_ascii_to_lowercase(std::string& s);
[[nodiscard]] std::string ascii_to_lowercase(std::string s);
[[nodiscard]] std::string ascii_to_uppercase(std::string s);
[[nodiscard]] std::string ascii_to_lowercase(StringView s);
[[nodiscard]] std::string ascii_to_uppercase(StringView s);

bool case_insensitive_ascii_starts_with(StringView s, StringView pattern);
bool case_insensitive_ascii_ends_with(StringView s, StringView pattern);
Expand Down
3 changes: 2 additions & 1 deletion include/vcpkg/commands.help.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vcpkg/base/fwd/files.h>

#include <vcpkg/fwd/triplet.h>
#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/fwd/vcpkgpaths.h>

Expand All @@ -11,5 +12,5 @@ namespace vcpkg::Help

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

void help_topic_valid_triplet(const VcpkgPaths& paths);
void help_topic_valid_triplet(const TripletDatabase& database);
}
2 changes: 2 additions & 0 deletions include/vcpkg/fwd/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ namespace vcpkg
{
struct TripletInstance;
struct Triplet;
struct TripletFile;
struct TripletDatabase;
}
1 change: 0 additions & 1 deletion include/vcpkg/fwd/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace vcpkg
struct ToolsetArchOption;
struct Toolset;
struct ManifestAndPath;
struct TripletFile;
struct VcpkgPaths;

struct VcpkgPathsImpl;
Expand Down
21 changes: 15 additions & 6 deletions include/vcpkg/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@

namespace vcpkg
{
PackageSpec check_and_get_package_spec(std::string&& spec_string,
// Parse a package spec without features; typically used by commands which
// refer to already installed packages which make features irrelevant.
//
// Does not assert that the package spec has a valid triplet. This allows
// such commands to refer to entities that were installed with an overlay
// triplet or similar which is no longer active.
PackageSpec check_and_get_package_spec(StringView spec_string,
vicroms marked this conversation as resolved.
Show resolved Hide resolved
Triplet default_triplet,
bool& default_triplet_used,
const LocalizedString& example_text,
const VcpkgPaths& paths);
const LocalizedString& example_text);

FullPackageSpec check_and_get_full_package_spec(std::string spec_string,
// Parse a package spec with features, typically used by commands which will
// install or modify a port.
//
// Asserts that the package spec has a valid triplet.
FullPackageSpec check_and_get_full_package_spec(StringView spec_string,
Triplet default_triplet,
bool& default_triplet_used,
const LocalizedString& example_text,
const VcpkgPaths& paths);
const TripletDatabase& database);

void check_triplet(Triplet t, const VcpkgPaths& paths);
void check_triplet(StringView name, const TripletDatabase& database);
}
32 changes: 29 additions & 3 deletions include/vcpkg/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vcpkg/fwd/vcpkgcmdarguments.h>

#include <vcpkg/base/optional.h>
#include <vcpkg/base/path.h>
#include <vcpkg/base/stringview.h>

#include <string>
Expand Down Expand Up @@ -41,9 +42,6 @@ namespace vcpkg

inline bool operator!=(Triplet left, Triplet right) { return !(left == right); }

Triplet default_triplet(const VcpkgCmdArguments& args);
Triplet default_host_triplet(const VcpkgCmdArguments& args);
void print_default_triplet_warning(const VcpkgCmdArguments& arg);
}

VCPKG_FORMAT_AS(vcpkg::Triplet, vcpkg::StringView);
Expand All @@ -56,3 +54,31 @@ namespace std
size_t operator()(vcpkg::Triplet t) const { return t.hash_code(); }
};
}

namespace vcpkg
{
Triplet default_triplet(const VcpkgCmdArguments& args, const TripletDatabase& database);
Triplet default_host_triplet(const VcpkgCmdArguments& args, const TripletDatabase& database);
void print_default_triplet_warning(const VcpkgCmdArguments& arg, const TripletDatabase& database);

struct TripletFile
{
std::string name;
Path location;

TripletFile(StringView name, StringView location);

Path get_full_path() const;
};

struct TripletDatabase
{
Path default_triplet_directory;
Path community_triplet_directory;
std::vector<TripletFile> available_triplets;

Path get_triplet_file_path(Triplet triplet) const;
bool is_valid_triplet_name(StringView name) const;
bool is_valid_triplet_canonical_name(StringView name) const;
};
}
19 changes: 6 additions & 13 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <vcpkg/fwd/registries.h>
#include <vcpkg/fwd/sourceparagraph.h>
#include <vcpkg/fwd/tools.h>
#include <vcpkg/fwd/triplet.h>
#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/fwd/vcpkgpaths.h>

Expand Down Expand Up @@ -45,14 +46,6 @@ namespace vcpkg
std::vector<ToolsetArchOption> supported_architectures;
};

struct TripletFile
{
std::string name;
Path location;

TripletFile(StringView name, StringView location) : name(name.data(), name.size()), location(location) { }
};

struct VcpkgPaths
{
VcpkgPaths(const Filesystem& filesystem, const VcpkgCmdArguments& args, const BundleSettings& bundle);
Expand All @@ -65,12 +58,9 @@ namespace vcpkg
Path build_dir(StringView package_name) const;
Path build_info_file_path(const PackageSpec& spec) const;

bool is_valid_triplet(Triplet t) const;
const std::vector<std::string> get_available_triplets_names() const;
const std::vector<TripletFile>& get_available_triplets() const;
const TripletDatabase& get_triplet_db() const;
const std::map<std::string, std::string>& get_cmake_script_hashes() const;
StringView get_ports_cmake_hash() const;
const Path& get_triplet_file_path(Triplet triplet) const;

LockFile& get_installed_lockfile() const;
void flush_lockfile() const;
Expand Down Expand Up @@ -104,11 +94,14 @@ namespace vcpkg
const Path buildsystems_msbuild_targets;
const Path buildsystems_msbuild_props;
const Path ports_cmake;

private:
const Path triplets;
const Path community_triplets;
std::vector<std::string> overlay_triplets;

public:
std::vector<std::string> overlay_ports;
std::vector<std::string> overlay_triplets;

std::string get_toolver_diagnostics() const;

Expand Down
7 changes: 2 additions & 5 deletions src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,8 @@ namespace
return command_function->function(args, paths);
}

Triplet default_triplet = vcpkg::default_triplet(args);
check_triplet(default_triplet, paths);
Triplet host_triplet = vcpkg::default_host_triplet(args);
check_triplet(host_triplet, paths);

Triplet default_triplet = vcpkg::default_triplet(args, paths.get_triplet_db());
Triplet host_triplet = vcpkg::default_host_triplet(args, paths.get_triplet_db());
if (const auto command_function = find_command(Commands::triplet_commands))
{
get_global_metrics_collector().track_string(StringMetric::CommandName, command_function->name);
Expand Down
14 changes: 8 additions & 6 deletions src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,18 @@ void Strings::inplace_ascii_to_lowercase(std::string& s)
Strings::inplace_ascii_to_lowercase(s.data(), s.data() + s.size());
}

std::string Strings::ascii_to_lowercase(std::string s)
std::string Strings::ascii_to_lowercase(StringView s)
{
Strings::inplace_ascii_to_lowercase(s);
return std::move(s);
std::string result;
std::transform(s.begin(), s.end(), std::back_inserter(result), tolower_char);
return result;
}

std::string Strings::ascii_to_uppercase(std::string s)
std::string Strings::ascii_to_uppercase(StringView s)
{
std::transform(s.begin(), s.end(), s.begin(), to_upper_char);
return std::move(s);
std::string result;
std::transform(s.begin(), s.end(), std::back_inserter(result), to_upper_char);
return result;
}

bool Strings::case_insensitive_ascii_starts_with(StringView s, StringView pattern)
Expand Down
7 changes: 4 additions & 3 deletions src/vcpkg/base/system.mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace vcpkg

// get "physical address"
if (parser.require_character('"')) return false;
auto mac_address = parser.match_until(is_quote).to_string();
out = parser.match_until(is_quote).to_string();
if (parser.require_character('"')) return false;
if (parser.require_character(',')) return false;

Expand All @@ -121,12 +121,13 @@ namespace vcpkg
parser.skip_whitespace();
if (!parser.at_eof())
{
out.clear();
return false;
}

// output line was properly formatted
std::replace(mac_address.begin(), mac_address.end(), '-', ':');
out = Strings::ascii_to_lowercase(std::move(mac_address));
std::replace(out.begin(), out.end(), '-', ':');
Strings::inplace_ascii_to_lowercase(out);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/cmakevars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace vcpkg::CMakeVars

for (auto&& p : emitted_triplets)
{
auto path_to_triplet = paths.get_triplet_file_path(p.first);
auto path_to_triplet = paths.get_triplet_db().get_triplet_file_path(p.first);
fmt::format_to(std::back_inserter(extraction_file),
"if(VCPKG_TRIPLET_ID EQUAL {})\n"
"set(CMAKE_CURRENT_LIST_FILE \"{}\")\n"
Expand Down
14 changes: 7 additions & 7 deletions src/vcpkg/commands.autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ namespace vcpkg::Commands::Autocomplete
Checks::exit_success(line_info);
}

static std::vector<std::string> combine_port_with_triplets(StringView port,
const std::vector<std::string>& triplets)
static std::vector<std::string> combine_port_with_triplets(StringView port, View<TripletFile> triplets)
{
return Util::fmap(triplets, [&](const std::string& triplet) { return fmt::format("{}:{}", port, triplet); });
return Util::fmap(triplets,
[&](const TripletFile& triplet) { return fmt::format("{}:{}", port, triplet.name); });
}

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
Expand Down Expand Up @@ -113,9 +113,9 @@ namespace vcpkg::Commands::Autocomplete
Checks::exit_success(VCPKG_LINE_INFO);
}

std::vector<std::string> triplets = paths.get_available_triplets_names();
Util::erase_remove_if(triplets, [&](const std::string& s) {
return !Strings::case_insensitive_ascii_starts_with(s, triplet_prefix);
auto triplets = paths.get_triplet_db().available_triplets;
Util::erase_remove_if(triplets, [&](const TripletFile& tf) {
return !Strings::case_insensitive_ascii_starts_with(tf.name, triplet_prefix);
});

auto result = combine_port_with_triplets(port_name, triplets);
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace vcpkg::Commands::Autocomplete
if (command.name == "install" && results.size() == 1 && !is_option)
{
const auto port_at_each_triplet =
combine_port_with_triplets(results[0], paths.get_available_triplets_names());
combine_port_with_triplets(results[0], paths.get_triplet_db().available_triplets);
Util::Vectors::append(&results, port_at_each_triplet);
}

Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/commands.build-external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace vcpkg::Commands::BuildExternal
default_triplet,
default_triplet_used,
COMMAND_STRUCTURE.get_example_text(),
paths);
paths.get_triplet_db());
if (default_triplet_used)
{
print_default_triplet_warning(args);
print_default_triplet_warning(args, paths.get_triplet_db());
}

auto overlays = paths.overlay_ports;
Expand Down
Loading
Loading