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

[regex-ripout] part 2/n #431

Merged
merged 17 commits into from
Mar 16, 2022
4 changes: 2 additions & 2 deletions include/vcpkg/binarycaching.private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace vcpkg
// - v?<X>.<Y><whatever> -> <X>.<Y>.0-vcpkg<abitag>
// - v?<X>.<Y>.<Z><whatever> -> <X>.<Y>.<Z>-vcpkg<abitag>
// - anything else -> 0.0.0-vcpkg<abitag>
std::string reformat_version(StringView version, StringView abi_tag);
std::string format_version_for_nugetref(StringView version, StringView abi_tag);

struct NugetReference
{
Expand All @@ -33,7 +33,7 @@ namespace vcpkg
const std::string& abi_tag,
const std::string& prefix)
{
return {Strings::concat(prefix, spec.dir()), reformat_version(raw_version, abi_tag)};
return {Strings::concat(prefix, spec.dir()), format_version_for_nugetref(raw_version, abi_tag)};
}
inline NugetReference make_nugetref(const Dependencies::InstallPlanAction& action, const std::string& prefix)
{
Expand Down
2 changes: 2 additions & 0 deletions include/vcpkg/export.ifw.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace vcpkg::Export::IFW
Optional<std::string> maybe_installer_file_path;
};

std::string safe_rich_from_plain_text(StringView text);

void do_export(const std::vector<Dependencies::ExportPlanAction>& export_plan,
const std::string& export_id,
const Options& ifw_options,
Expand Down
10 changes: 8 additions & 2 deletions include/vcpkg/export.prefab.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace vcpkg::Export::Prefab
std::string to_string();
void to_string(std::string& out);

friend bool operator==(const NdkVersion& lhs, const NdkVersion& rhs)
{
return lhs.m_major == rhs.m_major && lhs.m_minor == rhs.m_minor && lhs.m_patch == rhs.m_patch;
}
friend bool operator!=(const NdkVersion& lhs, const NdkVersion& rhs) { return !(lhs == rhs); }

private:
int m_major;
int m_minor;
Expand Down Expand Up @@ -74,6 +80,6 @@ namespace vcpkg::Export::Prefab
const VcpkgPaths& paths,
const Options& prefab_options,
const Triplet& triplet);
Optional<std::string> find_ndk_version(const std::string& content);
Optional<NdkVersion> to_version(const std::string& version);
Optional<StringView> find_ndk_version(StringView content);
Optional<NdkVersion> to_version(StringView version);
}
2 changes: 2 additions & 0 deletions include/vcpkg/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ namespace vcpkg
void flush(Filesystem& fs);
};

Optional<StringView> find_first_nonzero_mac(StringView sv);

extern LockGuarded<Metrics> g_metrics;
}
17 changes: 17 additions & 0 deletions include/vcpkg/versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ namespace vcpkg
None,
Minimum
};

// this is for version parsing that isn't in vcpkg ports
// stuff like tools, nuget, etc.
struct ParsedExternalVersion
{
StringView major;
StringView minor;
StringView patch;

void normalize();
};

StringView normalize_external_version_zeros(StringView sv);
// /(\d\d\d\d)-(\d\d)-(\d\d).*/
bool try_parse_external_date_version(ParsedExternalVersion& out, StringView version);
// /(\d+)(\.\d+|$)(\.\d+)?.*/
bool try_parse_external_dot_version(ParsedExternalVersion& out, StringView version);
}

VCPKG_FORMAT_WITH_TO_STRING(vcpkg::VersionSpec);
34 changes: 17 additions & 17 deletions src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,30 @@ TEST_CASE ("CacheStatus operations", "[BinaryCache]")
REQUIRE(lhs_lines.size() == rhs_lines.size()); \
}

TEST_CASE ("reformat_version semver-ish", "[reformat_version]")
TEST_CASE ("format_version_for_nugetref semver-ish", "[format_version_for_nugetref]")
{
REQUIRE(reformat_version("0.0.0", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(reformat_version("1.0.1", "abitag") == "1.0.1-vcpkgabitag");
REQUIRE(reformat_version("1.01.000", "abitag") == "1.1.0-vcpkgabitag");
REQUIRE(reformat_version("1.2", "abitag") == "1.2.0-vcpkgabitag");
REQUIRE(reformat_version("v52", "abitag") == "52.0.0-vcpkgabitag");
REQUIRE(reformat_version("v09.01.02", "abitag") == "9.1.2-vcpkgabitag");
REQUIRE(reformat_version("1.1.1q", "abitag") == "1.1.1-vcpkgabitag");
REQUIRE(reformat_version("1", "abitag") == "1.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("0.0.0", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("1.0.1", "abitag") == "1.0.1-vcpkgabitag");
REQUIRE(format_version_for_nugetref("1.01.000", "abitag") == "1.1.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("1.2", "abitag") == "1.2.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("v52", "abitag") == "52.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("v09.01.02", "abitag") == "9.1.2-vcpkgabitag");
REQUIRE(format_version_for_nugetref("1.1.1q", "abitag") == "1.1.1-vcpkgabitag");
REQUIRE(format_version_for_nugetref("1", "abitag") == "1.0.0-vcpkgabitag");
}

TEST_CASE ("reformat_version date", "[reformat_version]")
TEST_CASE ("format_version_for_nugetref date", "[format_version_for_nugetref]")
{
REQUIRE(reformat_version("2020-06-26", "abitag") == "2020.6.26-vcpkgabitag");
REQUIRE(reformat_version("20-06-26", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(reformat_version("2020-06-26-release", "abitag") == "2020.6.26-vcpkgabitag");
REQUIRE(reformat_version("2020-06-26000", "abitag") == "2020.6.26-vcpkgabitag");
REQUIRE(format_version_for_nugetref("2020-06-26", "abitag") == "2020.6.26-vcpkgabitag");
REQUIRE(format_version_for_nugetref("20-06-26", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("2020-06-26-release", "abitag") == "2020.6.26-vcpkgabitag");
REQUIRE(format_version_for_nugetref("2020-06-26000", "abitag") == "2020.6.26-vcpkgabitag");
}

TEST_CASE ("reformat_version generic", "[reformat_version]")
TEST_CASE ("format_version_for_nugetref generic", "[format_version_for_nugetref]")
{
REQUIRE(reformat_version("apr", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(reformat_version("", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("apr", "abitag") == "0.0.0-vcpkgabitag");
REQUIRE(format_version_for_nugetref("", "abitag") == "0.0.0-vcpkgabitag");
}

TEST_CASE ("generate_nuspec", "[generate_nuspec]")
Expand Down
126 changes: 126 additions & 0 deletions src/vcpkg-test/export.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <catch2/catch.hpp>

#include <vcpkg/export.ifw.h>
#include <vcpkg/export.prefab.h>

using namespace vcpkg;

namespace IFW = Export::IFW;
namespace Prefab = Export::Prefab;

TEST_CASE ("safe_rich_from_plain_text", "[export]")
{
CHECK(IFW::safe_rich_from_plain_text("&") == "&amp;");
CHECK(IFW::safe_rich_from_plain_text("&asdf") == "&amp;asdf");
CHECK(IFW::safe_rich_from_plain_text("&#123") == "&amp;#123");
CHECK(IFW::safe_rich_from_plain_text("&#x1AfC") == "&amp;#x1AfC");

CHECK(IFW::safe_rich_from_plain_text("&;") == "&amp;;");
CHECK(IFW::safe_rich_from_plain_text("&#;") == "&amp;#;");
CHECK(IFW::safe_rich_from_plain_text("&#x;") == "&amp;#x;");

CHECK(IFW::safe_rich_from_plain_text("&asdf ;") == "&amp;asdf ;");
CHECK(IFW::safe_rich_from_plain_text("&#123a;") == "&amp;#123a;");
CHECK(IFW::safe_rich_from_plain_text("&#x1AfCx;") == "&amp;#x1AfCx;");
CHECK(IFW::safe_rich_from_plain_text("&#X123;") == "&amp;#X123;");

CHECK(IFW::safe_rich_from_plain_text("&asdf;") == "&asdf;");
CHECK(IFW::safe_rich_from_plain_text("&asdf_asdf123;") == "&asdf_asdf123;");
CHECK(IFW::safe_rich_from_plain_text("&#123;") == "&#123;");
CHECK(IFW::safe_rich_from_plain_text("&#x1AfC;") == "&#x1AfC;");
}

TEST_CASE ("find_ndk_version", "[export]")
{
auto result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
Pkg.Revision = 23.1.7779620
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "23.1.7779620");

result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
Pkg.Revision = 23.1.7779620
Pkg.Blah = doopadoopa
Pkg.Revision = foobar
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "23.1.7779620");

result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
Pkg.Revision = 1.2.3.4.5
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "1.2.3.4.5");

result = Prefab::find_ndk_version(R"(
Pkg.Revision = 1.2
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "1.2");

result = Prefab::find_ndk_version(R"(
Pkg.Revision `=
Pkg.Revision = 1.2.3
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "1.2.3");

result = Prefab::find_ndk_version(R"(
Pkg.Revision = foobar
Pkg.Revision = 1.2.3
)");
REQUIRE(result.has_value());
CHECK(*result.get() == "1.2.3");

result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
)");
CHECK_FALSE(result.has_value());

result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
Pkg.Revision `=
)");
CHECK_FALSE(result.has_value());

result = Prefab::find_ndk_version(R"(
Pkg.Desc = Android NDK
Pkg.Revision = foobar
)");
CHECK_FALSE(result.has_value());
}

TEST_CASE ("Prefab::to_version", "[export]")
{
auto result = Prefab::to_version("1.2.3");
REQUIRE(result.has_value());
CHECK(*result.get() == Prefab::NdkVersion{1, 2, 3});

result = Prefab::to_version("20.180.2134324");
REQUIRE(result.has_value());
CHECK(*result.get() == Prefab::NdkVersion{20, 180, 2134324});

result = Prefab::to_version(" 1.2.3");
REQUIRE(result.has_value());
CHECK(*result.get() == Prefab::NdkVersion{1, 2, 3});

result = Prefab::to_version("1.2.3 ");
REQUIRE(result.has_value());
CHECK(*result.get() == Prefab::NdkVersion{1, 2, 3});

result = Prefab::to_version(" 1.2.3 ");
REQUIRE(result.has_value());
CHECK(*result.get() == Prefab::NdkVersion{1, 2, 3});

result = Prefab::to_version("1.2.3.4");
CHECK_FALSE(result.has_value());

result = Prefab::to_version("1.2");
CHECK_FALSE(result.has_value());

result = Prefab::to_version("100000000000.2.3");
CHECK_FALSE(result.has_value());
}
35 changes: 35 additions & 0 deletions src/vcpkg-test/metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <catch2/catch.hpp>

#include <vcpkg/metrics.h>

using namespace vcpkg;

TEST_CASE ("find_first_nonzero_mac", "[metrics]")
{
auto result = find_first_nonzero_mac(R"()");
CHECK_FALSE(result.has_value());

result = find_first_nonzero_mac(R"(12-34-56-78-90-ab)");
REQUIRE(result.has_value());
CHECK(*result.get() == "12-34-56-78-90-ab");

result = find_first_nonzero_mac(R"(12-34-56-78-90-AB)");
REQUIRE(result.has_value());
CHECK(*result.get() == "12-34-56-78-90-AB");

result = find_first_nonzero_mac(R"(12-34-56-78-90-AB CD-EF-01-23-45-67)");
REQUIRE(result.has_value());
CHECK(*result.get() == "12-34-56-78-90-AB");

result = find_first_nonzero_mac(R"(00-00-00-00-00-00 CD-EF-01-23-45-67)");
REQUIRE(result.has_value());
CHECK(*result.get() == "CD-EF-01-23-45-67");

result = find_first_nonzero_mac(R"(asdfa00-00-00-00-00-00 jiojCD-EF-01-23-45-67-89)");
REQUIRE(result.has_value());
CHECK(*result.get() == "CD-EF-01-23-45-67");

result = find_first_nonzero_mac(R"(afCD-EF-01-23-45-67)");
REQUIRE(result.has_value());
CHECK(*result.get() == "CD-EF-01-23-45-67");
}
Loading