Skip to content

Commit

Permalink
add version header
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Feb 8, 2025
1 parent 2e13ea6 commit e1ae034
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows-in/ys/common.ys
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ version-env =::
- name: Env (from tag)
if: contains(github.ref, 'tags/v')
run: |
source vars.sh
echo "SRC_VERSION_BODY=$SRC_VERSION_BODY" >> $GITHUB_ENV
- name: Variables (from commit, no tag)
if: ${{ !contains(github.ref, 'tags/v') }}
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ set(C4CORE_SRC_FILES
c4/utf.hpp
c4/utf.cpp
c4/windows.hpp
c4/version.hpp
c4/version.cpp
c4/windows_pop.hpp
c4/windows_push.hpp
c4/c4core.natvis
Expand Down
5 changes: 5 additions & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Add header `c4/version.hpp`:
- `c4::version()`
- `c4::version_major()`
- `c4::version_minor()`
- `c4::version_patch()`
25 changes: 25 additions & 0 deletions src/c4/version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "c4/version.hpp"

namespace c4 {

const char* version()
{
return C4CORE_VERSION;
}

int version_major()
{
return C4CORE_VERSION_MAJOR;
}

int version_minor()
{
return C4CORE_VERSION_MINOR;
}

int version_patch()
{
return C4CORE_VERSION_PATCH;
}

} // namespace c4
22 changes: 22 additions & 0 deletions src/c4/version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _C4_VERSION_HPP_
#define _C4_VERSION_HPP_

/** @file version.hpp */

#define C4CORE_VERSION "0.2.3"
#define C4CORE_VERSION_MAJOR 0
#define C4CORE_VERSION_MINOR 2
#define C4CORE_VERSION_PATCH 3

#include <c4/export.hpp>

namespace c4 {

C4CORE_EXPORT const char* version();
C4CORE_EXPORT int version_major();
C4CORE_EXPORT int version_minor();
C4CORE_EXPORT int version_patch();

} // namespace c4

#endif /* _C4_VERSION_HPP_ */
15 changes: 15 additions & 0 deletions tbump.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ search = "c4_project\\(VERSION {current_version}"
[[file]]
src = "test/test_singleheader/CMakeLists.txt"
search = "c4_project\\(VERSION {current_version}"
[[file]]
src = "src/c4/version.hpp"
search = "#define C4CORE_VERSION ['\"]{current_version}['\"]"
[[file]]
src = "src/c4/version.hpp"
version_template = "{major}"
search = "#define C4CORE_VERSION_MAJOR {current_version}"
[[file]]
src = "src/c4/version.hpp"
version_template = "{minor}"
search = "#define C4CORE_VERSION_MINOR {current_version}"
[[file]]
src = "src/c4/version.hpp"
version_template = "{patch}"
search = "#define C4CORE_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 @@ -30,6 +30,7 @@ function(c4core_test name)
c4_add_test(c4core-test-${name} ARGS --duration=on --no-version=on)
endfunction()

c4core_test(version test_version.cpp)
c4core_test(preprocessor test_preprocessor.cpp)
c4core_test(type_name test_type_name.cpp)
c4core_test(types test_types.cpp)
Expand Down
32 changes: 32 additions & 0 deletions test/test_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "c4/test.hpp"
#ifndef C4CORE_SINGLE_HEADER
#include "c4/version.hpp"
#endif

TEST_CASE("version.major")
{
int v = c4::version_major();
CHECK_GE(v, 0);
CHECK_EQ(v, C4CORE_VERSION_MAJOR);
}

TEST_CASE("version.minor")
{
int v = c4::version_minor();
CHECK_GE(v, 0);
CHECK_EQ(v, C4CORE_VERSION_MINOR);
}

TEST_CASE("version.patch")
{
int v = c4::version_patch();
CHECK_GE(v, 0);
CHECK_EQ(v, C4CORE_VERSION_PATCH);
}

TEST_CASE("version.str")
{
c4::csubstr v = c4::to_csubstr(c4::version());
CHECK_GE(v.len, 5);
CHECK_EQ(v, C4_XQUOTE(C4CORE_VERSION_MAJOR) "." C4_XQUOTE(C4CORE_VERSION_MINOR) "." C4_XQUOTE(C4CORE_VERSION_PATCH) "");
}
2 changes: 2 additions & 0 deletions tools/amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def amalgamate_c4core(filename: str,
am.cmtfile("LICENSE.txt"),
am.injcode(exports_def_code),
"src/c4/export.hpp",
"src/c4/version.hpp",
"src/c4/preprocessor.hpp",
"src/c4/platform.hpp",
"src/c4/cpu.hpp",
Expand Down Expand Up @@ -112,6 +113,7 @@ def amalgamate_c4core(filename: str,
am.ignfile("src/c4/c4_pop.hpp"),
am.ignfile("src/c4/restrict.hpp"),
am.ignfile("src/c4/unrestrict.hpp"),
"src/c4/version.cpp",
"src/c4/language.cpp",
"src/c4/format.cpp",
"src/c4/memory_util.cpp",
Expand Down

0 comments on commit e1ae034

Please sign in to comment.