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

Embed vcpkg configuration in manifest #239

Merged
merged 17 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace vcpkg
std::vector<std::string> default_features;
std::string license; // SPDX license expression
Optional<std::string> builtin_baseline;
Optional<Json::Object> vcpkg_configuration;

Type type = {Type::PORT};
PlatformExpression::Expr supports_expression;
Expand Down
5 changes: 5 additions & 0 deletions include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace vcpkg
bool binary_caching;
bool versions;
bool manifests;
bool config_manifests;
};

struct VcpkgCmdArguments
Expand Down Expand Up @@ -202,6 +203,8 @@ namespace vcpkg
Optional<bool> registries_feature = nullopt;
constexpr static StringLiteral VERSIONS_FEATURE = "versions";
Optional<bool> versions_feature = nullopt;
constexpr static StringLiteral CONFIG_MANIFESTS_FEATURE = "configmanifests";
Optional<bool> config_manifests_feature = nullopt;

constexpr static StringLiteral RECURSIVE_DATA_ENV = "X_VCPKG_RECURSIVE_DATA";

Expand All @@ -210,6 +213,7 @@ namespace vcpkg
bool registries_enabled() const { return registries_feature.value_or(true); }
bool versions_enabled() const { return versions_feature.value_or(true); }
bool manifests_enabled() const { return manifest_mode.value_or(true); }
bool config_manifests_enabled() const { return config_manifests_feature.value_or(false); }
FeatureFlagSettings feature_flag_settings() const
{
FeatureFlagSettings f;
Expand All @@ -218,6 +222,7 @@ namespace vcpkg
f.registries = registries_enabled();
f.versions = versions_enabled();
f.manifests = manifests_enabled();
f.config_manifests = config_manifests_enabled();
return f;
}

Expand Down
47 changes: 39 additions & 8 deletions src/vcpkg/sourceparagraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ namespace vcpkg
constexpr static StringLiteral SUPPORTS = "supports";
constexpr static StringLiteral OVERRIDES = "overrides";
constexpr static StringLiteral BUILTIN_BASELINE = "builtin-baseline";
constexpr static StringLiteral VCPKG_CONFIGURATION = "x-vcpkg-configuration";
vicroms marked this conversation as resolved.
Show resolved Hide resolved

virtual Span<const StringView> valid_fields() const override
{
Expand All @@ -874,6 +875,7 @@ namespace vcpkg
SUPPORTS,
OVERRIDES,
BUILTIN_BASELINE,
VCPKG_CONFIGURATION,
};
static const auto t = Util::Vectors::concat<StringView>(schemed_deserializer_fields(), u);

Expand Down Expand Up @@ -932,6 +934,18 @@ namespace vcpkg
r.optional_object_field(
obj, FEATURES, control_file->feature_paragraphs, FeaturesFieldDeserializer::instance);

if (auto configuration = obj.get(VCPKG_CONFIGURATION))
{
if (!configuration->is_object())
{
r.add_generic_error(type_name(), VCPKG_CONFIGURATION, " x-vcpkg-configuration must be an object");
}
else
{
spgh->vcpkg_configuration = make_optional(configuration->object());
}
}

if (auto maybe_error = canonicalize(*control_file))
{
Checks::exit_with_message(VCPKG_LINE_INFO, maybe_error->error);
Expand All @@ -957,6 +971,7 @@ namespace vcpkg
constexpr StringLiteral ManifestDeserializer::SUPPORTS;
constexpr StringLiteral ManifestDeserializer::OVERRIDES;
constexpr StringLiteral ManifestDeserializer::BUILTIN_BASELINE;
constexpr StringLiteral ManifestDeserializer::VCPKG_CONFIGURATION;

SourceControlFile SourceControlFile::clone() const
{
Expand Down Expand Up @@ -998,6 +1013,19 @@ namespace vcpkg
bool is_default_builtin_registry) const
{
static constexpr StringLiteral s_extended_help = "See `vcpkg help versioning` for more information.";
auto format_error_message = [&](StringView manifest_field, StringView feature_flag) {
return Strings::format(" was rejected because it uses \"%s\" and the `%s` feature flag is disabled.\n"
"This can be fixed by removing \"%s\".\n",
manifest_field,
feature_flag,
manifest_field);
};
if (!flags.config_manifests && core_paragraph->extra_info.contains(ManifestDeserializer::VCPKG_CONFIGURATION))
{
return Strings::concat(origin,
format_error_message(ManifestDeserializer::VCPKG_CONFIGURATION,
VcpkgCmdArguments::CONFIG_MANIFESTS_FEATURE));
}
if (!flags.versions)
{
auto check_deps = [&](View<Dependency> deps) -> Optional<std::string> {
Expand Down Expand Up @@ -1027,21 +1055,18 @@ namespace vcpkg
if (core_paragraph->overrides.size() != 0)
{
LockGuardPtr<Metrics>(g_metrics)->track_property("error-versioning-disabled", "defined");
return Strings::concat(origin,
" was rejected because it uses overrides and the `",
VcpkgCmdArguments::VERSIONS_FEATURE,
"` feature flag is disabled.\nThis can be fixed by removing \"overrides\".\n",
s_extended_help);
return Strings::concat(
origin,
format_error_message(ManifestDeserializer::OVERRIDES, VcpkgCmdArguments::VERSIONS_FEATURE),
s_extended_help);
}

if (core_paragraph->builtin_baseline.has_value())
{
LockGuardPtr<Metrics>(g_metrics)->track_property("error-versioning-disabled", "defined");
return Strings::concat(
origin,
" was rejected because it uses builtin-baseline and the `",
VcpkgCmdArguments::VERSIONS_FEATURE,
"` feature flag is disabled.\nThis can be fixed by removing \"builtin-baseline\".\n",
format_error_message(ManifestDeserializer::BUILTIN_BASELINE, VcpkgCmdArguments::VERSIONS_FEATURE),
s_extended_help);
}
}
Expand Down Expand Up @@ -1327,6 +1352,12 @@ namespace vcpkg
obj.insert(el.first.to_string(), el.second);
}

// TODO: Actually serialize vcpkg-configuration
if (auto configuration = scf.core_paragraph->vcpkg_configuration.get())
{
obj.insert(ManifestDeserializer::VCPKG_CONFIGURATION, *configuration);
}
vicroms marked this conversation as resolved.
Show resolved Hide resolved

obj.insert(ManifestDeserializer::NAME, Json::Value::string(scf.core_paragraph->name));

serialize_schemed_version(obj,
Expand Down
6 changes: 6 additions & 0 deletions src/vcpkg/vcpkgcmdarguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace vcpkg
{VcpkgCmdArguments::COMPILER_TRACKING_FEATURE, args.compiler_tracking},
{VcpkgCmdArguments::REGISTRIES_FEATURE, args.registries_feature},
{VcpkgCmdArguments::VERSIONS_FEATURE, args.versions_feature},
{VcpkgCmdArguments::CONFIG_MANIFESTS_FEATURE, args.config_manifests_feature},
};

for (const auto& desc : flag_descriptions)
Expand Down Expand Up @@ -813,6 +814,9 @@ namespace vcpkg
} possible_inconsistencies[] = {
{BINARY_CACHING_FEATURE, BINARY_SOURCES_ARG, !binary_sources.empty() && !binary_caching.value_or(true)},
{MANIFEST_MODE_FEATURE, MANIFEST_ROOT_DIR_ARG, manifest_root_dir && !manifest_mode.value_or(true)},
{MANIFEST_MODE_FEATURE,
CONFIG_MANIFESTS_FEATURE,
config_manifests_feature.value_or(false) && !manifest_mode.value_or(true)},
};
for (const auto& el : possible_inconsistencies)
{
Expand Down Expand Up @@ -841,6 +845,7 @@ namespace vcpkg
{COMPILER_TRACKING_FEATURE, compiler_tracking},
{REGISTRIES_FEATURE, registries_feature},
{VERSIONS_FEATURE, versions_feature},
{CONFIG_MANIFESTS_FEATURE, config_manifests_feature},
};

for (const auto& flag : flags)
Expand Down Expand Up @@ -1032,6 +1037,7 @@ namespace vcpkg
constexpr StringLiteral VcpkgCmdArguments::REGISTRIES_FEATURE;
constexpr StringLiteral VcpkgCmdArguments::RECURSIVE_DATA_ENV;
constexpr StringLiteral VcpkgCmdArguments::VERSIONS_FEATURE;
constexpr StringLiteral VcpkgCmdArguments::CONFIG_MANIFESTS_FEATURE;

constexpr StringLiteral VcpkgCmdArguments::CMAKE_SCRIPT_ARG;
}
46 changes: 43 additions & 3 deletions src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ namespace vcpkg
static ConfigAndPath load_configuration(const Filesystem& fs,
const VcpkgCmdArguments& args,
const Path& vcpkg_root,
const Path& manifest_dir)
const Path& manifest_dir,
const Optional<Json::Object>& configuration_from_manifest)
{
Path config_dir;
if (manifest_dir.empty())
Expand All @@ -163,7 +164,27 @@ namespace vcpkg
auto path_to_config = config_dir / "vcpkg-configuration.json";
if (!fs.exists(path_to_config, IgnoreErrors{}))
{
return {};
if (!configuration_from_manifest.has_value())
{
return {};
}

return {std::move(config_dir),
deserialize_configuration(
configuration_from_manifest.value_or_exit(VCPKG_LINE_INFO), args, manifest_dir / "vcpkg.json")};
}

if (configuration_from_manifest.has_value())
{
print2(Color::error,
"Ambiguous vcpkg configuration provided by both manifest and configuration file.\n"
"-- Delete configuration file \"",
path_to_config,
"\"\n"
"-- Or remove \"$x-vcpkg-configuration\" from manifest file \"",
vicroms marked this conversation as resolved.
Show resolved Hide resolved
manifest_dir / "vcpkg.json",
"\".");
Checks::exit_fail(VCPKG_LINE_INFO);
}

auto parsed_config = Json::parse_file(VCPKG_LINE_INFO, fs, path_to_config);
Expand Down Expand Up @@ -356,7 +377,26 @@ namespace vcpkg
m_pimpl->m_manifest_path = manifest_root_dir / "vcpkg.json";
}

auto config_file = load_configuration(filesystem, args, root, manifest_root_dir);
auto configuration_from_manifest = [&]() -> vcpkg::Optional<Json::Object> {
if (auto manifest = m_pimpl->m_manifest_doc.get())
{
auto manifest_obj = manifest->first;
if (auto config_obj = manifest_obj.get("x-vcpkg-configuration"))
{
if (!config_obj->is_object())
{
print2(Color::error,
"Failed to parse ",
m_pimpl->m_manifest_path,
": x-vcpkg-configuration must be an object\n");
Checks::exit_fail(VCPKG_LINE_INFO);
}
return make_optional(config_obj->object());
}
}
return nullopt;
}();
vicroms marked this conversation as resolved.
Show resolved Hide resolved
auto config_file = load_configuration(filesystem, args, root, manifest_root_dir, configuration_from_manifest);

// metrics from configuration
{
Expand Down