From 9c3449c1bf510aab395280eb0da5e248a77f5e30 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Fri, 2 Sep 2016 12:03:33 +0200
Subject: [PATCH] undid the changes to use pbuilder in make_debian_package.sh.
 This conceptualluy does not work and will completely be changed in future.

---
 cmake/DebianPackaging.config    |  19 -----
 cmake/getDebianBuildVersion     | 113 ---------------------------
 cmake/make_debian_package.sh.in | 131 ++++++++------------------------
 3 files changed, 33 insertions(+), 230 deletions(-)
 delete mode 100644 cmake/DebianPackaging.config
 delete mode 100755 cmake/getDebianBuildVersion

diff --git a/cmake/DebianPackaging.config b/cmake/DebianPackaging.config
deleted file mode 100644
index 728f006..0000000
--- a/cmake/DebianPackaging.config
+++ /dev/null
@@ -1,19 +0,0 @@
-########################################################################################
-# Project-specific configuration for the Debian packaging scripts                      #
-#                                                                                      #
-# Please modify this file for your needs by copying a line, uncommenting it and then   #
-# modifying the uncommented copy. Keep the commented original copy to avoid conflicts! #
-########################################################################################
-
-# URI of the git repository containing the build version numbers
-#DEBIAN_BUILD_VERSIONS_REPO=git@github.com:ChimeraTK/DebianBuildVersions.git
-
-########################################################################################
-#  NO USER CONFIGURATION BELOW THIS POINT! DO NOT MODIFY OUTSIDE THE project-template  #
-########################################################################################
-ERROR_MESSAGE="DebianPackaging.config is not properly updated for this package!"
-if [ -z "$DEBIAN_BUILD_VERSIONS_REPO" ]; then
-  echo ${ERROR_MESSAGE}
-  exit 1
-fi
-unset ERROR_MESSAGE
diff --git a/cmake/getDebianBuildVersion b/cmake/getDebianBuildVersion
deleted file mode 100755
index 7ea0f94..0000000
--- a/cmake/getDebianBuildVersion
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-#######################################################################################################################
-# getDebianBuildVersion
-#
-# Determine the Debian build version from the git repository specified in the DebianPackaging.config file.
-#
-# Usage:
-# ./getDebianBuildVersion <PACKAGE_NAME> <PACKAGE_VERSION> <DEBIAN_CODENAME> [<DEPENDENCY1_NAME_WITH_VERSION>]  \
-#                         [<DEPENDENCY2_NAME_WITH_VERSION>] [...]
-#
-# Example:
-# ./getDebianBuildVersion DeviceAccess-DoocsBackend 0.1 xenial DeviceAccess-0.14 DOOCS-18.10.5 DoocsServerTestHelper-0.1
-#
-# IMPORTANT NOTES:
-# If you change the order of dependencies passed to this script, the build version will be unnecessarily increased!
-# Running this script requires access to the git repository and WILL eventually MAKE COMMITS to it!
-#
-#######################################################################################################################
-
-#######################################################################################################################
-#
-# IMPORTANT NOTE:
-#
-# DO NOT MODIFY THIS FILE inside a project. Instead update the project-template repository and pull the change from
-# there. Make sure to keep the file generic, since it will be used by other projects, too.
-#
-# If you have modified this file inside a project despite this warning, make sure to cherry-pick all your changes
-# into the project-template repository immediately.
-#
-#######################################################################################################################
-
-# obtain configuration
-source "$(dirname $0)/DebianPackaging.config"
-
-# check minimum number of command line parameters
-if [ $# -lt 3 ]; then
-  echo "Usage:"
-  echo "./getDebianBuildVersion <PACKAGE_NAME> <PACKAGE_VERSION> <DEBIAN_CODENAME> [<DEPENDENCY1_NAME_WITH_VERSION>] [<DEPENDENCY2_NAME_WITH_VERSION>] [...]"
-  echo ""
-  echo "Example:"
-  echo "./getDebianBuildVersion DeviceAccess-DoocsBackend 0.1 xenial DeviceAccess-0.14 DOOCS-18.10.5 DoocsServerTestHelper-0.1"
-  echo ""
-  echo "IMPORTANT NOTES:"
-  echo "If you change the order of dependencies passed to this script, the build version will be unnecessarily increased!"
-  echo "Running this script requires access to the git repository and WILL eventually MAKE COMMITS to it!"
-  exit 1
-fi
-
-# parse mandatory command line parameters
-PACKAGE_NAME="$1"
-PACKAGE_VERSION="$2"
-DEBIAN_CODENAME="$3"
-shift ; shift ; shift
-
-# build sub-directory name for dependency versions (will start and end with a /)
-DEPENDENCY_STRING="/"
-while (( "$#" )); do
-  DEPENDENCY_STRING="${DEPENDENCY_STRING}${1}/"
-  shift
-done
-
-# output information extracted from command line:
-echo "PACKAGE_NAME=${PACKAGE_NAME}" >&2
-echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >&2
-echo "DEBIAN_CODENAME=${DEBIAN_CODENAME}" >&2
-echo "DEPENDENCY_STRING=${DEPENDENCY_STRING}" >&2
-
-# create temporary directory for checking out the DebianBuildVersions repository and modifying it
-WDIR=`mktemp --tmpdir -d DebianBuildVersions.XXXXXXXX`
-echo Temporary directory to work in: $WDIR >&2
-echo Git repository containing the build versions: $DEBIAN_BUILD_VERSIONS_REPO >&2
-
-# check out the DebianBuildVersions repository
-cd $WDIR || exit 1
-git clone "$DEBIAN_BUILD_VERSIONS_REPO" . >&2 || exit 1
-
-# go to the directory for the specific package version and debian codename (create it if not yet existing)
-mkdir -p "${PACKAGE_NAME}/${PACKAGE_VERSION}/${DEBIAN_CODENAME}"
-cd "${PACKAGE_NAME}/${PACKAGE_VERSION}/${DEBIAN_CODENAME}"
-
-# if LATEST_BUILD file is not there, this is the first build of this package version on this debian codename
-if [ ! -f "LATEST_BUILD" ]; then
-  echo "The package ${PACKAGE_NAME} in version ${PACKAGE_VERSION} has never been build on ${DEBIAN_CODENAME} before." >&2
-  # start with build number 1 and create the necessary control structure
-  BUILD_NUMBER=1
-  echo ".${DEPENDENCY_STRING}BUILD_NUMBER" > LATEST_BUILD
-  mkdir -p ".${DEPENDENCY_STRING}"
-  echo ${BUILD_NUMBER} > ".${DEPENDENCY_STRING}BUILD_NUMBER"
-else
-  # if the file BUILD_NUMBER exists in the dependency sub-directory, this is a patch build and we re-use the build number
-  if [ -f ".${DEPENDENCY_STRING}BUILD_NUMBER" ]; then
-    echo "The package ${PACKAGE_NAME} in version ${PACKAGE_VERSION} has been build on ${DEBIAN_CODENAME} before against the SAME dependency versions." >&2
-    BUILD_NUMBER=`cat ".${DEPENDENCY_STRING}BUILD_NUMBER"`
-  else
-    # no build number has been assigned yet, so we have to increase the build number from the latest build
-    echo "The package ${PACKAGE_NAME} in version ${PACKAGE_VERSION} has been build on ${DEBIAN_CODENAME} before against DIFFERENT dependency versions." >&2
-    BUILD_NUMBER=$(( `cat $(cat LATEST_BUILD)` + 1 ))
-    echo ".${DEPENDENCY_STRING}BUILD_NUMBER" > LATEST_BUILD
-    mkdir -p ".${DEPENDENCY_STRING}"
-    echo ${BUILD_NUMBER} > ".${DEPENDENCY_STRING}BUILD_NUMBER"
-  fi
-fi
-
-# commit the changes to the repository
-git add -A . >&2 || exit 1
-git commit -m "Update by getDebianBuildVersion: ${PACKAGE_NAME}/${PACKAGE_VERSION}/${DEBIAN_CODENAME}${DEPENDENCY_STRING} -> ${BUILD_NUMBER}" >&2
-git push >&2 || exit 1
-
-# output the build number to stderr in human readable form and to stdout in plain form for further script processing
-echo Build number: ${BUILD_NUMBER} >&2
-echo ${BUILD_NUMBER}
-
-rm -rf $WDIR
diff --git a/cmake/make_debian_package.sh.in b/cmake/make_debian_package.sh.in
index 2342ffd..b3ea221 100755
--- a/cmake/make_debian_package.sh.in
+++ b/cmake/make_debian_package.sh.in
@@ -15,121 +15,56 @@
 #######################################################################################################################
 
 # This cmake.in file requires the following variables to be set:
+# PACKAGE_BUILDVERSION_ENVIRONMENT_VARIABLE_NAME Environment variable which contains the build version.
+#   Must not contain any hyphens.
 # PACKAGE_BASE_NAME This is the debian package name, not the project name (e.g. libraries must start with lib,
-#   all lower case, no underscore)
+#   all lover case, no underscore)
+# PACKAGE_FULL_LIBRARY_VERSION The full version, incl. build version and patch version
+# PACKAGE_GIT_URI The URI where to check out the source code
 # PACKAGE_TAG_VERSION The tag for which the package is build
-# PACKAGE_MAJORMINOR_VERSION The library version without the patch level (i.e. just "MAJOR.MINOR")
-# PACKAGE_PATCH_VERSION The patch level
 # PACKAGE_MESSAGE The message for the debian package log
-# PACKAGE_DEPENDENCY_VERSIONS A space-separated list of dependency names and versions, each connected by a dash, e.g.:
-#                             "DeviceAccess-0.15 ControlSystemAdapter-0.1"
-# Also the following standard cmake variables are used (should be always correctly set):
-# CMAKE_SOURCE_DIR
-# PROJECT_NAME
 
-# drop out of the script if anything goes wrong (e.g. non-existing git tag)
+#Check that the @PACKAGE_BUILDVERSION_ENVIRONMENT_VARIABLE_NAME@ variable is set, otherwise reject creating a package
+if [ -z "$@PACKAGE_BUILDVERSION_ENVIRONMENT_VARIABLE_NAME@" ]; then
+    echo Environment variable '@PACKAGE_BUILDVERSION_ENVIRONMENT_VARIABLE_NAME@' not set or empty. You need it to make a debian package!
+    exit 1
+fi
+
+#drop out of the script if anything goes wrong (e.g. non-existen git tag)
 set -e
 
-# Create a working directory in order not to merge with the rest in the build directory
+#Create a working directory in order not to merge with the rest in the build directory
 rm -rf debian_package
 mkdir debian_package
 cd debian_package
 
-# Parse command line argument
-if [ -z "$1" ] ; then
-  # build on host system
-  USE_PBUILDER=0
-  CODENAME=`lsb_release -c | sed "{s/Codename:\s*//}"`
-elif [ "$1" == "--setup" ] ; then
-  if [ -z "$2" ] ; then
-    echo "Missing parameter to --setup"
-    exit 1
-  fi
-  sudo pbuilder --create --distribution $2
-  exit $?
-else
-  USE_PBUILDER=1
-  CODENAME=$1
-fi
-
-# Print warning if not using pbuilder
-if [ "$USE_PBUILDER" == "0" ]; then
-  echo "WARNING: You are building on your host system for ${CODENAME}."
-  echo ""
-  echo "It is strongly recommended to build in a chroot environment using pbuilder. This can be simply enabled by calling the make_debian_package.sh script with the codename as command line argument, i.e.:"
-  echo " ./make_debian_package.sh ${CODENAME}"
-  echo ""
-  echo "This will require root permissons (script will ask for password via sudo) and a previously setup pbuilder environment, but you can build for any target on every host system with pbuilder installed."
-  echo ""
-  echo "To setup the pbuilder environment, use the following command:"
-  echo " ./make_debian_package.sh --setup ${CODENAME}"
-  echo ""
-  echo -n "Continuing in 5 seconds. Press Ctrl+C to abort."
-  sleep 1 ; echo -n "."
-  sleep 1 ; echo -n "."
-  sleep 1 ; echo -n "."
-  sleep 1 ; echo -n "."
-  sleep 1 ; echo "."
-fi
-
-
-# Obtain build version and the derived so-file and debian versions
-BUILD_NUMBER=`"@CMAKE_SOURCE_DIR@/cmake/getDebianBuildVersion" @PROJECT_NAME@ @PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@ ${CODENAME} @PACKAGE_DEPENDENCY_VERSIONS@` || exit 1
-export PROJECT_BUILDVERSION="${CODENAME}${BUILD_NUMBER}"
-
-DEBVERSION="@PACKAGE_MAJOR_VERSION@-@PACKAGE_MINOR_VERSION@-${PROJECT_BUILDVERSION}"
-SOVERSION="@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@${PROJECT_BUILDVERSION}"
-
-# replace #DEBVERSION# inside the template files in the debian_from_template directory, also replace DEBVERSION in the
-# file names
-for file_source in ../debian_from_template/* ; do
-  file_target=`echo ${file_source} | sed -e "s|DEBVERSION|${DEBVERSION}|g" -e "s|.template$||" `
-  
-  echo "$file_source -> $file_target"
-
-  # perform operation, if source and target file names are not identical
-  if [ "$file_source" != "$file_target" ] ; then
-    sed "$file_source" -e "s|#DEBVERSION#|${DEBVERSION}|g" -e "s|#SOVERSION#|${SOVERSION}|g" > "$file_target"
-  fi
-
-done
-
-# Check out the correct tag from the master git repository.
-# The local directory name has to follow the debian convention
-#  lowecasepackagenname_package.ver.sion
-# Note, we first clone and then checkout the tag because the old git version on
-# Ubuntu12.4 does not support to do it in one go.
-BUILD_DIR_NAME="@PACKAGE_BASE_NAME@_@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@-${PROJECT_BUILDVERSION}"
+#Check out the correct tag from the master git repository.
+#The local directory name has to follow the debian convention
+# lowecasepackagenname_package.ver.sion
+#Note, we first clone and then checkout the tag because the old git version on
+#Ubuntu12.4 does not support to do it in one go.
+BUILD_DIR_NAME=@PACKAGE_BASE_NAME@_@PACKAGE_FULL_LIBRARY_VERSION@
 git clone @CMAKE_SOURCE_DIR@ ${BUILD_DIR_NAME}
 ( cd  ${BUILD_DIR_NAME} &&\
   git checkout @PACKAGE_TAG_VERSION@ &&\
   rm -rf .git )
-# Debian convention: file has to end on .orig.tar.gz
+#Debian convention: file has to end on .orig.tar.gz
 tar -czf  ${BUILD_DIR_NAME}.orig.tar.gz  ${BUILD_DIR_NAME}
 
-# Copy the prepared debian packaging config files to the source code
-# directroy
+#Copy the prepared debian packaging config files to the source code
+#directroy
 cp -r ../debian_from_template  ${BUILD_DIR_NAME}/debian
 cd ${BUILD_DIR_NAME}
 
-# Before building the package we will update the changelog. This is easier from a shell script
-# because debchange does the right format and the current date, user name and email automatically for us.
-# Use the NAME and EMAIL environment variables to get correct values if needed (usually the email is
-#  user@host instead of first.last@institute, for instance killenb@mskpcx18571.desy.de instead of martin.killenberg@desy.de).
-debchange --create --package @PACKAGE_BASE_NAME@ -v @PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@-${PROJECT_BUILDVERSION}-@PACKAGE_PATCH_VERSION@ --distribution ${CODENAME} @PACKAGE_MESSAGE@
+#The package versions for doocs / Ubuntu contain the codename of the distribution. Get it from the system.
+CODENAME=`lsb_release -c | sed "{s/Codename:\s*//}"`
 
-# Now everything is prepared and we can actually build the package.
-# If you have a gpg signature you can remove the -us and -uc flags and sign the package.
-if [ "$USE_PBUILDER" == "0" ]; then
-  dpkg-buildpackage -rfakeroot -us -uc
-else
-  MIRRORLIST="deb [trusted=yes] http://doocspkgs.desy.de/pub/doocs xenial main|deb [trusted=yes] http://doocs.desy.de/pub/doocs xenial main|deb [trusted=yes] file:///var/cache/pbuilder/result ./"
-  sudo bash -c "cd /var/cache/pbuilder/result ; apt-ftparchive packages . > Packages"                   || exit 1
-  sudo pbuilder --update --distribution ${CODENAME} --override-config --components "main universe" \
-                --othermirror "$MIRRORLIST" --buildresult "/var/cache/pbuilder/result"             \
-                --bindmounts "/var/cache/pbuilder/result"                                               || exit 1
-  pdebuild -- --distribution ${CODENAME} --buildresult "/var/cache/pbuilder/result"                \
-              --bindmounts "/var/cache/pbuilder/result"                                                 || exit 1
-  echo ""
-  echo "You can find the resulting debian packages in this directory: /var/cache/pbuilder/result"
-fi
+#Before building the package we will update the changelog. This is easier from a shell script
+#because debchange does the right format and the current date, user name and email automatically for us.
+#Use the NAME and EMAIL environment variables to get correct values if needed (usually the email is
+# user@host instead of first.last@institute, for instance killenb@mskpcx18571.desy.de instead of martin.killenberg@desy.de).
+debchange --create --package @PACKAGE_BASE_NAME@ -v @PACKAGE_FULL_LIBRARY_VERSION@-${@PACKAGE_BUILDVERSION_ENVIRONMENT_VARIABLE_NAME@} --distribution ${CODENAME} @PACKAGE_MESSAGE@
+
+#Now everything is prepared and we can actually build the package.
+#If you have a gpg signature you can remove the -us and -uc flags and sign the package.
+dpkg-buildpackage -rfakeroot -us -uc
-- 
GitLab