Files
slsDetectorPackage/etc/updateAPIVersion.py
T
mazzol_aandGitHub 7db947e4d2
Build on RHEL9 docker image / build (push) Successful in 4m15s
Build on RHEL8 docker image / build (push) Successful in 5m21s
Build and Deploy on local RHEL9 / build (push) Successful in 2m12s
Build and Deploy on local RHEL8 / build (push) Successful in 5m12s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m55s
Run Simulator Tests on local RHEL8 / build (push) Successful in 22m19s
Dev/matterhorn server funcs (#1469)
* added fetch fmt server library

* added first draft of matterhorn

* added cpp TCP Interface to slsDetectorServer

* bug: added std::signal for proper handling of ctr+c

* added compile option to set log level

* WIP

* dont use c project settings when building matterhornserver

* updated logger

* WIP

* WIP

* linked fmt to slsProjectOptions

* solved merge conflict

* some refactoring

* cleaned up logs

* WIP

* generated register defs from csv file

* oops given in hex

* properly added fmt as a dependency

* some format changes

* WIP

* used CRTP for virtual detector

* WIP

* added udp functions to matterhornserver

* fixed build

* added Server class usable for all detectors

* removed stopserver

* added some more functions

* wrong overload

* porper cleanup of matterhorn app

* PR Review

* refactored directory structure

* added shared memory for aqcuisition status

* implemented bus read and write

* added Matterhorn data class

* modified memory model

* added SPI communication

* moved memory for Bus communication to BucCommunication class

* WIP added HelperFunction for mask conversion

* completed HelperFunctions

* added tests for MatterHorn Helper Functions

* removed shared memory in destructor

* fixed SPI communication

* moved SharedMemory to slsSupportLib

* added toolchain file for cross compilation

* fix constructor for HarwareSPICommunication is public

* update receiver parameters function

* updated mac address

* uploaded matterhorn server binary tracked as lfs

* small fixes from tests on board

* automatically update matterhorn api version when cross compiling binaries

* fix bug in SPI read

* copy to server_directory/bin when cross compiling

* fixed cmake list

* update generate_registerdefs.py

* fixed copy of server binary

* always return error message

* add error log when opening dev/mem

* code review

* fixed eiger, mythen tests for dynamic range

* second Review

* member function getDerived for better readability

* split code into implementation class and actual class doing tcp communication

* added slsWarnings and c++17 compiler option

* added git lfs to workflow

* fix gitea workflows

* bug: add extra clock register

* implement initial checks

* bug: client excpetcs 4 bytes

* refactoring directory structure and rename to .hpp

* check if detector already set up

* missed .h to .hpp

* Code Review 3

* use temmplate value for stopserver

* use internal CMAKE_CROSSCOMPILING variable

* moved boolean stop server flag to DetectorImpl - moving template parameter up

* missed a file

* replace baseclass:: with this

* add Matterhorn server in github workflow

* whatever workflow bug- lets see

* fixed receiving trim bits changed to int64_t
2026-07-16 10:10:14 +02:00

84 lines
2.8 KiB
Python

# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2025 Contributors to the SLS Detector Package
"""
Script to update API VERSION file based on the version in VERSION file.
"""
import argparse
import sys
from pathlib import Path
import os
import re
import time
from datetime import datetime
ROOT_DIR = Path(__file__).resolve().parent.parent
API_FILE = ROOT_DIR / "slsSupportLib/include/sls/versionAPI.h"
VERSION_FILE = ROOT_DIR / "VERSION"
parser = argparse.ArgumentParser(description = 'updates API version')
parser.add_argument('api_module_name', choices=["APILIB", "APIRECEIVER", "APICTB", "APIGOTTHARD2", "APIMOENCH", "APIEIGER", "APIXILINXCTB", "APIJUNGFRAU", "APIMYTHEN3", "APIMATTERHORN"], help = 'module name to change api version options are: ["APILIB", "APIRECEIVER", "APICTB", "APIGOTTHARD2", "APIMOENCH", "APIEIGER", "APIXILINXCTB", "APIJUNGFRAU", "APIMYTHEN3", "APIMATTERHORN"]')
parser.add_argument('api_dirs', nargs="+", help = 'Relative or absolute paths to the module code')
def update_api_file(new_api : str, api_module_name : str, api_file_name : str):
regex_pattern = re.compile(rf'#define\s+{api_module_name}\s+')
with open(api_file_name, "r") as api_file:
lines = api_file.readlines()
with open(api_file_name, "w") as api_file:
for line in lines:
if regex_pattern.match(line):
api_file.write(f'#define {api_module_name} "{new_api}"\n')
else:
api_file.write(line)
def get_latest_modification_date(directories : list[str]):
latest_time = 0
latest_date = None
for directory in directories:
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".o"):
continue
full_path = os.path.join(root, file)
try:
mtime = os.path.getmtime(full_path)
if mtime > latest_time:
latest_time = mtime
except FileNotFoundError:
continue
latest_date = datetime.fromtimestamp(latest_time).strftime("%y%m%d")
return latest_date
def update_api_version(api_module_name : str, api_dir : str):
api_date = get_latest_modification_date(api_dir)
api_date = "0x"+str(api_date)
with open(VERSION_FILE, "r") as version_file:
api_version = version_file.read().strip()
api_version = api_version + " " + api_date #not sure if we should give an argument option version_branch
update_api_file(api_version, api_module_name, API_FILE)
print(f"updated {api_module_name} api version to: {api_version}")
if __name__ == "__main__":
args = parser.parse_args()
api_dirs = [ROOT_DIR / api_dir for api_dir in args.api_dirs]
update_api_version(args.api_module_name, api_dirs)