diff options
author | robot-piglet <[email protected]> | 2025-08-31 20:00:36 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-08-31 20:11:04 +0300 |
commit | 19c9ebfca4556e766aa7121e3893cb235022256e (patch) | |
tree | bc59bc6869ac28224700228e66849ef48f69626b /contrib/libs/jinja2cpp | |
parent | 2ab5cfb1d5db344f7ac3c66671594f3b0a590ab3 (diff) |
Intermediate changes
commit_hash:d8a5d171761d004556c21491e0dbec959e6818a5
Diffstat (limited to 'contrib/libs/jinja2cpp')
8 files changed, 313 insertions, 0 deletions
diff --git a/contrib/libs/jinja2cpp/.yandex_meta/__init__.py b/contrib/libs/jinja2cpp/.yandex_meta/__init__.py new file mode 100644 index 00000000000..676cf51bfb2 --- /dev/null +++ b/contrib/libs/jinja2cpp/.yandex_meta/__init__.py @@ -0,0 +1,72 @@ +import os + +from devtools.yamaker import boost +from devtools.yamaker import fileutil +from devtools.yamaker import pathutil +from devtools.yamaker.project import CMakeNinjaNixProject + + +HEADERS_FROM_STD = ["optional", "string_view", "variant"] +TOKENS_FROM_STD = [ + "basic_string_view", + "get", + "get_if", + "optional", + "string_view", + "variant", + "visit", + "wstring_view", +] + + +def post_install(self): + with self.yamakes["."] as jinja2cpp: + # Emulate -DJINJA2CPP_WITH_JSON_BINDINGS=rapid which is broken in upstream + os.remove(f"{self.dstdir}/src/binding/boost_json_serializer.h") + os.remove(f"{self.dstdir}/src/binding/boost_json_serializer.cpp") + jinja2cpp.SRCS.remove("src/binding/boost_json_serializer.cpp") + + jinja2cpp.PEERDIR += [ + boost.make_arcdir("algorithm"), + boost.make_arcdir("container"), + boost.make_arcdir("numeric_conversion"), + boost.make_arcdir("unordered"), + boost.make_arcdir("variant"), + ] + + # use optional, string_view and variant from std without relying onto nonstd proxies + for header in HEADERS_FROM_STD: + fileutil.re_sub_dir( + self.dstdir, + f"<nonstd/{header}.hpp>", + f"<{header}>", + test=pathutil.is_preprocessable, + ) + + for token in TOKENS_FROM_STD: + fileutil.re_sub_dir( + self.dstdir, + rf"nonstd::{token}\b", + f"std::{token}", + test=pathutil.is_preprocessable, + ) + + # use absolute includes for nonstd/expected.hpp + fileutil.re_sub_dir( + self.dstdir, + "<nonstd/expected.hpp>", + "<contrib/restricted/expected-lite/include/nonstd/expected.hpp>", + test=pathutil.is_preprocessable, + ) + + +jinja2cpp = CMakeNinjaNixProject( + owners=["g:cpp-contrib"], + arcdir="contrib/libs/jinja2cpp", + nixattr="jinja2cpp", + disable_includes=[ + "binding/boost_json_serializer.h", + ], + post_install=post_install, + addincl_global={".": {"contrib/libs/rapidjson/include"}}, +) diff --git a/contrib/libs/jinja2cpp/.yandex_meta/boost-external.patch b/contrib/libs/jinja2cpp/.yandex_meta/boost-external.patch new file mode 100644 index 00000000000..bb5df705ff9 --- /dev/null +++ b/contrib/libs/jinja2cpp/.yandex_meta/boost-external.patch @@ -0,0 +1,15 @@ +diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt +index fc8f51d..49c55b2 100644 +--- a/thirdparty/CMakeLists.txt ++++ b/thirdparty/CMakeLists.txt +@@ -70,8 +70,8 @@ endif() + + if (NOT DEFINED JINJA2_PRIVATE_LIBS_INT) + set(JINJA2CPP_PRIVATE_LIBS ${JINJA2CPP_PRIVATE_LIBS} +- Boost::variant Boost::filesystem Boost::algorithm Boost::lexical_cast Boost::json +- Boost::regex fmt RapidJson) ++ boost_variant boost_filesystem boost_algorithm boost_json ++ boost_regex fmt RapidJson) + else () + set (JINJA2CPP_PRIVATE_LIBS ${JINJA2_PRIVATE_LIBS_INT}) + endif () diff --git a/contrib/libs/jinja2cpp/.yandex_meta/default.nix b/contrib/libs/jinja2cpp/.yandex_meta/default.nix new file mode 100644 index 00000000000..f44f673c6f0 --- /dev/null +++ b/contrib/libs/jinja2cpp/.yandex_meta/default.nix @@ -0,0 +1,100 @@ +self: super: with self; let + + optional-lite = stdenv.mkDerivation rec { + name = "optional-lite"; + version = "3.6.0"; + + src = fetchFromGitHub { + owner = "martinmoene"; + repo = "optional-lite"; + rev = "v${version}"; + sha256 = "sha256-qmKuxYc0cpoOtRRb4okJZ8pYPvzQid1iqBctnhGlz6M="; + }; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = [ + "-DOPTIONAL_LITE_OPT_BUILD_TESTS=OFF" + ]; + }; + + variant-lite = stdenv.mkDerivation rec { + pname = "variant-lite"; + version = "2.0.0"; + + src = fetchFromGitHub { + owner = "martinmoene"; + repo = "variant-lite"; + rev = "v${version}"; + hash = "sha256-zLyzNzeD0C4e7CYqCCsPzkqa2cH5pSbL9vNVIxdkEfc="; + }; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = [ + "-DVARIANT_LITE_OPT_BUILD_TESTS=OFF" + ]; + }; + + string-view-lite = stdenv.mkDerivation rec { + pname = "string-view-lite"; + version = "1.7.0"; + + src = fetchFromGitHub { + owner = "martinmoene"; + repo = "string-view-lite"; + rev = "v${version}"; + hash = "sha256-L7b0MGp9grE/a9ppzsPe6UzEoA/yK3y1VD24OB7oadw="; + }; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = [ + "-DSTRING_VIEW_LITE_OPT_BUILD_TESTS=OFF" + ]; + }; + +in { + jinja2cpp = stdenv.mkDerivation rec { + pname = "jinja2cpp"; + version = "1.3.1"; + + src = fetchFromGitHub { + owner = "jinja2cpp"; + repo = "Jinja2Cpp"; + rev = "${version}"; + hash = "sha256-pWNHugUab0ACuhOivw4LZFcHhwxDSMsVz8hDiw/XVW8="; + }; + + patches = [ ./externals.patch ./boost-external.patch ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = [ + "-DJINJA2CPP_DEPS_MODE=external" + "-DJINJA2CPP_CXX_STANDARD=17" + "-DJINJA2CPP_BUILD_TESTS=FALSE" + + # FIXME: this setting has no effect, + # as CMakeLists.txt in upstream unconditionally overwrites it. + # We will emulate necessary behavior during post_install() + "-DJINJA2CPP_WITH_JSON_BINDINGS=none" + ]; + + CXXFLAGS = [ + "-DFMT_USE_INTERNAL=TRUE" + ]; + + buildInputs = [ + boost + gtest + fmt_9 + rapidjson + + expected-lite + optional-lite + string-view-lite + variant-lite + ]; + }; +} diff --git a/contrib/libs/jinja2cpp/.yandex_meta/externals.patch b/contrib/libs/jinja2cpp/.yandex_meta/externals.patch new file mode 100644 index 00000000000..a968f684325 --- /dev/null +++ b/contrib/libs/jinja2cpp/.yandex_meta/externals.patch @@ -0,0 +1,13 @@ +diff --git a/thirdparty/thirdparty-external.cmake b/thirdparty/thirdparty-external.cmake +index 524dabe..b2bb08b 100644 +--- a/thirdparty/thirdparty-external.cmake ++++ b/thirdparty/thirdparty-external.cmake +@@ -27,7 +27,7 @@ macro (find_hdr_package PKG_NAME HDR_PATH) + + if(${PKG_NAME}_FOUND) + if (NOT TARGET ${PKG_NAME}) +- imported_target_alias(${PKG_NAME} ALIAS "${PKG_NAME}::${PKG_NAME}") ++ imported_target_alias(${PKG_NAME} ALIAS "nonstd::${PKG_NAME}") + endif () + else() + message(FATAL_ERROR "${PKG_NAME} not found!") diff --git a/contrib/libs/jinja2cpp/patches/01-ambigious-format_to.sh b/contrib/libs/jinja2cpp/patches/01-ambigious-format_to.sh new file mode 100644 index 00000000000..8015407b2de --- /dev/null +++ b/contrib/libs/jinja2cpp/patches/01-ambigious-format_to.sh @@ -0,0 +1,2 @@ +sed -i 's|fmt::format_to|format_to|g' src/error_info.cpp +sed -i 's|format_to|fmt::format_to|g' src/error_info.cpp diff --git a/contrib/libs/jinja2cpp/patches/02-incomplete-types.patch b/contrib/libs/jinja2cpp/patches/02-incomplete-types.patch new file mode 100644 index 00000000000..c4a7fd4a0f7 --- /dev/null +++ b/contrib/libs/jinja2cpp/patches/02-incomplete-types.patch @@ -0,0 +1,57 @@ +--- contrib/libs/jinja2cpp/src/internal_value.cpp (index) ++++ contrib/libs/jinja2cpp/src/internal_value.cpp (working tree) +@@ -8,6 +8,20 @@ + namespace jinja2 + { + ++void InternalValue::SetParentData(const InternalValue& val) { ++ m_parentData = val.GetData(); ++} ++ ++void InternalValue::SetParentData(InternalValue&& val) { ++ m_parentData = std::move(val.GetData()); ++} ++ ++void ListAdapter::Iterator::increment() { ++ m_isFinished = !m_iterator->MoveNext(); ++ ++ m_currentIndex; ++ m_currentVal = m_isFinished ? InternalValue() : m_iterator->GetCurrent(); ++} ++ + std::atomic_uint64_t UserCallable::m_gen{}; + + bool Value::IsEqual(const Value& rhs) const +--- contrib/libs/jinja2cpp/src/internal_value.h (index) ++++ contrib/libs/jinja2cpp/src/internal_value.h (working tree) +@@ -382,15 +382,9 @@ public: + auto& GetParentData() {return m_parentData;} + auto& GetParentData() const {return m_parentData;} + +- void SetParentData(const InternalValue& val) +- { +- m_parentData = val.GetData(); +- } ++ void SetParentData(const InternalValue& val); + +- void SetParentData(InternalValue&& val) +- { +- m_parentData = std::move(val.GetData()); +- } ++ void SetParentData(InternalValue&& val); + + bool ShouldExtendLifetime() const + { +@@ -444,12 +438,7 @@ public: + private: + friend class boost::iterator_core_access; + +- void increment() +- { +- m_isFinished = !m_iterator->MoveNext(); +- ++ m_currentIndex; +- m_currentVal = m_isFinished ? InternalValue() : m_iterator->GetCurrent(); +- } ++ void increment(); + + bool equal(const Iterator& other) const + { diff --git a/contrib/libs/jinja2cpp/patches/iterators.patch b/contrib/libs/jinja2cpp/patches/iterators.patch new file mode 100644 index 00000000000..a92a9cd4a37 --- /dev/null +++ b/contrib/libs/jinja2cpp/patches/iterators.patch @@ -0,0 +1,11 @@ +--- a/src/string_converter_filter.cpp (index) ++++ b/src/string_converter_filter.cpp (working tree) +@@ -379,7 +379,7 @@ InternalValue StringConverter::Filter(const InternalValue& baseVal, RenderContex + if (string_length >= width) + return str; + auto whitespaces = width - string_length; +- str.insert(0, static_cast<std::string::size_type>(whitespaces + 1) / 2, ' '); ++ str = decltype(str)(static_cast<std::string::size_type>(whitespaces + 1) / 2, ' ') + str; + str.append(static_cast<std::string::size_type>(whitespaces / 2), ' '); + return TargetString(std::move(str)); + }); diff --git a/contrib/libs/jinja2cpp/patches/pr-259-fix_qadric_tojson.patch b/contrib/libs/jinja2cpp/patches/pr-259-fix_qadric_tojson.patch new file mode 100644 index 00000000000..569aa4875e7 --- /dev/null +++ b/contrib/libs/jinja2cpp/patches/pr-259-fix_qadric_tojson.patch @@ -0,0 +1,43 @@ +--- contrib/libs/jinja2cpp/src/serialize_filters.cpp (index) ++++ contrib/libs/jinja2cpp/src/serialize_filters.cpp (working tree) +@@ -152,27 +152,20 @@ InternalValue Serialize::Filter(const InternalValue& value, RenderContext& conte + DocumentWrapper jsonDoc; + const auto jsonValue = jsonDoc.CreateValue(value); + const auto jsonString = jsonValue.AsString(static_cast<uint8_t>(indent)); +- const auto result = std::accumulate(jsonString.begin(), jsonString.end(), ""s, [](const auto &str, const auto &c) +- { +- switch (c) +- { +- case '<': +- return str + "\\u003c"; +- break; +- case '>': +- return str +"\\u003e"; +- break; +- case '&': +- return str +"\\u0026"; +- break; +- case '\'': +- return str +"\\u0027"; +- break; +- default: +- return str + c; +- break; ++ std::string result = ""s; ++ for (char c : jsonString) { ++ if (c == '<') { ++ result.append("\\u003c"); ++ } else if (c == '>') { ++ result.append("\\u003e"); ++ } else if (c == '&') { ++ result.append("\\u0026"); ++ } else if (c == '\'') { ++ result.append("\\u0027"); ++ } else { ++ result.push_back(c); + } +- }); ++ } + + return result; + } |