From 7415935b329d1881acf148472e2a62f536341bf7 Mon Sep 17 00:00:00 2001
From: Tristan Laurent <tristan.laurent@cs-soprasteria.com>
Date: Thu, 30 Jan 2025 16:10:33 +0100
Subject: [PATCH] ENH: do not recompile bindings already compiled with good
 python version

---
 CMakeLists.txt                                | 19 +++++++++++++++++
 Packaging/Files/post_install.sh.in            |  6 +++---
 .../Maintenance/update_copyright_date.sh      | 21 +++++++++++++++++++
 3 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 473055c2bb..98c6cfed6c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -436,6 +436,25 @@ if(UNIX)
     DESTINATION .
     COMPONENT Core
     )
+  # output of python3 --version is "Python XX.XX.XX", notice the space that
+  # is used
+  execute_process(
+    COMMAND python3 --version
+    RESULT_VARIABLE CMD_RES
+    OUTPUT_VARIABLE PYTHON_VERSION_DURING_BUILD
+  )
+  # Get the first two digit and concatenate them
+  string(REGEX MATCH " ([0-9]+)\.([0-9]+)" TMP_VAR "${PYTHON_VERSION_DURING_BUILD}")
+
+  if (${CMAKE_MATCH_COUNT} EQUAL 2)
+    # CMAKE_MATCH_0 is the entire match
+    # See https://cmake.org/cmake/help/latest/variable/CMAKE_MATCH_n.html
+    set(PYTHON_VERSION_DURING_BUILD "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
+  else()
+    # set default version
+    set(PYTHON_VERSION_DURING_BUILD "310")
+  endif()
+  
   configure_file(${OTB_SOURCE_DIR}/Packaging/Files/post_install.sh.in
                  ${CMAKE_BINARY_DIR}/post_install.sh @ONLY)
   install( PROGRAMS
diff --git a/Packaging/Files/post_install.sh.in b/Packaging/Files/post_install.sh.in
index 8ff82bedf3..7e935214d0 100644
--- a/Packaging/Files/post_install.sh.in
+++ b/Packaging/Files/post_install.sh.in
@@ -37,9 +37,9 @@ ostype="$(lsb_release -is)"
 
 if [ "$ostype" != "RedHatEnterprise" ] ; then
   concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')"
-  # Recompile OTB Python bindings. By default on non RHEL OS, the packaged
-  # bindings are compiled for version 3.10
-  if [ "$concatpyversion" -ne "310" ]; then
+  # Compare the concat version with the version used to build this OTB package
+  # The python build version is filled by cmake
+  if [ "$concatpyversion" -ne "@PYTHON_VERSION_DURING_BUILD@" ]; then
     sh "$OTB_INSTALL_DIR"/recompile_bindings.sh
   fi
   # Check python version, if python 3.12 (ubuntu 24 and debian > 12) download
diff --git a/Utilities/Maintenance/update_copyright_date.sh b/Utilities/Maintenance/update_copyright_date.sh
index 9cc9bb5efc..9b2f36a0df 100755
--- a/Utilities/Maintenance/update_copyright_date.sh
+++ b/Utilities/Maintenance/update_copyright_date.sh
@@ -1,4 +1,25 @@
 #!/bin/bash
+#
+# Copyright (C) 2005-2025 Centre National d'Etudes Spatiales (CNES)
+#
+# This file is part of Orfeo Toolbox
+#
+#     https://www.orfeo-toolbox.org/
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Change the copyright date of all files (recursively) where this script is executed
 
 tmp_file_name="_tmp_file_list.txt"
 # get all files
-- 
GitLab