Skip to content

Commit c8d1318

Browse files
authored
Versioning: use MAJOR.YYYYMMDD.PATCH.
2 parents 6a13413 + 43d3a08 commit c8d1318

File tree

12 files changed

+83
-42
lines changed

12 files changed

+83
-42
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ endforeach()
2424

2525
# Project details.
2626

27-
string(TIMESTAMP CURRENT_YEAR "%Y")
28-
string(TIMESTAMP CURRENT_MONTH "%m")
29-
string(TIMESTAMP CURRENT_DAY "%d")
27+
string(TIMESTAMP YEAR "%Y")
28+
string(TIMESTAMP MONTH "%m")
29+
string(TIMESTAMP DAY "%d")
3030

3131
project(libOpenCOR
32-
VERSION "${CURRENT_YEAR}.${CURRENT_MONTH}.${CURRENT_DAY}")
32+
VERSION "0.${YEAR}${MONTH}${DAY}.0")
3333

3434
string(TOLOWER "${CMAKE_PROJECT_NAME}" CMAKE_PROJECT_NAME_LC)
3535

cmake/packaging/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ if(WIN32)
8181
endif()
8282
endif()
8383

84-
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${CPACK_SYSTEM_NAME}${LIBRARY_ARCHITECTURE}${LIBRARY_TYPE}${LIBRARY_MODE})
84+
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}${CPACK_SYSTEM_NAME}${LIBRARY_ARCHITECTURE}${LIBRARY_TYPE}${LIBRARY_MODE})
8585

8686
# Package libOpenCOR.
8787

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
setup(
2525
name="libopencor",
26-
version=f"{year}.{month:02}.{day:02}",
26+
version=f"0.{year}{month:02}{day:02}.0",
2727
description="libOpenCOR is the backend library to OpenCOR, a cross-platform modelling environment, which can be used to organise, edit, simulate and analyse CellML files.",
2828
author="libOpenCOR contributors",
2929
url="https://opencor.ws/libopencor/",

src/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ endif()
5959

6060
# Configure the version file.
6161

62-
set(LIBOPENCOR_VERSION 0x${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH})
62+
foreach(VERSION_PART PROJECT_VERSION_MAJOR PROJECT_VERSION_PATCH)
63+
string(LENGTH ${${VERSION_PART}} VERSION_PART_LENGTH)
64+
65+
if(VERSION_PART_LENGTH EQUAL 1)
66+
set(${VERSION_PART}_PAD 0)
67+
endif()
68+
endforeach()
69+
70+
set(LIBOPENCOR_VERSION 0x${PROJECT_VERSION_MAJOR_PAD}${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH_PAD}${PROJECT_VERSION_PATCH})
6371
set(LIBOPENCOR_VERSION_STRING ${PROJECT_VERSION})
6472

6573
set(VERSION_HEADER_FILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in)
@@ -291,7 +299,7 @@ if(EMSCRIPTEN)
291299

292300
# Create a .tgz file for our generated .js file that can be used to distribute our JavaScript bindings.
293301

294-
set(TGZ_FILE ${CMAKE_BINARY_DIR}/../../../../${REAL_CMAKE_PROJECT_NAME}-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.tgz)
302+
set(TGZ_FILE ${CMAKE_BINARY_DIR}/../../../../${REAL_CMAKE_PROJECT_NAME}-${PROJECT_VERSION}.tgz)
295303

296304
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
297305
COMMAND ${CMAKE_COMMAND} -E make_directory package
@@ -377,7 +385,6 @@ else()
377385
CXX_VISIBILITY_PRESET hidden
378386
DEBUG_POSTFIX d
379387
PREFIX ""
380-
VERSION ${PROJECT_VERSION}
381388
VISIBILITY_INLINES_HIDDEN ON)
382389
endif()
383390

src/api/libopencor/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace libOpenCOR {
3030
* @return A number that represents the version of libOpenCOR.
3131
*/
3232

33-
unsigned int LIBOPENCOR_EXPORT version();
33+
uint64_t LIBOPENCOR_EXPORT version();
3434

3535
/**
3636
* Return the version of libOpenCOR as a string. The version string is in the format x.y.z, where the "."s are literal,

src/solver/solvercvode.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ limitations under the License.
3333
#include "sunnonlinsol/sunnonlinsol_fixedpoint.h"
3434
#include "sundialsend.h"
3535

36+
#include <utility>
37+
3638
namespace libOpenCOR {
3739

3840
// Right-hand side function.
@@ -289,11 +291,11 @@ bool SolverCvode::Impl::initialise(double pVoi, size_t pSize, double *pStates, d
289291
}
290292

291293
if (needUpperAndLowerHalfBandwidths) {
292-
if ((mUpperHalfBandwidth < 0) || (mUpperHalfBandwidth >= static_cast<int>(pSize))) {
294+
if ((mUpperHalfBandwidth < 0) || std::cmp_greater_equal(mUpperHalfBandwidth, pSize)) {
293295
addError(std::string("The upper half-bandwidth cannot be equal to ").append(toString(mUpperHalfBandwidth)).append(". It must be between 0 and ").append(toString(pSize - 1)).append("."));
294296
}
295297

296-
if ((mLowerHalfBandwidth < 0) || (mLowerHalfBandwidth >= static_cast<int>(pSize))) {
298+
if ((mLowerHalfBandwidth < 0) || std::cmp_greater_equal(mLowerHalfBandwidth, pSize)) {
297299
addError(std::string("The lower half-bandwidth cannot be equal to ").append(toString(mLowerHalfBandwidth)).append(". It must be between 0 and ").append(toString(pSize - 1)).append("."));
298300
}
299301
}

src/solver/solverkinsol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ limitations under the License.
3030
#include "sunlinsol/sunlinsol_sptfqmr.h"
3131
#include "sundialsend.h"
3232

33+
#include <utility>
34+
3335
namespace libOpenCOR {
3436

3537
// Compute system.
@@ -206,11 +208,11 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t
206208
}
207209

208210
if (needUpperAndLowerHalfBandwidths) {
209-
if ((mUpperHalfBandwidth < 0) || (mUpperHalfBandwidth >= static_cast<int>(pN))) {
211+
if ((mUpperHalfBandwidth < 0) || std::cmp_greater_equal(mUpperHalfBandwidth, pN)) {
210212
addError(std::string("The upper half-bandwidth cannot be equal to ").append(toString(mUpperHalfBandwidth)).append(". It must be between 0 and ").append(toString(pN - 1)).append("."));
211213
}
212214

213-
if ((mLowerHalfBandwidth < 0) || (mLowerHalfBandwidth >= static_cast<int>(pN))) {
215+
if ((mLowerHalfBandwidth < 0) || std::cmp_greater_equal(mLowerHalfBandwidth, pN)) {
214216
addError(std::string("The lower half-bandwidth cannot be equal to ").append(toString(mLowerHalfBandwidth)).append(". It must be between 0 and ").append(toString(pN - 1)).append("."));
215217
}
216218
}

src/version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ unsigned int secondDigit(unsigned int pTwoDigitNumber)
7474
return pTwoDigitNumber % TEN;
7575
}
7676

77-
unsigned int version()
77+
uint64_t version()
7878
{
7979
return LIBOPENCOR_VERSION;
8080
}

src/version.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
namespace libOpenCOR {
2020

2121
// clang-format off
22-
static constexpr unsigned int LIBOPENCOR_VERSION = @LIBOPENCOR_VERSION@;
22+
static constexpr auto LIBOPENCOR_VERSION = @LIBOPENCOR_VERSION@;
2323
// clang-format on
2424
static constexpr auto LIBOPENCOR_VERSION_STRING = "@LIBOPENCOR_VERSION_STRING@";
2525

tests/api/version/tests.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,51 @@ limitations under the License.
2222

2323
TEST(VersionTest, libOpenCOR)
2424
{
25-
static const int NINETEEN_HUNDRED = 1900;
26-
static const int ONE = 1;
25+
static const auto VERSION_MAJOR = 0;
26+
static const auto VERSION_PATCH = 0;
2727

28-
auto now = std::chrono::system_clock::now();
29-
auto now_time_t = std::chrono::system_clock::to_time_t(now);
30-
std::tm local_tm {};
28+
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
29+
std::tm tm {};
3130

3231
#ifdef BUILDING_ON_WINDOWS
33-
localtime_s(&local_tm, &now_time_t); // NOLINT
32+
localtime_s(&tm, &now); // NOLINT
3433
#else
35-
localtime_r(&now_time_t, &local_tm); // NOLINT
34+
localtime_r(&now, &tm); // NOLINT
3635
#endif
3736

38-
auto year = NINETEEN_HUNDRED + local_tm.tm_year;
39-
auto month = ONE + local_tm.tm_mon;
40-
auto day = local_tm.tm_mday;
37+
static const auto NINETEEN_HUNDRED = 1900;
38+
static const auto ONE = 1;
4139

42-
static const int TEN_THOUSAND = 10000;
43-
static const int HUNDRED = 100;
44-
static const int TEN = 10;
40+
const auto year = NINETEEN_HUNDRED + tm.tm_year;
41+
const auto month = ONE + tm.tm_mon;
42+
const auto day = tm.tm_mday;
4543

46-
int version = 0;
47-
int number = TEN_THOUSAND * year + HUNDRED * month + day;
44+
static const uint64_t TEN_BILLION = 10000000000;
45+
static const uint64_t TEN_THOUSAND = 10000;
46+
static const uint64_t HUNDRED = 100;
47+
static const uint64_t TEN = 10;
48+
49+
uint64_t version = 0;
50+
auto number = TEN_BILLION * VERSION_MAJOR + HUNDRED * (TEN_THOUSAND * static_cast<uint64_t>(year) + HUNDRED * static_cast<uint64_t>(month) + static_cast<uint64_t>(day)) + VERSION_PATCH;
4851

4952
for (int i = 0; number != 0; i += 4) {
5053
version |= (number % TEN) << i; // NOLINT
5154
number /= TEN;
5255
}
5356

54-
static const size_t VERSION_STRING_SIZE = 11;
57+
static const size_t VERSION_STRING_SIZE = 15;
5558

5659
std::array<char, VERSION_STRING_SIZE> versionString {};
5760

58-
EXPECT_EQ(std::snprintf(versionString.data(), VERSION_STRING_SIZE, "%d.%02d.%02d", year, month, day), VERSION_STRING_SIZE - 1); // NOLINT
61+
#ifdef BUILDING_USING_GNU
62+
# pragma GCC diagnostic push
63+
# pragma GCC diagnostic ignored "-Wformat-truncation"
64+
#endif
65+
std::snprintf(versionString.data(), VERSION_STRING_SIZE, "%d.%d%02d%02d.%d", VERSION_MAJOR, year, month, day, VERSION_PATCH); // NOLINT
5966
// Note: ideally, we would be using std::format(), but it is not available on some of the CI systems we are using.
67+
#ifdef BUILDING_USING_GNU
68+
# pragma GCC diagnostic pop
69+
#endif
6070

6171
EXPECT_EQ(version, libOpenCOR::version());
6272
EXPECT_EQ(versionString.data(), libOpenCOR::versionString());

0 commit comments

Comments
 (0)