Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ endforeach()

# Project details.

string(TIMESTAMP YEAR "%Y")
string(TIMESTAMP MONTH "%m")
string(TIMESTAMP DAY "%d")
file(READ "${CMAKE_SOURCE_DIR}/VERSION.txt" PROJECT_VERSION)

string(STRIP "${PROJECT_VERSION}" PROJECT_VERSION)

project(libOpenCOR
VERSION "0.${YEAR}${MONTH}${DAY}.0")
VERSION "${PROJECT_VERSION}")

string(TOLOWER "${CMAKE_PROJECT_NAME}" CMAKE_PROJECT_NAME_LC)

Expand Down
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.20250101.0
38 changes: 38 additions & 0 deletions newversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# Major version.

major_version=0

# Minor version.

now=$(date +%Y%m%d)
minor_version=$now

# Patch version.

patch_version=0

if latest_tag_commit=$(git rev-list --tags --max-count=1 2> /dev/null); then
if git_describe=$(git describe --tags "$latest_tag_commit" 2> /dev/null); then
if echo "$git_describe" | grep -Eo '^v?[0-9]+\.[0-9]+\.[0-9]+' > /dev/null; then
minor=$(echo "$git_describe" | cut -d. -f2)
patch=$(echo "$git_describe" | cut -d. -f3)
patch_version=$patch

if [ "$minor" = "$minor_version" ]; then
patch_version=$((patch_version + 1))
else
patch_version=0
fi
fi
fi
fi

# Full version.

version="$major_version.$minor_version.$patch_version"

# Update our version file.

echo $version > $(cd $(dirname $0); pwd)/VERSION.txt
50 changes: 50 additions & 0 deletions newversion.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

REM Major version.

SET MajorVersion=0

REM Minor version.

FOR /F "tokens=2 delims==" %%I IN ('wmic os get localdatetime /value') DO SET Now=%%I
SET MinorVersion=!Now:~0,8!
ECHO "MinorVersion: !MinorVersion!"

REM Patch version.

SET PatchVersion=0

FOR /F %%I IN ('git rev-list --tags --max-count=1 2^> NUL') DO (
SET LatestTagCommit=%%I
)
ECHO "LatestTagCommit: !LatestTagCommit!"

IF DEFINED LatestTagCommit (
FOR /F %%I IN ('git describe --tags !LatestTagCommit! 2^> NUL') DO (
SET GitDescribe=%%I
)
ECHO "GitDescribe: !GitDescribe!"

FOR /F "tokens=2,3 delims=." %%A IN ("!GitDescribe!") DO (
SET MinorVersion=%%A
ECHO "MinorVersion: !MinorVersion!"
SET PatchVersion=%%B
ECHO "PatchVersion: !PatchVersion!"

IF "!MinorVersion!"=="!MinorVersion!" (
SET /A PatchVersion+=1
) ELSE (
SET PatchVersion=0
)
)
)

REM Full version.

SET Version=!MajorVersion!.!MinorVersion!.!PatchVersion!

REM Update our version file.

ECHO !Version! > "%~dp0VERSION.txt"
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ if(NOT BASE64ENCODER_EXE)
message(FATAL_ERROR "base64encoder could not be built...")
endif()

# Copy of our version file over.

file(COPY ${CMAKE_SOURCE_DIR}/VERSION.txt
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# Include our different tests.

include(api/file/tests.cmake)
Expand Down
51 changes: 22 additions & 29 deletions tests/api/version/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,45 @@ limitations under the License.

#include <array>
#include <chrono>
#include <fstream>
#include <regex>
#include <libopencor>

TEST(VersionTest, libOpenCOR)
{
static const auto VERSION_MAJOR = 0;
static const auto VERSION_PATCH = 0;

auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm tm {};

#ifdef BUILDING_ON_WINDOWS
localtime_s(&tm, &now); // NOLINT
#else
localtime_r(&now, &tm); // NOLINT
#endif

static const auto NINETEEN_HUNDRED = 1900;
static const auto ONE = 1;

const auto year = NINETEEN_HUNDRED + tm.tm_year;
const auto month = ONE + tm.tm_mon;
const auto day = tm.tm_mday;

static const uint64_t TEN_BILLION = 10000000000;
static const uint64_t TEN_THOUSAND = 10000;
static const uint64_t HUNDRED = 100;
static const uint64_t TEN = 10;

std::ifstream versionFile("../../VERSION.txt");
std::string versionString;
std::getline(versionFile, versionString);

versionFile.close();

const std::regex versionRegex(R"((\d+)\.(\d{8})\.(\d+))");
std::smatch match;

ASSERT_TRUE(std::regex_match(versionString, match, versionRegex));

const uint64_t majorVersion = static_cast<uint64_t>(std::stoi(match[1]));
const uint64_t year = static_cast<uint64_t>(std::stoi(match[2].str().substr(0, 4)));
const uint64_t month = static_cast<uint64_t>(std::stoi(match[2].str().substr(4, 2)));
const uint64_t day = static_cast<uint64_t>(std::stoi(match[2].str().substr(6, 2)));
const uint64_t patchVersion = static_cast<uint64_t>(std::stoi(match[3]));
uint64_t version = 0;
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;
auto number = TEN_BILLION * majorVersion
+ HUNDRED * (TEN_THOUSAND * year + HUNDRED * month + day)
+ patchVersion;

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

static const int INT_TEN = 10;

auto versionString = std::to_string(VERSION_MAJOR)
+ "."
+ std::to_string(year) + ((month < INT_TEN) ? "0" : "") + std::to_string(month) + ((day < INT_TEN) ? "0" : "") + std::to_string(day)
+ "."
+ std::to_string(VERSION_PATCH);

EXPECT_EQ(version, libOpenCOR::version());
EXPECT_EQ(versionString.data(), libOpenCOR::versionString());
EXPECT_EQ(versionString, libOpenCOR::versionString());
}

TEST(VersionTest, Clang)
Expand Down
31 changes: 21 additions & 10 deletions tests/bindings/javascript/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,36 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import libOpenCOR from "./libopencor.js";

const loc = await libOpenCOR();

describe("Version tests", () => {
test("libOpenCOR", () => {
const versionMajor = 0;
const versionPatch = 0;

const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
const day = now.getDate();
const versionStr = fs
.readFileSync(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../../VERSION.txt",
),
"utf8",
)
.trim();
const [majorVersionStr, dateStr, patchVersionStr] = versionStr.split(".");
const majorVersion = Number(majorVersionStr);
const patchVersion = Number(patchVersionStr);
const year = Number(dateStr.slice(0, 4));
const month = Number(dateStr.slice(4, 6));
const day = Number(dateStr.slice(6, 8));

let version = BigInt(0);
let number = BigInt(
10000000000 * versionMajor +
10000000000 * majorVersion +
100 * (10000 * year + 100 * month + day) +
versionPatch,
patchVersion,
);
let i = BigInt(0);

Expand All @@ -47,7 +58,7 @@ describe("Version tests", () => {

expect(loc.version()).toBe(version);
expect(loc.versionString()).toBe(
`${versionMajor}.${year}${String(month).padStart(2, "0")}${String(day).padStart(2, "0")}.${versionPatch}`,
`${majorVersion}.${year}${String(month).padStart(2, "0")}${String(day).padStart(2, "0")}.${patchVersion}`,
);
});

Expand Down
22 changes: 12 additions & 10 deletions tests/bindings/python/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@
# limitations under the License.


import datetime
import libopencor as loc
import pathlib


version_major = 0
version_patch = 0
with open(pathlib.Path(__file__).parent.parent.parent / "VERSION.txt") as file:
version_str = file.read().strip()

now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day
major_version, date_str, patch_version = version_str.split(".")
major_version = int(major_version)
patch_version = int(patch_version)
year = int(date_str[:4])
month = int(date_str[4:6])
day = int(date_str[6:8])


def test_version():
version = 0
number = (
10000000000 * version_major
10000000000 * major_version
+ 100 * (10000 * year + 100 * month + day)
+ version_patch
+ patch_version
)
i = 0

Expand All @@ -45,7 +47,7 @@ def test_version():


def test_version_string():
version = f"{version_major}.{year}{month:02}{day:02}.{version_patch}"
version = f"{major_version}.{year}{month:02}{day:02}.{patch_version}"

assert loc.__version__ == version

Expand Down
Loading