Skip to content

Commit

Permalink
Merge pull request #459 from marcalff/fix_version_header
Browse files Browse the repository at this point in the history
Add version number in header files
  • Loading branch information
biojppm authored Aug 13, 2024
2 parents 5e35659 + 022d2a2 commit 0b761bc
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ 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
ryml.natvis
Expand Down
15 changes: 15 additions & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
@@ -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 [#455](https://github.com/biojppm/rapidyaml/issues/455): parsing of trailing val-less nested maps when deindented to maps ([PR#460](https://github.com/biojppm/rapidyaml/pull/460))
Expand All @@ -15,6 +29,7 @@
## Thanks
- @marcalff
- @toge
- @musicinmybrain
- @buty4649
27 changes: 27 additions & 0 deletions src/c4/yml/version.cpp
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions src/c4/yml/version.hpp
Original file line number Diff line number Diff line change
@@ -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 <c4/substr.hpp>
#include <c4/yml/export.hpp>

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_ */
1 change: 1 addition & 0 deletions src/c4/yml/yml.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 15 additions & 1 deletion tbump.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/test_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef RYML_SINGLE_HEADER
#include "c4/yml/version.hpp"
#endif
#include "./test_lib/test_case.hpp"
#include <gtest/gtest.h>

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);
}
2 changes: 2 additions & 0 deletions tools/amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0b761bc

Please sign in to comment.