Skip to content

Commit

Permalink
fixed and tested behaviour of new library
Browse files Browse the repository at this point in the history
fixed clang-format not doing a left merge correctly
  • Loading branch information
JessyDL committed Jun 10, 2024
1 parent bfdecfe commit 9b54f32
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion psl/inc/psl/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class metalib {
}

static constexpr psl::string8::view serialization_name {"METALIB"};
psl::serialization::property <"ENTRIES", std::vector<entry>> entries;
psl::serialization::property<"ENTRIES", std::vector<entry>> entries;
};

/// \brief container class for meta::file's
Expand Down
29 changes: 15 additions & 14 deletions psl/src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ const uint64_t file::polymorphic_identity {register_polymorphic<file>()};
library::library() {}

library::library(std::optional<psl::string8::view> lib, std::vector<psl::string8_t> environment) {
auto library = [&lib]() {
if(lib) {
// it makes no sense to specify a path if the file is not there, this must be a mistake or error.
psl_assert(
psl::utility::platform::file::exists(psl::from_string8_t(*lib)), "Could not find library at '{}'", *lib);
return psl::utility::platform::file::read(psl::from_string8_t(*lib)).value_or("");
}
return psl::string8_t();
}();
m_LibraryLocation = psl::utility::platform::directory::to_platform(lib.value_or(""));
auto loc = m_LibraryLocation.rfind(psl::to_string8_t(psl::utility::platform::directory::seperator));
m_LibraryFolder = psl::string8::view(&m_LibraryLocation[0], loc);
Expand All @@ -35,25 +26,35 @@ library::library(std::optional<psl::string8::view> lib, std::vector<psl::string8
"could not find library at '{}'",
m_LibraryLocation);

if(library.empty()) {
if(!lib) {
return;
}

// Load library into memory
serializer s;
metalib metalib;
s.deserialize<decode_from_format>(metalib, library);
s.deserialize<decode_from_format>(metalib, lib.value());

for(auto& entry : metalib.entries.value) {
psl_assert(m_MetaData.find(entry.first) == std::end(m_MetaData),
// here we handle environment variations
// if the environments for the file aren't empty we check if any_of the environments are also in the provided
// environment list, if not (or if the environment list is empty) we skip this entry
if(!entry.environments->empty() &&
!std::any_of(std::begin(environment), std::end(environment), [&entry](auto const& environment) {
return std::find(entry.environments->begin(), entry.environments->end(), environment) !=
entry.environments->end();
})) {
continue;
}
psl_assert(m_MetaData.find(entry.id) == std::end(m_MetaData),
"duplicate UID {} found in library",
entry.first.to_string());
entry.id->to_string());

auto full_metapath = psl::utility::platform::file::to_platform(root + entry.meta->path);
psl_assert(psl::utility::platform::file::exists(full_metapath),
"could not find file associated with UID {} at {}",
entry.id->to_string(),
entry.meta->path);
entry.meta->path.value);

file* metaPtr = nullptr;
s.deserialize<decode_from_format>(metaPtr, full_metapath);
Expand Down
15 changes: 14 additions & 1 deletion tools/clang-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@


def load_config(file: str = CONFIG_FILE):
# https://stackoverflow.com/a/24837438
def merge(dict1: dict, dict2: dict):
"""Recursively merges dict2 into dict1"""
if not isinstance(dict1, dict) or not isinstance(dict2, dict):
return dict2
for k in dict2:
if k in dict1:
dict1[k] = merge(dict1[k], dict2[k])
else:
dict1[k] = dict2[k]
return dict1

res = {
"formatting": {
"run-on-wsl": False,
Expand All @@ -28,7 +40,8 @@ def load_config(file: str = CONFIG_FILE):
}
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, "r") as f:
res = res | json.load(f)
res = merge(res, json.load(f))

if isinstance(res["formatting"]["clang-format"], str):
res["formatting"]["clang-format"] = [res["formatting"]["clang-format"]]
return res
Expand Down

0 comments on commit 9b54f32

Please sign in to comment.