[vcpkg] Reorganize some parsing functions.
MODIFY
include/PackageSpec.h
include/PackageSpec.h
#pragma once
+
#include "PackageSpecParseResult.h"
-#include "SourceParagraph.h"
#include "Triplet.h"
#include "vcpkg_expected.h"
@@ -17,7 +17,6 @@ namespace vcpkg
struct PackageSpec
{
- static std::string to_string(const std::string& name, const Triplet& triplet);
static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name,
const Triplet& triplet);
@@ -43,6 +42,14 @@ namespace vcpkg
const Triplet& default_triplet);
};
+ struct Features
+ {
+ std::string name;
+ std::vector<std::string> features;
+
+ static ExpectedT<Features, PackageSpecParseResult> from_string(const std::string& input);
+ };
+
bool operator==(const PackageSpec& left, const PackageSpec& right);
bool operator!=(const PackageSpec& left, const PackageSpec& right);
}

MODIFY
include/SourceParagraph.h
include/SourceParagraph.h
#pragma once
+#include "PackageSpec.h"
#include "Span.h"
#include "vcpkg_Parse.h"
#include "vcpkg_System.h"
@@ -13,16 +14,6 @@ namespace vcpkg
{
extern bool g_feature_packages;
- struct Triplet;
-
- struct Features
- {
- std::string name;
- std::vector<std::string> features;
- };
-
- Features parse_feature_list(const std::string& name);
-
struct Dependency
{
Features depend;
@@ -73,7 +64,6 @@ namespace vcpkg
// zlib[uwp] becomes Dependency{"zlib", "uwp"}
std::vector<Dependency> expand_qualified_dependencies(const std::vector<std::string>& depends);
- std::vector<std::string> parse_comma_list(const std::string& str);
struct Supports
{

MODIFY
include/vcpkg_Parse.h
include/vcpkg_Parse.h
@@ -33,4 +33,6 @@ namespace vcpkg::Parse
RawParagraph&& fields;
std::vector<std::string> missing_fields;
};
+
+ std::vector<std::string> parse_comma_list(const std::string& str);
}

MODIFY
src/PackageSpec.cpp
src/PackageSpec.cpp
#include "pch.h"
#include "PackageSpec.h"
+#include "vcpkg_Parse.h"
#include "vcpkg_Util.h"
+using vcpkg::Parse::parse_comma_list;
+
namespace vcpkg
{
static bool is_valid_package_spec_char(char c)
@@ -45,11 +48,7 @@ namespace vcpkg
std::string PackageSpec::dir() const { return Strings::format("%s_%s", this->m_name, this->m_triplet); }
- std::string PackageSpec::to_string(const std::string& name, const Triplet& triplet)
- {
- return Strings::format("%s:%s", name, triplet);
- }
- std::string PackageSpec::to_string() const { return to_string(this->name(), this->triplet()); }
+ std::string PackageSpec::to_string() const { return Strings::format("%s:%s", this->name(), this->triplet()); }
bool operator==(const PackageSpec& left, const PackageSpec& right)
{
@@ -106,4 +105,21 @@ namespace vcpkg
}
return f;
}
+
+ ExpectedT<Features, PackageSpecParseResult> Features::from_string(const std::string& name)
+ {
+ auto maybe_spec = ParsedSpecifier::from_string(name);
+ if (auto spec = maybe_spec.get())
+ {
+ Checks::check_exit(
+ VCPKG_LINE_INFO, spec->triplet.empty(), "error: triplet not allowed in specifier: %s", name);
+
+ Features f;
+ f.name = spec->name;
+ f.features = spec->features;
+ return f;
+ }
+
+ return maybe_spec.error();
+ }
}

MODIFY
src/SourceParagraph.cpp
src/SourceParagraph.cpp
@@ -157,29 +157,15 @@ namespace vcpkg
return std::move(control_file);
}
- Features parse_feature_list(const std::string& name)
- {
- auto maybe_spec = ParsedSpecifier::from_string(name);
- if (auto spec = maybe_spec.get())
- {
- Checks::check_exit(
- VCPKG_LINE_INFO, spec->triplet.empty(), "error: triplet not allowed in specifier: %s", name);
-
- Features f;
- f.name = spec->name;
- f.features = spec->features;
- return f;
- }
-
- Checks::exit_with_message(
- VCPKG_LINE_INFO, "error while parsing feature list: %s: %s", to_string(maybe_spec.error()), name);
- }
-
Dependency Dependency::parse_dependency(std::string name, std::string qualifier)
{
Dependency dep;
dep.qualifier = qualifier;
- dep.depend = parse_feature_list(name);
+ if (auto maybe_features = Features::from_string(name))
+ dep.depend = *maybe_features.get();
+ else
+ Checks::exit_with_message(
+ VCPKG_LINE_INFO, "error while parsing dependency: %s: %s", to_string(maybe_features.error()), name);
return dep;
}
@@ -217,39 +203,6 @@ namespace vcpkg
});
}
- std::vector<std::string> parse_comma_list(const std::string& str)
- {
- if (str.empty())
- {
- return {};
- }
-
- std::vector<std::string> out;
-
- size_t cur = 0;
- do
- {
- auto pos = str.find(',', cur);
- if (pos == std::string::npos)
- {
- out.push_back(str.substr(cur));
- break;
- }
- out.push_back(str.substr(cur, pos - cur));
-
- // skip comma and space
- ++pos;
- if (str[pos] == ' ')
- {
- ++pos;
- }
-
- cur = pos;
- } while (cur != std::string::npos);
-
- return out;
- }
-
std::vector<std::string> filter_dependencies(const std::vector<vcpkg::Dependency>& deps, const Triplet& t)
{
std::vector<std::string> ret;

MODIFY
src/tests_dependencies.cpp
src/tests_dependencies.cpp
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace vcpkg;
+using Parse::parse_comma_list;
namespace UnitTest1
{
@@ -41,7 +42,15 @@ namespace UnitTest1
TEST_METHOD(parse_supports_all)
{
auto v = Supports::parse({
- "x64", "x86", "arm", "windows", "uwp", "v140", "v141", "crt-static", "crt-dynamic",
+ "x64",
+ "x86",
+ "arm",
+ "windows",
+ "uwp",
+ "v140",
+ "v141",
+ "crt-static",
+ "crt-dynamic",
});
Assert::AreNotEqual(uintptr_t(0), uintptr_t(v.get()));
@@ -74,7 +83,9 @@ namespace UnitTest1
TEST_METHOD(parse_supports_some)
{
auto v = Supports::parse({
- "x64", "x86", "windows",
+ "x64",
+ "x86",
+ "windows",
});
Assert::AreNotEqual(uintptr_t(0), uintptr_t(v.get()));

MODIFY
src/vcpkg_Parse.cpp
src/vcpkg_Parse.cpp
@@ -44,4 +44,37 @@ namespace vcpkg::Parse
}
return nullptr;
}
+
+ std::vector<std::string> parse_comma_list(const std::string& str)
+ {
+ if (str.empty())
+ {
+ return {};
+ }
+
+ std::vector<std::string> out;
+
+ size_t cur = 0;
+ do
+ {
+ auto pos = str.find(',', cur);
+ if (pos == std::string::npos)
+ {
+ out.push_back(str.substr(cur));
+ break;
+ }
+ out.push_back(str.substr(cur, pos - cur));
+
+ // skip comma and space
+ ++pos;
+ if (str[pos] == ' ')
+ {
+ ++pos;
+ }
+
+ cur = pos;
+ } while (cur != std::string::npos);
+
+ return out;
+ }
}

[vcpkg] Reorganize some parsing functions.