Skip to content

Commit dbb09d9

Browse files
authored
Use <year>.<month>.<day> as a versioning system.
2 parents b5e79d9 + 38e4586 commit dbb09d9

File tree

6 files changed

+87
-23
lines changed

6 files changed

+87
-23
lines changed

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,22 @@
1414

1515
cmake_minimum_required(VERSION 3.15)
1616

17+
# Some CMake policies.
18+
19+
foreach(POLICY CMP0096 CMP0144)
20+
if(POLICY ${POLICY})
21+
cmake_policy(SET ${POLICY} NEW)
22+
endif()
23+
endforeach()
24+
25+
# Project details.
26+
27+
string(TIMESTAMP CURRENT_YEAR "%Y")
28+
string(TIMESTAMP CURRENT_MONTH "%m")
29+
string(TIMESTAMP CURRENT_DAY "%d")
30+
1731
project(libOpenCOR
18-
VERSION 0.0.0)
32+
VERSION "${CURRENT_YEAR}.${CURRENT_MONTH}.${CURRENT_DAY}")
1933

2034
string(TOLOWER "${CMAKE_PROJECT_NAME}" CMAKE_PROJECT_NAME_LC)
2135

@@ -25,13 +39,7 @@ set(CMAKE_CXX_STANDARD 20)
2539
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2640
set(CMAKE_CXX_EXTENSIONS OFF)
2741

28-
# Some common CMake policies, functions, and macros.
29-
30-
foreach(POLICY CMP0144)
31-
if(POLICY ${POLICY})
32-
cmake_policy(SET ${POLICY} NEW)
33-
endif()
34-
endforeach()
42+
# Some common functions and macros.
3543

3644
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
3745

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
# limitations under the License.
1414

1515

16+
import datetime
1617
from skbuild import setup
1718

19+
year = datetime.datetime.now().year
20+
month = datetime.datetime.now().month
21+
day = datetime.datetime.now().day
22+
1823
setup(
1924
name="libopencor",
20-
version="0.0.0",
25+
version=f"{year}.{month:02}.{day:02}",
2126
description="libOpenCOR is the backend library to OpenCOR, an open source cross-platform modelling environment.",
2227
author="libOpenCOR contributors",
2328
url="https://opencor.ws/libopencor",

src/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ endif()
5959

6060
# Configure the version file.
6161

62-
foreach(VERSION_PART PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH)
63-
if(${${VERSION_PART}} LESS 10)
64-
set(${VERSION_PART}_PAD 0)
65-
endif()
66-
endforeach()
67-
68-
set(LIBOPENCOR_VERSION 0x${PROJECT_VERSION_MAJOR_PAD}${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR_PAD}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH_PAD}${PROJECT_VERSION_PATCH})
62+
set(LIBOPENCOR_VERSION 0x${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH})
6963
set(LIBOPENCOR_VERSION_STRING ${PROJECT_VERSION})
7064

7165
set(VERSION_HEADER_FILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in)

tests/api/version/tests.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,37 @@ limitations under the License.
1616

1717
#include "tests/utils.h"
1818

19+
#include <array>
20+
#include <chrono>
1921
#include <libopencor>
2022

2123
TEST(VersionTest, libOpenCOR)
2224
{
23-
EXPECT_EQ(0x000000U, libOpenCOR::version());
24-
EXPECT_EQ("0.0.0", libOpenCOR::versionString());
25+
static const int TEN_THOUSAND = 10000;
26+
static const int HUNDRED = 100;
27+
static const int TEN = 10;
28+
29+
auto now = std::chrono::year_month_day {std::chrono::time_point_cast<std::chrono::days>(std::chrono::system_clock::now())};
30+
auto year = static_cast<int>(now.year());
31+
auto month = static_cast<int>(static_cast<unsigned>(now.month()));
32+
auto day = static_cast<int>(static_cast<unsigned>(now.day()));
33+
int version = 0;
34+
int number = TEN_THOUSAND * year + HUNDRED * month + day;
35+
36+
for (int i = 0; number != 0; i += 4) {
37+
version |= (number % TEN) << i; // NOLINT
38+
number /= TEN;
39+
}
40+
41+
static const size_t VERSION_STRING_SIZE = 11;
42+
43+
std::array<char, VERSION_STRING_SIZE> versionString {};
44+
45+
EXPECT_EQ(std::snprintf(versionString.data(), VERSION_STRING_SIZE, "%d.%02d.%02d", year, month, day), VERSION_STRING_SIZE - 1); // NOLINT
46+
// Note: ideally, we would be using std::format(), but it is not available on some of the CI systems we are using.
47+
48+
EXPECT_EQ(version, libOpenCOR::version());
49+
EXPECT_EQ(versionString.data(), libOpenCOR::versionString());
2550
}
2651

2752
TEST(VersionTest, Clang)

tests/bindings/javascript/version.test.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,25 @@ const libopencor = await libOpenCOR();
2020

2121
describe("Version tests", () => {
2222
test("libOpenCOR", () => {
23-
expect(libopencor.version()).toBe(0x000000);
24-
expect(libopencor.versionString()).toBe("0.0.0");
23+
const now = new Date();
24+
const year = now.getFullYear();
25+
const month = now.getMonth() + 1;
26+
const day = now.getDate();
27+
28+
let version = 0;
29+
let number = 10000 * year + 100 * month + day;
30+
let i = 0;
31+
32+
while (number != 0) {
33+
version |= number % 10 << i;
34+
number = Math.floor(number / 10);
35+
i += 4;
36+
}
37+
38+
expect(libopencor.version()).toBe(version);
39+
expect(libopencor.versionString()).toBe(
40+
`${year}.${String(month).padStart(2, "0")}.${String(day).padStart(2, "0")}`,
41+
);
2542
});
2643

2744
test("libCellML", () => {

tests/bindings/python/test_version.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@
1313
# limitations under the License.
1414

1515

16+
import datetime
1617
import libopencor as oc
1718

1819

20+
now = datetime.datetime.now()
21+
22+
1923
def test_version():
24+
version = 0
25+
number = 10000 * now.year + 100 * now.month + now.day
26+
i = 0
27+
28+
while number != 0:
29+
version |= (number % 10) << i
30+
number //= 10
31+
i += 4
32+
2033
assert isinstance(oc.version(), int)
21-
assert oc.version() == 0x000000
34+
assert oc.version() == version
2235

2336

2437
def test_version_string():
25-
assert oc.__version__ == "0.0.0"
38+
version = f"{now.year}.{now.month:02}.{now.day:02}"
39+
40+
assert oc.__version__ == version
2641

2742
assert isinstance(oc.version_string(), str)
28-
assert oc.version_string() == "0.0.0"
43+
assert oc.version_string() == version
2944

3045

3146
def test_clang_version():

0 commit comments

Comments
 (0)