diff --git a/CMakeLists.txt b/CMakeLists.txt index 473055c2bb94bb81eb5751b2cf923c217388806d..98c6cfed6cdb88de748533ee4051a61a236d7055 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/build_gdal_bindings.sh b/Packaging/Files/build_gdal_bindings.sh index d8fd70d8a3f937ea2a3925a0ca4c264f88ce302c..affc3451aa9c5d0ad46f3026841dd365f55ce74b 100644 --- a/Packaging/Files/build_gdal_bindings.sh +++ b/Packaging/Files/build_gdal_bindings.sh @@ -25,18 +25,20 @@ if [ "$#" -ne 3 ]; then exit fi -SOURCEDIR=$1 -WORKDIR=$2 -INSTALLDIR=$WORKDIR/gdal_bindings_otb-$3-py312 +SOURCEDIR="$1" +WORKDIR="$2" +concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')" +INSTALLDIR="$WORKDIR/gdal_bindings_otb-$3-py$concatpyversion" echo "*** Checking out branch release-$3 ***" -cd $SOURCEDIR +cd "$SOURCEDIR" git checkout origin/release-$3 -pyversion="$(python3 -V 2>&1)" -echo "*** Building GDAL bindings with $pyversion for otb $3 ***" -mkdir $WORKDIR/gdal_build_otb-$3 && cd $WORKDIR/gdal_build_otb-$3 -cmake $SOURCEDIR/SuperBuild -DCMAKE_INSTALL_PREFIX=$INSTALLDIR -DDOWNLOAD_LOCATION=$WORKDIR/superbuild-archives +echo "*** Building GDAL bindings with $concatpyversion for otb $3 ***" +mkdir "$WORKDIR/gdal_build_otb-$3" && cd "$WORKDIR/gdal_build_otb-$3" +cmake "$SOURCEDIR/SuperBuild" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DDOWNLOAD_LOCATION="$WORKDIR/superbuild-archives" make -j16 GDAL + echo "*** Creating a tar gz of the gdal bindings in the directory $INSTALLDIR ***" -find $INSTALLDIR/lib/python3/dist-packages/osgeo/ -type f -name "*.so" -printf "%P\n" | tar -czf $INSTALLDIR/OTB-$3-GDAL-bindings-py312.tar.gz --no-recursion -C $INSTALLDIR/lib/python3/dist-packages/osgeo -T - +osgeopython=$(find "$INSTALLDIR/lib" -mindepth 3 -maxdepth 3 -type d -name "osgeo") +find "$osgeopython" -type f -name "*.so" -printf "%P\n" | tar -czf "$INSTALLDIR/OTB-$3-GDAL-bindings-py$concatpyversion.tar.gz" --no-recursion -C "$osgeopython" -T - diff --git a/Packaging/Files/otbenv.profile b/Packaging/Files/otbenv.profile index c40c49a2c729fafc400b56bf56edaaa7b8f4f68d..bc934b99dff63ca0537d706a9978b0f93ee3e1ce 100644 --- a/Packaging/Files/otbenv.profile +++ b/Packaging/Files/otbenv.profile @@ -42,7 +42,7 @@ OS="$(lsb_release -is)" # path may differ if [ -n "${BASH}" ]; then # dirname does not exists on RH-based OS - if [ $OS = "RedHatEnterprise" ] || [ $OS = "Fedora" ] || [ $OS = "RockyLinux" ]; then + if [ "$OS" = "RedHatEnterprise" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "RockyLinux" ]; then OTB_INSTALL_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))" elif [ -n "${BASH}" ]; then OTB_INSTALL_DIR="$( dirname -- "$( readlink -f -- "${BASH_SOURCE[0]}"; )"; )" @@ -51,7 +51,7 @@ else # non-bash shell OTB_INSTALL_DIR="$( dirname -- "$( readlink -f -- "$0"; )"; )" fi -CMAKE_PREFIX_PATH=$OTB_INSTALL_DIR +CMAKE_PREFIX_PATH="$OTB_INSTALL_DIR" export CMAKE_PREFIX_PATH # check and set OTB_APPLICATION_PATH @@ -62,7 +62,7 @@ PATH=$(cat_path "$OTB_INSTALL_DIR/bin" "$PATH") # export PYTHONPATH to import otbApplication.py PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/otb/python" "$PYTHONPATH") -if [ $OS = "RedHatEnterprise" ] || [ $OS = "Fedora" ] || [ $OS = "RockyLinux" ]; then +if [ "$OS" = "RedHatEnterprise" ] || [ "$OS" = "Fedora" ] || [ "$OS" = "RockyLinux" ]; then PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/python3.8/site-packages" "$PYTHONPATH") else PYTHONPATH=$(cat_path "$OTB_INSTALL_DIR/lib/python3/dist-packages" "$PYTHONPATH") @@ -76,7 +76,7 @@ GDAL_DATA="$OTB_INSTALL_DIR/share/gdal" PROJ_LIB="$OTB_INSTALL_DIR/share/proj" -export GDAL_DRIVER_PATH=disable +export GDAL_DRIVER_PATH="disable" export LD_LIBRARY_PATH="$OTB_INSTALL_DIR/lib:$LD_LIBRARY_PATH" diff --git a/Packaging/Files/post_install.sh.in b/Packaging/Files/post_install.sh.in index e14909d8fcd2197ffcc1535db38a4f91de606cce..7e935214d0dbe5a7607234fa233d859caf405682 100644 --- a/Packaging/Files/post_install.sh.in +++ b/Packaging/Files/post_install.sh.in @@ -33,27 +33,36 @@ sed -i "s/\/builds\/otb\/xdk/\$OTB_INSTALL_DIR/g" "$OTB_INSTALL_DIR"/bin/gdal-co sed -i "s/\/builds\/otb\/xdk/\$OTB_INSTALL_DIR/g" "$OTB_INSTALL_DIR"/bin/curl-config sh "$OTB_INSTALL_DIR"/tools/sanitize_rpath.sh -pyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')" ostype="$(lsb_release -is)" -# Recompile OTB Python bindings -if [ "$pyversion" -ne "310" ] && [ $ostype != "RedHatEnterprise" ] ; then + +if [ "$ostype" != "RedHatEnterprise" ] ; then + concatpyversion="$(python3 -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]*\).*/\1\2/')" + # 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 and extract the gdal bindings for python 3.12 -# In case your install is from compiled code, the gdal bindings will be already there in the installation -python_distpackage_path="$OTB_INSTALL_DIR/lib/python3/dist-packages/osgeo/" -gdal_python_found="$(find $python_distpackage_path -name "*$pyversion-x86_64-linux*")" -if [ -z "$gdal_python_found" ]; then - echo "***** Python $pyversion detected, downloading gdal bindings compiled for this Python version *****" - HTTP_STATUS=$(curl -s -o "$OTB_INSTALL_DIR"/tools/gdal-py$pyversion.tar.gz -w "%{response_code}\n" https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$pyversion.tar.gz) - if [ $HTTP_STATUS -eq 200 ]; then - tar -xf "$OTB_INSTALL_DIR"/tools/gdal-py$pyversion.tar.gz -C $python_distpackage_path - rm "$OTB_INSTALL_DIR"/tools/gdal-py$pyversion.tar.gz - echo "***** GDAL bindings for python $pyversion successfully installed *****" + fi + # Check python version, if python 3.12 (ubuntu 24 and debian > 12) download + # and extract the gdal bindings for python 3.12 + # In case your install is from compiled code, the gdal bindings will be + # already there in the installation + # Note that the install path differs from OS. To handle it, + # check before the folder name (always prefixed of python3) + osgeo_pkg_path=$(find "$OTB_INSTALL_DIR/lib" -mindepth 3 -maxdepth 3 -type d -name "osgeo") + gdal_python_found="$(find $osgeo_pkg_path -name "*$concatpyversion-x86_64-linux*")" + if [ -z "$gdal_python_found" ]; then + echo "***** Python $concatpyversion detected, downloading gdal bindings compiled for this Python version *****" + HTTP_STATUS=$(curl -s -o "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz -w "%{response_code}\n" https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$concatpyversion.tar.gz) + if [ "$HTTP_STATUS" -eq 200 ]; then + tar -xf "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz -C $python_distpackage_path + rm "$OTB_INSTALL_DIR"/tools/gdal-py$concatpyversion.tar.gz + echo "***** GDAL bindings for python $concatpyversion successfully installed *****" else - echo "Can not find GDAL bindings at https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$pyversion.tar.gz" - return -1 + echo "Can not find GDAL bindings at https://www.orfeo-toolbox.org/packages/archives/OTB/OTB-$OTB_SHORT_VERSION-GDAL-bindings-py$concatpyversion.tar.gz" + return -1 fi + fi fi + echo "***** OTB Environment and Python bindings setup complete *****" -echo "OK" > "$OTB_INSTALL_DIR"/tools/install_done.txt \ No newline at end of file +echo "OK" > "$OTB_INSTALL_DIR"/tools/install_done.txt diff --git a/Utilities/Maintenance/update_copyright_date.sh b/Utilities/Maintenance/update_copyright_date.sh new file mode 100755 index 0000000000000000000000000000000000000000..9b2f36a0dff989f1ab78024f7fe6b78e2e0fb2ff --- /dev/null +++ b/Utilities/Maintenance/update_copyright_date.sh @@ -0,0 +1,37 @@ +#!/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 +find . -type f > $tmp_file_name +current_year=$(date -u | egrep -o "[0-9]{4}") + +# for all files, update the year to current +while IFS= read -r f_path; do + # except for this current script + if [ "$f_path" != $0 ]; then + sed -i "s/Copyright (C) 2005-20../Copyright (C) 2005-$current_year/g" "$line" + fi +done < "$tmp_file_name" + +rm $tmp_file_name