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

Configuring overlay ports and overlay triplets through the manifest #743

Merged
merged 30 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6106edb
overlays through manifest implemented
Oct 10, 2022
0d52572
turned artifacts on
Oct 10, 2022
794c193
artifacts settings once more
Oct 10, 2022
a8e13fc
fixed formatting
Oct 10, 2022
8c674e0
brought overlays to vcpkgpaths
Oct 12, 2022
1dec381
Merge branch 'main' into val-port-overlays
valeriaconde Oct 12, 2022
50dbc45
artifacts settings
valeriaconde Oct 12, 2022
f1fbae0
format
valeriaconde Oct 12, 2022
07e55f4
sending merged overlay triplets
valeriaconde Oct 13, 2022
0a0e92f
moved constructor
valeriaconde Oct 13, 2022
533898f
passing parameters by reference
valeriaconde Oct 13, 2022
679ad17
e2e tests
valeriaconde Oct 14, 2022
a4f8cba
bad paths test
valeriaconde Oct 14, 2022
47c7816
fix
valeriaconde Oct 15, 2022
fe933d0
resolves overlay paths relative to vcpkg-configuration.json
valeriaconde Oct 17, 2022
485f998
path fix
valeriaconde Oct 17, 2022
5a613f0
Update test config
valeriaconde Oct 17, 2022
1cfacb1
modified make_relative_to_manifest
valeriaconde Oct 18, 2022
934b316
Fix build
valeriaconde Oct 18, 2022
b143bb7
changed lambda function
valeriaconde Oct 18, 2022
1916cb6
made manifest directory const
valeriaconde Oct 18, 2022
e1d3ba8
Revert
valeriaconde Oct 18, 2022
9588151
Revert
valeriaconde Oct 18, 2022
8294341
Revert lambda function
valeriaconde Oct 18, 2022
86bd17f
Merge branch 'main' into val-port-overlays
valeriaconde Oct 18, 2022
0dda41a
Add get_manifest_directory()
valeriaconde Oct 18, 2022
9b9bfaa
making make_relative_to_manifest cleaner
valeriaconde Oct 18, 2022
9ff35b8
Comments
valeriaconde Oct 19, 2022
3de2e68
Merge branch 'main' into val-port-overlays
valeriaconde Oct 19, 2022
ed88c70
Comments
valeriaconde Oct 20, 2022
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
2 changes: 2 additions & 0 deletions include/vcpkg/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace vcpkg
std::vector<RegistryConfig> registries;
Json::Object ce_metadata;
Json::Object extra_info;
std::vector<std::string> overlay_ports;
std::vector<std::string> overlay_triplets;

Json::Object serialize() const;
void validate_as_active();
Expand Down
7 changes: 7 additions & 0 deletions include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ namespace vcpkg

static void append_common_options(HelpTableFormatter& target);

void set_manifest_overlays(std::vector<std::string>&, std::vector<std::string>&);
void merge_overlays();
vicroms marked this conversation as resolved.
Show resolved Hide resolved

constexpr static StringLiteral VCPKG_ROOT_DIR_ENV = "VCPKG_ROOT";
constexpr static StringLiteral VCPKG_ROOT_DIR_ARG = "vcpkg-root";
std::unique_ptr<std::string> vcpkg_root_dir;
Expand Down Expand Up @@ -155,9 +158,13 @@ namespace vcpkg
constexpr static StringLiteral OVERLAY_PORTS_ENV = "VCPKG_OVERLAY_PORTS";
constexpr static StringLiteral OVERLAY_PORTS_ARG = "overlay-ports";
std::vector<std::string> overlay_ports;
std::vector<std::string> env_overlay_ports;
std::vector<std::string> manifest_overlay_ports;
constexpr static StringLiteral OVERLAY_TRIPLETS_ENV = "VCPKG_OVERLAY_TRIPLETS";
constexpr static StringLiteral OVERLAY_TRIPLETS_ARG = "overlay-triplets";
std::vector<std::string> overlay_triplets;
std::vector<std::string> env_overlay_triplets;
std::vector<std::string> manifest_overlay_triplets;

constexpr static StringLiteral BINARY_SOURCES_ARG = "binarysource";
std::vector<std::string> binary_sources;
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace vcpkg
TripletFile(StringView name, StringView location) : name(name.data(), name.size()), location(location) { }
};

VcpkgPaths(Filesystem& filesystem, const VcpkgCmdArguments& args);
VcpkgPaths(Filesystem& filesystem, VcpkgCmdArguments& args);
VcpkgPaths(const VcpkgPaths&) = delete;
VcpkgPaths& operator=(const VcpkgPaths&) = delete;
~VcpkgPaths();
Expand Down
98 changes: 98 additions & 0 deletions src/vcpkg-test/configmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,104 @@ TEST_CASE ("metadata demands", "[ce-metadata]")

TEST_CASE ("serialize configuration", "[ce-metadata]")
{
SECTION ("only overlay ports")
{
std::string raw = R"json({
"overlay-ports": [
"./my-ports/fmt" ,
valeriaconde marked this conversation as resolved.
Show resolved Hide resolved
"/custom-ports",
"../share/team-ports"
]
})json";
// parsing of configuration is tested elsewhere
auto config = parse_test_configuration(raw);
Test::check_json_eq(Json::parse_object(raw).value_or_exit(VCPKG_LINE_INFO), config.serialize());
}

SECTION ("invalid overlay ports")
{
std::string raw = R"json({
"overlay-ports": [
"./my-ports/fmt" ,
"/custom-ports",
123
]
})json";
check_errors(raw, R"(
$.overlay-ports[2]: mismatched type: expected an overlay path
)");
}

SECTION ("only overlay triplets")
{
std::string raw = R"json({
"overlay-triplets": [
"./team-triplets"
]
})json";
// parsing of configuration is tested elsewhere
auto config = parse_test_configuration(raw);
Test::check_json_eq(Json::parse_object(raw).value_or_exit(VCPKG_LINE_INFO), config.serialize());
}

SECTION ("invalid overlay triplets")
{
std::string raw = R"json({
"overlay-triplets": [
123
]
})json";
check_errors(raw, R"(
$.overlay-triplets[0]: mismatched type: expected a triplet path
)");
}

SECTION ("both overlay ports and overlay triplets")
{
std::string raw = R"json({
"overlay-ports": [
"./my-ports/fmt" ,
"/custom-ports",
"../share/team-ports"
],
"overlay-triplets": [
"./team-triplets"
]
})json";
// parsing of configuration is tested elsewhere
auto config = parse_test_configuration(raw);
Test::check_json_eq(Json::parse_object(raw).value_or_exit(VCPKG_LINE_INFO), config.serialize());
}

SECTION ("overriden default registry, registries and overlays")
{
std::string raw = R"json({
"default-registry": {
"kind": "builtin",
"baseline": "843e0ba0d8f9c9c572e45564263eedfc7745e74f"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg",
"baseline": "843e0ba0d8f9c9c572e45564263eedfc7745e74f",
"packages": [ "zlib" ]
}
],
"overlay-ports": [
"./my-ports/fmt" ,
"/custom-ports",
"../share/team-ports"
],
"overlay-triplets": [
"./team-triplets"
]
})json";
// parsing of configuration is tested elsewhere
auto config = parse_test_configuration(raw);
Test::check_json_eq(Json::parse_object(raw).value_or_exit(VCPKG_LINE_INFO), config.serialize());
}

SECTION ("null default registry")
{
std::string raw = R"json({
Expand Down
4 changes: 3 additions & 1 deletion src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void invalid_command(const std::string& cmd)
Checks::exit_fail(VCPKG_LINE_INFO);
}

static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args)
static void inner(vcpkg::Filesystem& fs, VcpkgCmdArguments& args)
{
// track version on each invocation
LockGuardPtr<Metrics>(g_metrics)->track_string_property(StringMetric::VcpkgVersion,
Expand Down Expand Up @@ -79,6 +79,8 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args)
const VcpkgPaths paths(fs, args);
paths.track_feature_flag_metrics();

args.merge_overlays();

fs.current_path(paths.root, VCPKG_LINE_INFO);

if (const auto command_function = find_command(Commands::get_available_paths_commands()))
Expand Down
32 changes: 32 additions & 0 deletions src/vcpkg/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ namespace

constexpr static StringLiteral DEFAULT_REGISTRY = "default-registry";
constexpr static StringLiteral REGISTRIES = "registries";
constexpr static StringLiteral OVERLAY_PORTS = "overlay-ports";
constexpr static StringLiteral OVERLAY_TRIPLETS = "overlay-triplets";

virtual Optional<Configuration> visit_object(Json::Reader& r, const Json::Object& obj) override;

Expand All @@ -268,6 +270,8 @@ namespace
ConfigurationDeserializer ConfigurationDeserializer::instance;
constexpr StringLiteral ConfigurationDeserializer::DEFAULT_REGISTRY;
constexpr StringLiteral ConfigurationDeserializer::REGISTRIES;
constexpr StringLiteral ConfigurationDeserializer::OVERLAY_PORTS;
constexpr StringLiteral ConfigurationDeserializer::OVERLAY_TRIPLETS;

Optional<Json::Object> DictionaryDeserializer::visit_object(Json::Reader& r, const Json::Object& obj)
{
Expand Down Expand Up @@ -391,6 +395,14 @@ namespace
}
}

static Json::ArrayDeserializer<Json::StringDeserializer> op_des("an array of overlay ports paths",
Json::StringDeserializer{"an overlay path"});
r.optional_object_field(obj, OVERLAY_PORTS, ret.overlay_ports, op_des);

static Json::ArrayDeserializer<Json::StringDeserializer> ot_des("an array of overlay triplets paths",
Json::StringDeserializer{"a triplet path"});
r.optional_object_field(obj, OVERLAY_TRIPLETS, ret.overlay_triplets, ot_des);

RegistryConfig default_registry;
if (r.optional_object_field(obj, DEFAULT_REGISTRY, default_registry, RegistryConfigDeserializer::instance))
{
Expand Down Expand Up @@ -607,6 +619,8 @@ namespace vcpkg
static constexpr StringView known_fields[]{
ConfigurationDeserializer::DEFAULT_REGISTRY,
ConfigurationDeserializer::REGISTRIES,
ConfigurationDeserializer::OVERLAY_PORTS,
ConfigurationDeserializer::OVERLAY_TRIPLETS,
CeMetadataDeserializer::CE_MESSAGE,
CeMetadataDeserializer::CE_WARNING,
CeMetadataDeserializer::CE_ERROR,
Expand Down Expand Up @@ -739,6 +753,24 @@ namespace vcpkg
}
}

if (!overlay_ports.empty())
{
auto& op_arr = obj.insert(ConfigurationDeserializer::OVERLAY_PORTS, Json::Array());
for (const auto& port : overlay_ports)
{
op_arr.push_back(port);
}
}

if (!overlay_triplets.empty())
{
auto& ot_arr = obj.insert(ConfigurationDeserializer::OVERLAY_TRIPLETS, Json::Array());
for (const auto& triplet : overlay_triplets)
{
ot_arr.push_back(triplet);
}
}

if (!ce_metadata.is_empty())
{
serialize_ce_metadata(ce_metadata, obj);
Expand Down
23 changes: 19 additions & 4 deletions src/vcpkg/vcpkgcmdarguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,23 @@ namespace vcpkg
msg::println(LocalizedString::from_raw(table.m_str));
}

// Merges overlay ports in the specific order
void VcpkgCmdArguments::merge_overlays() {
overlay_ports.insert(
std::end(overlay_ports), std::begin(manifest_overlay_ports), std::end(manifest_overlay_ports));
overlay_ports.insert(
std::end(overlay_ports), std::begin(env_overlay_ports), std::end(env_overlay_ports));
overlay_triplets.insert(
std::end(overlay_triplets), std::begin(manifest_overlay_triplets), std::end(manifest_overlay_triplets));
overlay_triplets.insert(
std::end(overlay_triplets), std::begin(env_overlay_triplets), std::end(env_overlay_triplets));
vicroms marked this conversation as resolved.
Show resolved Hide resolved
}

void VcpkgCmdArguments::set_manifest_overlays(std::vector<std::string>& op, std::vector<std::string>& ot) {
manifest_overlay_ports.insert(std::end(manifest_overlay_ports), std::begin(op), std::end(op));
manifest_overlay_triplets.insert(std::end(manifest_overlay_triplets), std::begin(ot), std::end(ot));
}

void VcpkgCmdArguments::append_common_options(HelpTableFormatter& table)
{
static auto opt = [](StringView arg, StringView joiner, StringView value) {
Expand Down Expand Up @@ -729,16 +746,14 @@ namespace vcpkg
const auto vcpkg_overlay_ports_env = get_env(OVERLAY_PORTS_ENV);
if (const auto unpacked = vcpkg_overlay_ports_env.get())
{
auto overlays = Strings::split_paths(*unpacked);
overlay_ports.insert(std::end(overlay_ports), std::begin(overlays), std::end(overlays));
env_overlay_ports = Strings::split_paths(*unpacked);
}
}
{
const auto vcpkg_overlay_triplets_env = get_env(OVERLAY_TRIPLETS_ENV);
if (const auto unpacked = vcpkg_overlay_triplets_env.get())
{
auto triplets = Strings::split_paths(*unpacked);
overlay_triplets.insert(std::end(overlay_triplets), std::begin(triplets), std::end(triplets));
env_overlay_triplets = Strings::split_paths(*unpacked);
}
}
{
Expand Down
12 changes: 7 additions & 5 deletions src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ namespace vcpkg
#endif
}

VcpkgPaths::VcpkgPaths(Filesystem& filesystem, const VcpkgCmdArguments& args)
VcpkgPaths::VcpkgPaths(Filesystem& filesystem, VcpkgCmdArguments& args)
vicroms marked this conversation as resolved.
Show resolved Hide resolved
: original_cwd(preferred_current_path(filesystem))
, root(determine_root(filesystem, original_cwd, args))
// this is used during the initialization of the below public members
Expand Down Expand Up @@ -651,10 +651,12 @@ namespace vcpkg
auto maybe_config_json = config_from_json(m_pimpl->m_config_dir / "vcpkg-configuration.json", filesystem);

m_pimpl->m_config = merge_validate_configs(std::move(maybe_manifest_config),
m_pimpl->m_manifest_dir,
std::move(maybe_config_json),
m_pimpl->m_config_dir,
*this);
m_pimpl->m_manifest_dir,
std::move(maybe_config_json),
m_pimpl->m_config_dir,
*this);

args.set_manifest_overlays(m_pimpl->m_config.config.overlay_ports, m_pimpl->m_config.config.overlay_triplets);

m_pimpl->m_registry_set = m_pimpl->m_config.instantiate_registry_set(*this);
}
Expand Down