From bb7e2884feed6ff0bf8ea50818700f169116d397 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 29 May 2026 14:11:41 +0200 Subject: [PATCH] automatically update matterhorn api version when cross compiling binaries --- etc/updateAPIVersion.py | 33 ++++++++++--------- .../matterhornServer/CMakeLists.txt | 14 ++++++++ slsSupportLib/include/sls/versionAPI.h | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/etc/updateAPIVersion.py b/etc/updateAPIVersion.py index 84b160384..74c1289ec 100644 --- a/etc/updateAPIVersion.py +++ b/etc/updateAPIVersion.py @@ -20,8 +20,8 @@ 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"], help = 'module name to change api version options are: ["APILIB", "APIRECEIVER", "APICTB", "APIGOTTHARD2", "APIMOENCH", "APIEIGER", "APIXILINXCTB", "APIJUNGFRAU", "APIMYTHEN3"]') -parser.add_argument('api_dir', help = 'Relative or absolute path to the module code') +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): @@ -36,21 +36,22 @@ def update_api_file(new_api : str, api_module_name : str, api_file_name : str): else: api_file.write(line) -def get_latest_modification_date(directory : str): +def get_latest_modification_date(directories : list[str]): latest_time = 0 latest_date = None - 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 + 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") @@ -74,9 +75,9 @@ if __name__ == "__main__": args = parser.parse_args() - api_dir = ROOT_DIR / args.api_dir + api_dirs = [ROOT_DIR / api_dir for api_dir in args.api_dirs] - update_api_version(args.api_module_name, api_dir) + update_api_version(args.api_module_name, api_dirs) diff --git a/slsDetectorServers/matterhornServer/CMakeLists.txt b/slsDetectorServers/matterhornServer/CMakeLists.txt index dea7eddf4..3615e0c57 100644 --- a/slsDetectorServers/matterhornServer/CMakeLists.txt +++ b/slsDetectorServers/matterhornServer/CMakeLists.txt @@ -41,8 +41,22 @@ endif() # maybe better to have a else if build with simulators on one always use list(APPEND MATTERHORN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/MatterhornServer.cpp) +#mmh should slsSupportLib be considered as well when updating version? +if(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_TOOLCHAIN_FILE STREQUAL "") # only update version if cross compiling binaries + find_package(Python3 REQUIRED COMPONENTS Interpreter REQUIRED) + add_custom_target(update_server_version ALL + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/etc/updateAPIVersion.py APIMATTERHORN ${CMAKE_SOURCE_DIR}/slsDetectorServers/matterhornServer ${CMAKE_SOURCE_DIR}/slsDetectorServers/slsDetectorServer_cpp ${CMAKE_SOURCE_DIR}/slsSupportLib + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Updating APIMATTERHORN version" + VERBATIM) +endif() + add_executable(matterhornDetectorServer ${MATTERHORN_SOURCES}) +if(CMAKE_TOOLCHAIN_FILE AND NOT CMAKE_TOOLCHAIN_FILE STREQUAL "") # only update version if cross compiling binaries + add_dependencies(matterhornDetectorServer update_server_version) +endif() + target_compile_definitions(matterhornDetectorServer PRIVATE MATTERHORN_SERVER_HEADER= MATTERHORN_SERVER_CLASS=MatterhornServer diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 32fba195b..4da99e33a 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -10,4 +10,4 @@ #define APIXILINXCTB "0.0.0 0x260506" #define APIJUNGFRAU "0.0.0 0x260424" #define APIMYTHEN3 "0.0.0 0x260506" -#define APIMATTERHORN "0.0.0 0x260212" +#define APIMATTERHORN "0.0.0 0x260529"