Skip to content

Commit 43d3a08

Browse files
committed
Versioning: use MAJOR.YYYYMMDD.PATCH.
1 parent a843541 commit 43d3a08

File tree

10 files changed

+75
-38
lines changed

10 files changed

+75
-38
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/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());

tests/bindings/javascript/version.test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,34 @@ const libopencor = await libOpenCOR();
2020

2121
describe("Version tests", () => {
2222
test("libOpenCOR", () => {
23+
const version_major = 0;
24+
const version_patch = 0;
25+
2326
const now = new Date();
2427
const year = now.getFullYear();
2528
const month = now.getMonth() + 1;
2629
const day = now.getDate();
2730

28-
let version = 0;
29-
let number = 10000 * year + 100 * month + day;
30-
let i = 0;
31+
let version = BigInt(0);
32+
let number = BigInt(
33+
10000000000 * version_major +
34+
100 * (10000 * year + 100 * month + day) +
35+
version_patch,
36+
);
37+
let i = BigInt(0);
38+
39+
const ten = BigInt(10);
40+
const four = BigInt(4);
3141

3242
while (number != 0) {
33-
version |= number % 10 << i;
34-
number = Math.floor(number / 10);
35-
i += 4;
43+
version |= number % ten << i;
44+
number /= ten;
45+
i += four;
3646
}
3747

3848
expect(libopencor.version()).toBe(version);
3949
expect(libopencor.versionString()).toBe(
40-
`${year}.${String(month).padStart(2, "0")}.${String(day).padStart(2, "0")}`,
50+
`${version_major}.${year}${String(month).padStart(2, "0")}${String(day).padStart(2, "0")}.${version_patch}`,
4151
);
4252
});
4353

tests/bindings/python/test_version.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@
1717
import libopencor as oc
1818

1919

20+
version_major = 0
21+
version_patch = 0
22+
2023
now = datetime.datetime.now()
24+
year = now.year
25+
month = now.month
26+
day = now.day
2127

2228

2329
def test_version():
2430
version = 0
25-
number = 10000 * now.year + 100 * now.month + now.day
31+
number = (
32+
10000000000 * version_major
33+
+ 100 * (10000 * year + 100 * month + day)
34+
+ version_patch
35+
)
2636
i = 0
2737

2838
while number != 0:
@@ -35,7 +45,7 @@ def test_version():
3545

3646

3747
def test_version_string():
38-
version = f"{now.year}.{now.month:02}.{now.day:02}"
48+
version = f"{version_major}.{year}{month:02}{day:02}.{version_patch}"
3949

4050
assert oc.__version__ == version
4151

0 commit comments

Comments
 (0)