From 74974a444734363d5456ed7a7f978b42b8ea3232 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 3 Aug 2024 21:07:00 +0200 Subject: [PATCH 1/4] Fixes #458 --- CMakeLists.txt | 1 + src/c4/yml/version.cpp | 27 +++++++++++++++++++++++++++ src/c4/yml/version.hpp | 25 +++++++++++++++++++++++++ src/c4/yml/yml.hpp | 1 + 4 files changed, 54 insertions(+) create mode 100644 src/c4/yml/version.cpp create mode 100644 src/c4/yml/version.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 762bb9710..f2f25578b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ c4_add_library(ryml c4/yml/tag.cpp c4/yml/tree.hpp c4/yml/tree.cpp + c4/yml/version.cpp c4/yml/writer.hpp c4/yml/yml.hpp ryml.natvis diff --git a/src/c4/yml/version.cpp b/src/c4/yml/version.cpp new file mode 100644 index 000000000..c54c1f4fd --- /dev/null +++ b/src/c4/yml/version.cpp @@ -0,0 +1,27 @@ +#include "c4/yml/version.hpp" + +namespace c4 { +namespace yml { + +csubstr version() +{ + return RYML_VERSION; +} + +int version_major() +{ + return RYML_VERSION_MAJOR; +} + +int version_minor() +{ + return RYML_VERSION_MINOR; +} + +int version_patch() +{ + return RYML_VERSION_PATCH; +} + +} // namespace yml +} // namespace c4 diff --git a/src/c4/yml/version.hpp b/src/c4/yml/version.hpp new file mode 100644 index 000000000..3057b79c6 --- /dev/null +++ b/src/c4/yml/version.hpp @@ -0,0 +1,25 @@ +#ifndef _C4_YML_VERSION_HPP_ +#define _C4_YML_VERSION_HPP_ + +/** @file version.hpp */ + +#define RYML_VERSION "0.7.0" +#define RYML_VERSION_MAJOR 0 +#define RYML_VERSION_MINOR 7 +#define RYML_VERSION_PATCH 0 + +#include +#include + +namespace c4 { +namespace yml { + +RYML_EXPORT csubstr version(); +RYML_EXPORT int version_major(); +RYML_EXPORT int version_minor(); +RYML_EXPORT int version_patch(); + +} // namespace yml +} // namespace c4 + +#endif /* _C4_YML_VERSION_HPP_ */ diff --git a/src/c4/yml/yml.hpp b/src/c4/yml/yml.hpp index dcd7c18d0..0f997246b 100644 --- a/src/c4/yml/yml.hpp +++ b/src/c4/yml/yml.hpp @@ -1,6 +1,7 @@ #ifndef _C4_YML_YML_HPP_ #define _C4_YML_YML_HPP_ +#include "c4/yml/version.hpp" #include "c4/yml/tree.hpp" #include "c4/yml/node.hpp" #include "c4/yml/emit.hpp" From 3cd7298df6f3276dd58ebcb7e0f39878d7f0e586 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sat, 10 Aug 2024 20:30:14 +0200 Subject: [PATCH 2/4] Adjust tbump.toml --- tbump.toml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tbump.toml b/tbump.toml index a7751f398..c59b3db93 100644 --- a/tbump.toml +++ b/tbump.toml @@ -49,7 +49,21 @@ search = ".*{current_version}.*" [[file]] src = "doc/sphinx_*.rst" search = ".*{current_version}.*" - +[[file]] +src = "src/c4/yml/version.hpp" +search = "#define RYML_VERSION ['\"]{current_version}['\"]" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{major}" +search = "#define RYML_VERSION_MAJOR {current_version}" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{minor}" +search = "#define RYML_VERSION_MINOR {current_version}" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{patch}" +search = "#define RYML_VERSION_PATCH {current_version}" # You can specify a list of commands to # run after the files have been patched From 293a472d4f5c9eb2e6773fb8eb755a2989f60edd Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Sat, 10 Aug 2024 21:19:27 +0100 Subject: [PATCH 3/4] Add version tests --- changelog/current.md | 15 +++++++++++++++ test/CMakeLists.txt | 1 + test/test_version.cpp | 29 +++++++++++++++++++++++++++++ tools/amalgamate.py | 2 ++ 4 files changed, 47 insertions(+) create mode 100644 test/test_version.cpp diff --git a/changelog/current.md b/changelog/current.md index c8327e9e2..9a176d5e3 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -1,3 +1,17 @@ +## New features + +- [PR#459](https://github.com/biojppm/rapidyaml/pull/459): Add version functions and macros: + ```cpp + #define RYML_VERSION "0.7.1" + #define RYML_VERSION_MAJOR 0 + #define RYML_VERSION_MINOR 7 + #define RYML_VERSION_PATCH 1 + csubstr version(); + int version_major(); + int version_minor(); + int version_patch(); + ``` + ## Fixes - Fix filtering of double-quoted keys in block maps ([PR#452](https://github.com/biojppm/rapidyaml/pull/452)) @@ -14,6 +28,7 @@ ## Thanks +- @marcalff - @toge - @musicinmybrain - @buty4649 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f49083261..e5cad7efe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,6 +79,7 @@ ryml_add_engine_test(parse_engine_6_qmrk) ryml_add_engine_test(parse_engine_7_seqimap) ryml_add_engine_test(parse_engine_8_scalars_tokens) ryml_add_engine_test(yaml_events) +ryml_add_test(version) ryml_add_test(callbacks) ryml_add_test(stack) ryml_add_test(filter) diff --git a/test/test_version.cpp b/test/test_version.cpp new file mode 100644 index 000000000..60cef79ab --- /dev/null +++ b/test/test_version.cpp @@ -0,0 +1,29 @@ +#ifndef RYML_SINGLE_HEADER +#include "c4/yml/version.hpp" +#endif +#include "./test_lib/test_case.hpp" +#include + +TEST(version, str) +{ + c4::csubstr v = c4::yml::version(); + EXPECT_GE(v.len, 5); +} + +TEST(version, major) +{ + int v = c4::yml::version_major(); + EXPECT_GE(v, 0); +} + +TEST(version, minor) +{ + int v = c4::yml::version_minor(); + EXPECT_GE(v, 0); +} + +TEST(version, patch) +{ + int v = c4::yml::version_patch(); + EXPECT_GE(v, 0); +} diff --git a/tools/amalgamate.py b/tools/amalgamate.py index 9ace1a9b4..4f8c761dd 100644 --- a/tools/amalgamate.py +++ b/tools/amalgamate.py @@ -87,6 +87,7 @@ def amalgamate_ryml(filename: str, am.onlyif(with_c4core, c4core_amalgamated), "src/c4/yml/export.hpp", "src/c4/yml/fwd.hpp", + "src/c4/yml/version.hpp", "src/c4/yml/common.hpp", "src/c4/yml/node_type.hpp", "src/c4/yml/tag.hpp", @@ -110,6 +111,7 @@ def amalgamate_ryml(filename: str, am.onlyif(with_stl, "src/c4/yml/std/string.hpp"), am.onlyif(with_stl, "src/c4/yml/std/vector.hpp"), am.onlyif(with_stl, "src/c4/yml/std/std.hpp"), + "src/c4/yml/version.cpp", "src/c4/yml/common.cpp", "src/c4/yml/node_type.cpp", "src/c4/yml/tag.cpp", From 022d2a2d652ac8d7b74e3d3a011b53b948ee5a96 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Sun, 11 Aug 2024 13:57:16 +0200 Subject: [PATCH 4/4] Update CMakeLists.txt --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2f25578b..ef7efaf4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ c4_add_library(ryml c4/yml/tag.cpp c4/yml/tree.hpp c4/yml/tree.cpp + c4/yml/version.hpp c4/yml/version.cpp c4/yml/writer.hpp c4/yml/yml.hpp