Skip to content

Commit

Permalink
Enable linux tests (#265)
Browse files Browse the repository at this point in the history
* Use sequential map
* Enable tests
  • Loading branch information
mwasplund authored Sep 21, 2024
1 parent 9a0a875 commit d234e35
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Source/Client/Core/Recipe.sml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Source: [
]
Dependencies: {
Build: [
# 'mwasplund|Soup.Test.Cpp@0'
'mwasplund|Soup.Test.Cpp@0'
]
Runtime: [
'mwasplund|Opal@0'
Expand Down
10 changes: 5 additions & 5 deletions Source/Client/Core/Source/LocalUserConfig/LocalUserConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ namespace Soup::Core
private:
bool HasValue(std::string_view key)
{
return _table.contains(key.data());
return _table.Contains(key.data());
}

RecipeValue& GetValue(std::string_view key)
const RecipeValue& GetValue(std::string_view key) const
{
auto findItr = _table.find(key.data());
if (findItr != _table.end())
const RecipeValue* value;
if ( _table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand Down
21 changes: 4 additions & 17 deletions Source/Client/Core/Source/LocalUserConfig/SDKConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,15 @@ namespace Soup::Core
private:
bool HasValue(std::string_view key) const
{
return _table.contains(key.data());
return _table.Contains(key.data());
}

const RecipeValue& GetValue(std::string_view key) const
{
auto findItr = _table.find(key.data());
if (findItr != _table.end())
const RecipeValue* value;
if ( _table.TryGet(key.data(), value))
{
return findItr->second;
}
else
{
throw std::runtime_error("Requested recipe value does not exist in the root table.");
}
}

RecipeValue& GetValue(std::string_view key)
{
auto findItr = _table.find(key.data());
if (findItr != _table.end())
{
return findItr->second;
return *value;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions Source/Client/Core/Source/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ using namespace Opal;

#define CLIENT_CORE_IMPLEMENTATION

#include "Utils/SequenceMap.h"
#include "Build/RecipeBuildLocationManager.h"
#include "Build/BuildEngine.h"
#include "LocalUserConfig/LocalUserConfigExtensions.h"
Expand Down
14 changes: 7 additions & 7 deletions Source/Client/Core/Source/PackageLock/PackageLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ namespace Soup::Core
private:
bool HasValue(const RecipeTable& table, std::string_view key) const
{
return table.contains(key.data());
return table.Contains(key.data());
}

const RecipeValue& GetValue(const RecipeTable& table, std::string_view key) const
{
auto findItr = table.find(key.data());
if (findItr != table.end())
const RecipeValue* value;
if (table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand All @@ -198,10 +198,10 @@ namespace Soup::Core

RecipeValue& GetValue(RecipeTable& table, std::string_view key)
{
auto findItr = table.find(key.data());
if (findItr != table.end())
RecipeValue* value;
if (table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand Down
30 changes: 15 additions & 15 deletions Source/Client/Core/Source/Recipe/Recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ namespace Soup::Core

bool HasValue(const RecipeTable& table, std::string_view key) const
{
return table.contains(key.data());
return table.Contains(key.data());
}

const RecipeValue& GetValue(const RecipeTable& table, std::string_view key) const
{
auto findItr = table.find(key.data());
if (findItr != table.end())
const RecipeValue* value;
if (table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand All @@ -250,10 +250,10 @@ namespace Soup::Core

RecipeValue& GetValue(RecipeTable& table, std::string_view key)
{
auto findItr = table.find(key.data());
if (findItr != table.end())
RecipeValue* value;
if (table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand All @@ -263,10 +263,10 @@ namespace Soup::Core

RecipeValue& SetValue(RecipeTable& table, std::string_view key, RecipeValue&& value)
{
auto [insertIterator, wasInserted] = table.insert_or_assign(key.data(), std::move(value));
auto [wasInserted, valueReference] = table.TryInsert(key.data(), std::move(value));
if (wasInserted)
{
return insertIterator->second;
return *valueReference;
}
else
{
Expand All @@ -276,22 +276,22 @@ namespace Soup::Core

RecipeValue& EnsureTableValue(RecipeTable& table, std::string_view key)
{
auto findItr = table.find(key.data());
if (findItr != table.end())
RecipeValue* value;
if (table.TryGet(key.data(), value))
{
if (findItr->second.GetType() != RecipeValueType::Table)
if (value->GetType() != RecipeValueType::Table)
{
throw std::runtime_error("The recipe already has a non-table dependencies property");
}

return findItr->second;
return *value;
}
else
{
auto [insertIterator, wasInserted] = table.emplace(key.data(), RecipeValue(RecipeTable()));
auto [wasInserted, valueReference] = table.TryInsert(key.data(), RecipeValue(RecipeTable()));
if (wasInserted)
{
return insertIterator->second;
return *valueReference;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Source/Client/Core/Source/Recipe/RecipeSML.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Soup::Core
for (const auto& [key, value] : source.GetValue())
{
auto recipeValue = Parse(value);
target.emplace(key, std::move(recipeValue));
target.Insert(key, std::move(recipeValue));
}
}

Expand Down Expand Up @@ -162,11 +162,11 @@ namespace Soup::Core

static SMLTable Build(const RecipeTable& table)
{
auto result = std::unordered_map<std::string, SMLValue>();
auto result = SequenceMap<std::string, SMLValue>();

for (const auto& [key, value] : table)
{
result.emplace(key, Build(value));
result.Insert(key, Build(value));
}

return SMLTable(std::move(result));
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Core/Source/Recipe/RecipeValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Soup::Core
{
class RecipeValue;
using RecipeList = std::vector<RecipeValue>;
using RecipeTable = std::unordered_map<std::string, RecipeValue>;
using RecipeTable = SequenceMap<std::string, RecipeValue>;

enum class RecipeValueType
{
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/Core/Source/Recipe/RootRecipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ namespace Soup::Core
private:
bool HasValue(std::string_view key) const
{
return _table.contains(key.data());
return _table.Contains(key.data());
}

const RecipeValue& GetValue(std::string_view key) const
{
auto findItr = _table.find(key.data());
if (findItr != _table.end())
const RecipeValue* value;
if (_table.TryGet(key.data(), value))
{
return findItr->second;
return *value;
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions Source/Client/Core/Source/SML/SML.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ namespace Soup::Core

class SMLTable
{
private:
SequenceMap<std::string, SMLValue> _value;

public:
SMLTable() :
_value()
{
}

SMLTable(std::unordered_map<std::string, SMLValue> value) :
SMLTable(SequenceMap<std::string, SMLValue> value) :
_value(std::move(value))
{
}

bool Contains(const std::string& key) const
{
return _value.contains(key);
return _value.Contains(key);
}

const SMLValue& operator[](const std::string& key) const
{
return _value.at(key);
return _value[key];
}

const std::unordered_map<std::string, SMLValue>& GetValue() const
const SequenceMap<std::string, SMLValue>& GetValue() const
{
return _value;
}

private:
std::unordered_map<std::string, SMLValue> _value;
};

class SMLArray
Expand Down
11 changes: 5 additions & 6 deletions Source/Client/Core/Source/SML/SMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module;
# include <chrono>
#ifndef _WIN32 // TODO: MSVC BUG
# include <optional>
# include <unordered_map>
# include <vector>
#endif

Expand Down Expand Up @@ -413,7 +412,7 @@ class SMLParser : public SML::Lexer

bool TryParse()
{
std::unordered_map<std::string, SMLValue> table;
SequenceMap<std::string, SMLValue> table;
if (TryParseTableContents(table))
{
// Verify we are at the end of the content
Expand Down Expand Up @@ -577,7 +576,7 @@ class SMLParser : public SML::Lexer

bool TryParseTable(SMLTable& table)
{
std::unordered_map<std::string, SMLValue> tableValues;
SequenceMap<std::string, SMLValue> tableValues;
if (TryParseTableContents(tableValues))
{
// Verify we are at the end of the content
Expand All @@ -593,7 +592,7 @@ class SMLParser : public SML::Lexer
}
}

bool TryParseTableContents(std::unordered_map<std::string, SMLValue>& tableValues)
bool TryParseTableContents(SequenceMap<std::string, SMLValue>& tableValues)
{
// Odd move next to allow for optional extra delimiter checks at end
MoveNext();
Expand All @@ -614,7 +613,7 @@ class SMLParser : public SML::Lexer
if (!tableValue.has_value())
return true;

tableValues.emplace(std::move(key), std::move(tableValue.value()));
tableValues.Insert(std::move(key), std::move(tableValue.value()));

// Check for zero or more optional values
while (true)
Expand All @@ -640,7 +639,7 @@ class SMLParser : public SML::Lexer
return true;
}

tableValues.emplace(std::move(key), std::move(tableValue.value()));
tableValues.Insert(std::move(key), std::move(tableValue.value()));
}
}

Expand Down
Loading

0 comments on commit d234e35

Please sign in to comment.