Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c17e406
vcpkg ci: Parse ci.baseline.txt to determine regressions
autoantwort Feb 7, 2022
a555645
Fix bug and implement PASSING, REMOVE FROM FAIL LIST and --passing-is…
autoantwort Feb 11, 2022
fc2cbb5
Apply Nicole's CR
autoantwort Mar 6, 2022
4671c2f
Merge branch 'main' into parse-ci.baseline.txt
autoantwort Mar 6, 2022
7549a57
Fix build
autoantwort Mar 6, 2022
a3797dc
Fix Formatting
autoantwort Mar 6, 2022
8fe0d2c
WIP
BillyONeal Mar 18, 2022
d9da60b
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 18, 2022
d5f0498
Extend SortedVector to allow merging different SortedVectors together.
BillyONeal Mar 18, 2022
6aa5eaa
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 18, 2022
81c0ccb
Move some parsing stuff into the cpp, add ParseMessages::exit_if_erro…
BillyONeal Mar 18, 2022
f573df3
Finish implementing parser in terms of ParserBase.
BillyONeal Mar 19, 2022
13010c2
Tests and bugfixes!
BillyONeal Mar 19, 2022
2bc6f62
Fix MacOS and Linux build failures.
BillyONeal Mar 21, 2022
f3dea2a
Remove std::cerr.
BillyONeal Mar 21, 2022
1f41c11
Generate messages map
BillyONeal Mar 21, 2022
c207828
Try to fix macos and linux again.
BillyONeal Mar 21, 2022
b089a02
Ensure all named triplets are in the exclusions map.
BillyONeal Mar 21, 2022
8eca723
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 22, 2022
7f7b54e
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 22, 2022
bfbbe6e
Fix bad merge.
BillyONeal Mar 22, 2022
b99de1d
Require the caller to pass the predicate in sorted vector rather than…
BillyONeal Mar 23, 2022
e97eac1
Revert the match_until change.
BillyONeal Mar 23, 2022
686d7cd
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 23, 2022
ffa2c8b
Revert "Require the caller to pass the predicate in sorted vector rat…
BillyONeal Mar 23, 2022
a3e92af
Localize --allow-unexpected-passing can only be used if a baseline is…
BillyONeal Mar 23, 2022
463db01
Revert ref qualification of extract_Xxx functions.
BillyONeal Mar 23, 2022
19ae76d
Simplify try_match_keyword.
BillyONeal Mar 23, 2022
c2a64a0
Merge remote-tracking branch 'origin/main' into parse-ci.baseline.txt
BillyONeal Mar 24, 2022
319ab06
Add more tests requested by Robert.
BillyONeal Mar 24, 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
16 changes: 13 additions & 3 deletions include/vcpkg-test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <vcpkg/base/files.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/pragmas.h>
#include <vcpkg/base/sortedvector.h>

#include <vcpkg/packagespec.h>
#include <vcpkg/statusparagraph.h>

#include <iomanip>
Expand Down Expand Up @@ -55,10 +57,18 @@ namespace Catch
{
static const std::string convert(const vcpkg::LocalizedString& value) { return "LL\"" + value.data() + "\""; }
};

template<>
struct StringMaker<vcpkg::PackageSpec>
{
static const std::string convert(const vcpkg::PackageSpec& value) { return value.to_string(); }
};
}

namespace vcpkg
{
inline std::ostream& operator<<(std::ostream& os, const PackageSpec& value) { return os << value.to_string(); }

inline std::ostream& operator<<(std::ostream& os, const LocalizedString& value)
{
return os << "LL" << std::quoted(value.data());
Expand All @@ -75,12 +85,12 @@ namespace vcpkg::Test

inline auto test_parse_control_file(const std::vector<std::unordered_map<std::string, std::string>>& v)
{
std::vector<vcpkg::Parse::Paragraph> pghs;
std::vector<vcpkg::Paragraph> pghs;
for (auto&& p : v)
{
pghs.emplace_back();
for (auto&& kv : p)
pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::Parse::TextRowCol{}));
pghs.back().emplace(kv.first, std::make_pair(kv.second, TextRowCol{}));
}
return vcpkg::SourceControlFile::parse_control_file("", std::move(pghs));
}
Expand Down Expand Up @@ -135,7 +145,7 @@ namespace vcpkg::Test
inline std::vector<FullPackageSpec> parse_test_fspecs(StringView sv, Triplet t = X86_WINDOWS)
{
std::vector<FullPackageSpec> ret;
Parse::ParserBase parser(sv, "test");
ParserBase parser(sv, "test");
while (!parser.at_eof())
{
auto opt = parse_qualified_specifier(parser);
Expand Down
18 changes: 18 additions & 0 deletions include/vcpkg/base/fwd/parse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

namespace vcpkg
{
struct IParseError;
struct ParseError;
struct SourceLoc;

enum class MessageKind
{
Warning,
Error,
};

struct ParseMessage;
struct ParseMessages;
struct ParserBase;
}
9 changes: 5 additions & 4 deletions include/vcpkg/base/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,11 @@ namespace vcpkg::Json
underlying_t underlying_;
};

ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse_file(
const Filesystem&, const Path&, std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse(StringView text,
StringView origin = {}) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<IParseError>> parse_file(const Filesystem&,
const Path&,
std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<IParseError>> parse(StringView text,
StringView origin = {}) noexcept;
std::pair<Value, JsonStyle> parse_file(vcpkg::LineInfo li, const Filesystem&, const Path&) noexcept;

std::string stringify(const Value&, JsonStyle style);
Expand Down
62 changes: 31 additions & 31 deletions include/vcpkg/base/parse.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

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

#include <vcpkg/base/messages.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>
Expand All @@ -11,7 +13,7 @@
#include <memory>
#include <string>

namespace vcpkg::Parse
namespace vcpkg
{
struct IParseError
{
Expand Down Expand Up @@ -51,12 +53,6 @@ namespace vcpkg::Parse
int column;
};

enum class MessageKind
{
Warning,
Error,
};

struct ParseMessage
{
SourceLoc location = {};
Expand All @@ -69,6 +65,9 @@ namespace vcpkg::Parse
{
std::unique_ptr<ParseError> error;
std::vector<ParseMessage> warnings;

void exit_if_errors_or_warnings(StringView origin) const;
bool good() const { return !error && warnings.empty(); }
};

struct ParserBase
Expand All @@ -81,6 +80,7 @@ namespace vcpkg::Parse
static constexpr bool is_icase_alpha(char32_t ch) { return is_lower_alpha(ch) || is_upper_alpha(ch); }
static constexpr bool is_ascii_digit(char32_t ch) { return ch >= '0' && ch <= '9'; }
static constexpr bool is_lineend(char32_t ch) { return ch == '\r' || ch == '\n' || ch == Unicode::end_of_file; }
static constexpr bool is_not_lineend(char32_t ch) { return !is_lineend(ch); }
Comment thread
BillyONeal marked this conversation as resolved.
Outdated
static constexpr bool is_alphanum(char32_t ch) { return is_icase_alpha(ch) || is_ascii_digit(ch); }
static constexpr bool is_alphadash(char32_t ch) { return is_icase_alpha(ch) || ch == '-'; }
static constexpr bool is_alphanumdash(char32_t ch) { return is_alphanum(ch) || ch == '-'; }
Expand All @@ -91,41 +91,41 @@ namespace vcpkg::Parse
}
static constexpr bool is_word_char(char32_t ch) { return is_alphanum(ch) || ch == '_'; }

StringView skip_whitespace() { return match_zero_or_more(is_whitespace); }
StringView skip_tabs_spaces()
static constexpr bool is_package_name_char(char32_t ch)
{
return match_zero_or_more([](char32_t ch) { return ch == ' ' || ch == '\t'; });
return is_lower_alpha(ch) || is_ascii_digit(ch) || ch == '-';
}
void skip_to_eof() { m_it = m_it.end(); }
void skip_newline()
{
if (cur() == '\r') next();
if (cur() == '\n') next();
}
void skip_line()

static constexpr bool is_feature_name_char(char32_t ch)
{
match_until(is_lineend);
skip_newline();
// TODO: we do not intend underscores to be valid, however there is currently a feature using them
// (libwebp[vwebp_sdl]).
// TODO: we need to rename this feature, then remove underscores from this list.
Comment thread
BillyONeal marked this conversation as resolved.
Outdated
return is_package_name_char(ch) || ch == '_';
}

StringView skip_whitespace();
StringView skip_tabs_spaces();
void skip_to_eof();
void skip_newline();
void skip_line();

template<class Pred>
StringView match_zero_or_more(Pred p)
StringView match_while(Pred p)
{
const char* start = m_it.pointer_to_current();
auto ch = cur();
while (ch != Unicode::end_of_file && p(ch))
{
ch = next();
}

return {start, m_it.pointer_to_current()};
}
template<class Pred>
StringView match_until(Pred p)
{
const char* start = m_it.pointer_to_current();
auto ch = cur();
while (ch != Unicode::end_of_file && !p(ch))
ch = next();
return {start, m_it.pointer_to_current()};
}

bool require_character(char ch);

bool try_match_keyword(StringView keyword_content);

StringView text() const { return m_text; }
Unicode::Utf8Decoder it() const { return m_it; }
Expand All @@ -144,10 +144,10 @@ namespace vcpkg::Parse
void add_warning(LocalizedString&& message, const SourceLoc& loc);

const IParseError* get_error() const { return m_messages.error.get(); }
std::unique_ptr<IParseError> extract_error() { return std::move(m_messages.error); }
std::unique_ptr<IParseError> extract_error() && { return std::move(m_messages.error); }

const ParseMessages& messages() const { return m_messages; }
ParseMessages extract_messages() { return std::move(m_messages); }
ParseMessages extract_messages() && { return std::move(m_messages); }

private:
Unicode::Utf8Decoder m_it;
Expand Down
93 changes: 76 additions & 17 deletions include/vcpkg/base/sortedvector.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
#pragma once

#include <algorithm>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <vector>

// Add more forwarding functions to the m_data std::vector as needed.
namespace vcpkg
{
template<class T>
template<class Ty, class Compare = std::less<>>
struct SortedVector
{
using size_type = typename std::vector<T>::size_type;
using iterator = typename std::vector<T>::const_iterator;
using size_type = typename std::vector<Ty>::size_type;
using iterator = typename std::vector<Ty>::const_iterator;

SortedVector() : m_data() { }
SortedVector() : m_data(), m_comp() { }
SortedVector(const SortedVector&) = default;
SortedVector(SortedVector&&) = default;
SortedVector& operator=(const SortedVector&) = default;
SortedVector& operator=(SortedVector&&) = default;

explicit SortedVector(std::vector<T> v) : m_data(std::move(v))
explicit SortedVector(const std::vector<Ty>& data) : m_data(data), m_comp() { sort_uniqueify(); }
explicit SortedVector(const std::vector<Ty>& data, Compare comp) : m_data(data), m_comp(comp)
{
if (!std::is_sorted(m_data.begin(), m_data.end()))
{
std::sort(m_data.begin(), m_data.end());
}
sort_uniqueify();
}
explicit SortedVector(std::vector<Ty>&& data) : m_data(std::move(data)), m_comp() { sort_uniqueify(); }
explicit SortedVector(std::vector<Ty>&& data, Compare comp) : m_data(std::move(data)), m_comp(comp)
{
sort_uniqueify();
}

template<class Compare>
SortedVector(std::vector<T> v, Compare comp) : m_data(std::move(v))
template<class InIt>
explicit SortedVector(InIt first, InIt last) : m_data(first, last), m_comp()
{
if (!std::is_sorted(m_data.cbegin(), m_data.cend(), comp))
{
std::sort(m_data.begin(), m_data.end(), comp);
}
sort_uniqueify();
}

template<class InIt>
explicit SortedVector(InIt first, InIt last, Compare comp) : m_data(first, last), m_comp(comp)
{
sort_uniqueify();
}

SortedVector(std::initializer_list<Ty> elements) : m_data(elements), m_comp() { sort_uniqueify(); }

iterator begin() const { return this->m_data.cbegin(); }

iterator end() const { return this->m_data.cend(); }
Expand All @@ -43,9 +58,53 @@ namespace vcpkg

size_type size() const { return this->m_data.size(); }

const T& operator[](int i) const { return this->m_data[i]; }
const Ty& operator[](std::size_t i) const { return this->m_data[i]; }

bool contains(const Ty& element) const { return std::binary_search(m_data.begin(), m_data.end(), element); }

void append(const SortedVector& other)
{
// This could use a more efficient merge algorithm than inplace_merge with an understanding that we will
// allocate the whole result if perf becomes a problem
auto merge_point = m_data.insert(m_data.end(), other.begin(), other.end());
std::inplace_merge(m_data.begin(), merge_point, m_data.end(), m_comp);
uniqueify();
}

void append(SortedVector&& other)
{
auto merge_point = m_data.insert(
m_data.end(), std::make_move_iterator(other.begin()), std::make_move_iterator(other.end()));
std::inplace_merge(m_data.begin(), merge_point, m_data.end(), m_comp);
uniqueify();
}

friend bool operator==(const SortedVector& lhs, const SortedVector& rhs) { return lhs.m_data == rhs.m_data; }
friend bool operator!=(const SortedVector& lhs, const SortedVector& rhs) { return lhs.m_data != rhs.m_data; }

private:
std::vector<T> m_data;
void uniqueify()
{
Compare comp = m_comp;
m_data.erase(std::unique(m_data.begin(),
m_data.end(),
[comp](const Ty& lhs, const Ty& rhs) {
// note that we know !comp(rhs, lhs) because m_data is sorted
return !comp(lhs, rhs);
}),
m_data.end());
}
void sort_uniqueify()
{
if (!std::is_sorted(m_data.begin(), m_data.end(), m_comp))
{
std::sort(m_data.begin(), m_data.end(), m_comp);
}

uniqueify();
}

std::vector<Ty> m_data;
Compare m_comp;
Comment thread
BillyONeal marked this conversation as resolved.
};
}
2 changes: 1 addition & 1 deletion include/vcpkg/binaryparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace vcpkg
struct BinaryParagraph
{
BinaryParagraph();
explicit BinaryParagraph(Parse::Paragraph fields);
explicit BinaryParagraph(Paragraph fields);
BinaryParagraph(const SourceParagraph& spgh,
Triplet triplet,
const std::string& abi_tag,
Expand Down
Loading