summaryrefslogtreecommitdiffstats
path: root/debian/_buildscripts/local/scripts/build_module.sh
diff options
context:
space:
mode:
Diffstat (limited to 'debian/_buildscripts/local/scripts/build_module.sh')
-rwxr-xr-xdebian/_buildscripts/local/scripts/build_module.sh468
1 files changed, 468 insertions, 0 deletions
diff --git a/debian/_buildscripts/local/scripts/build_module.sh b/debian/_buildscripts/local/scripts/build_module.sh
new file mode 100755
index 000000000..3a421e572
--- /dev/null
+++ b/debian/_buildscripts/local/scripts/build_module.sh
@@ -0,0 +1,468 @@
+#!/bin/bash
+#
+# Build a single TDE module
+#
+
+# Load common code and initialization
+. ./_build_common.sh
+init_common
+
+# Timer settings
+_BUILDMOD_TIMER_NUM=0
+_BUILDMOD_TIME="--/--:--:--:---"
+exec_time_start $_BUILDMOD_TIMER_NUM
+
+
+#----------------------------
+# Parameters:
+# $1 - error code
+function do_exit()
+{
+ cd "$SCRIPT_DIR"
+ if [ $1 -eq 0 ]; then
+ echo -e "${CGreen}#### Processing module ${CLightGreen}\"$MOD_NAME\"${CGreen} succeeded ####${CNone}"
+ if [ "$bool_LOG_RESULT" = "y" ]; then
+ echo "[ OK ] [$_BUILDMOD_TIME] \"$MOD_NAME\"" >>"$LOG_RESULT_FILENAME"
+ fi
+ else
+ echo -e "${CRed}#### Processing module ${CLightRed}\"$MOD_NAME\"${CRed} failed ($1) ####${CNone}"
+ if [ "$bool_LOG_RESULT" = "y" ]; then
+ echo "[FAILED] [$_BUILDMOD_TIME] \"$MOD_NAME\"" >>"$LOG_RESULT_FILENAME"
+ fi
+ fi
+ exit $1
+}
+
+
+#----------------------------
+# Parameters:
+# $1 - folder name
+function recreate_folder()
+{
+ if [ -d "$1" ]; then
+ rm -R "$1"
+ fi
+ mkdir -p "$1"
+}
+
+
+#----------------------------
+# Check command line arguments
+#----------------------------
+MOD_NAME="" # the module to be built
+bool_BUILD_FROM_GIT="n"
+bool_EXTRADEP_MOD="n"
+bool_SHOW_BUILD_LOGS="n"
+bool_BUILD_LOCALLY="n"
+bool_LOG_RESULT="n"
+bool_SHELL_HOOK="n"
+bool_PREPARE_ONLY="n"
+bool_DEBUG_MODE="n"
+bool_INTERNAL_PBUILDER="n"
+for arg in $@; do
+ if [ "$arg" = "-g" ]; then # select code to build from Git repo (-g) or from local build copy
+ bool_BUILD_FROM_GIT="y"
+ elif [ "$arg" = "-l" ]; then # build module Locally instead of in a clean chroot environment
+ bool_BUILD_LOCALLY="y"
+ elif [ "$arg" = "-sl" ]; then # output the building logs to terminal (ShowLog)
+ bool_SHOW_BUILD_LOGS="y"
+ elif [ "$arg" = "-lr" ]; then # Log build Result to file
+ bool_LOG_RESULT="y"
+ elif [ "$arg" = "-sh" ]; then # install Shell Hook for failing builds (only valid if NOT building locally)
+ bool_SHELL_HOOK="y"
+ elif [ "$arg" = "-po" ]; then # Prepare build folder Only but do not build
+ bool_PREPARE_ONLY="y"
+ elif [ "$arg" = "-d" ]; then # build with Debug symbols (used in hook scripts)
+ bool_DEBUG_MODE="y"
+ elif [ "$arg" = "-ip" ]; then # build using Internal Pbuilder
+ bool_INTERNAL_PBUILDER="y"
+ elif [ "$MOD_NAME" = "" ]; then # module to be built
+ MOD_NAME="$arg"
+ fi
+done
+
+if [ "$MOD_NAME" = "" ]; then
+ echo "Please specify the module to build"
+ do_exit 3
+fi
+
+# Check if module is an extra dependency (i.e. from the nightly build dependency PPA)
+if [[ $MOD_NAME =~ ^edeps/ ]]; then
+ bool_EXTRADEP_MOD="y"
+fi
+
+# Shell hook is only valid if NOT building locally
+# Internal pbuilder option has no meaning if we are building locally
+if [ "bool_BUILD_LOCALLY" = "y" ]; then
+ bool_SHELL_HOOK="n"
+ bool_INTERNAL_PBUILDER="n"
+fi
+
+
+# Log start
+echo -e "${CLightCyan}#### Processing module \"$MOD_NAME\" ####${CNone}"
+
+
+#----------------------------
+# Base directories
+#----------------------------
+GIT_DIR="$TDE_DIR/$CFG_GIT_DIR"
+BUILD_DIR="$TDE_DIR/$CFG_BUILD_DIR"
+GIT_TDE_MAIN="$TDE_DIR/$CFG_GIT_TDE_MAIN"
+GIT_TDE_PACKAGING="$TDE_DIR/$CFG_GIT_TDE_PACKAGING"
+GIT_EXTRA_DEPENDENCIES="$TDE_DIR/$CFG_GIT_EXTRA_DEPENDENCIES"
+HOOK_DIR="$TDE_DIR/$CFG_HOOK_DIR"
+
+# This folders must exists
+BASE_DIRS=("GIT_DIR" "BUILD_DIR" "SCRIPT_DIR" "GIT_TDE_MAIN" "GIT_TDE_PACKAGING" "GIT_EXTRA_DEPENDENCIES" "HOOK_DIR" "PBUILDER_REPO")
+
+for var_name in ${BASE_DIRS[@]}; do
+ if [ ! -d "${!var_name}" ]; then
+ echo -e "$var_name directory missing. Value is \"${!var_name}\". Check your config or create it."
+ do_exit 4
+ fi
+done
+
+
+#----------------------------
+# Build output directories
+#----------------------------
+TDE_BUILD_DIR="$TDE_DIR/$CFG_TDE_BUILD_DIR"
+TDE_DEBS_DIR="$TDE_DIR/$CFG_TDE_DEBS_DIR"
+
+BUILD_DIRS=("TDE_BUILD_DIR" "TDE_DEBS_DIR")
+
+for var_name in ${BUILD_DIRS[@]}; do
+ if [ ! -d "${!var_name}" ]; then
+ mkdir "${!var_name}"
+ fi
+done
+
+
+#----------------------------
+# Check module name validity
+#----------------------------
+if [ "$bool_EXTRADEP_MOD" != "y" ]; then
+ # Standard module
+ MOD_GIT_PATH="$GIT_TDE_MAIN/$MOD_NAME"
+ MOD_GIT_PKGING_PATH="$GIT_TDE_PACKAGING/$MOD_NAME/debian"
+else
+ # Extra dependency module
+ MOD_GIT_PATH="$GIT_DIR/$MOD_NAME"
+fi
+MOD_BUILD_PATH="$TDE_BUILD_DIR/$MOD_NAME"
+MOD_BUILD_PKGING_PATH="$MOD_BUILD_PATH/debian"
+
+if [ "$bool_BUILD_FROM_GIT" = "y" ]; then
+ echo -e "${CYellow}> Building from GIT repo${CNone}"
+ # source files
+ if [ ! -d "$MOD_GIT_PATH" ]; then
+ echo "Module \"$MOD_NAME\" not found in GIT"
+ do_exit 5
+ fi
+ bool_COPY_MOD_SRC="y"
+
+ # packaging scripts
+ if [ "$bool_EXTRADEP_MOD" != "y" -a ! -d "$MOD_GIT_PKGING_PATH" ]; then
+ echo "Packaging for \"$MOD_NAME\" not found in GIT"
+ do_exit 6
+ fi
+ bool_COPY_PKGING_FILES="y"
+ #
+else
+ echo -e "${CYellow}> Building from BUILD folder${CNone}"
+ # source files
+ bool_COPY_MOD_SRC="n"
+ if [ ! -d "$MOD_BUILD_PATH" ]; then
+ if [ ! -d "$MOD_GIT_PATH" ]; then
+ echo "Module \"$MOD_NAME\" not found neither in BUILD nor in GIT"
+ do_exit 7
+ fi
+ bool_COPY_MOD_SRC="y"
+ fi
+
+ # packaging scripts
+ bool_COPY_PKGING_FILES="n"
+ if [ "$bool_EXTRADEP_MOD" != "y" -a ! -d "$MOD_BUILD_PKGING_PATH" ]; then
+ if [ ! -d "$MOD_GIT_PKGING_PATH" ]; then
+ echo "Packaging for \"$MOD_NAME\" not found neither in BUILD nor in GIT"
+ do_exit 8
+ fi
+ bool_COPY_PKGING_FILES="y"
+ fi
+fi
+
+
+#----------------------------
+# Prepare source files
+#----------------------------
+# remove output from previous build
+if [ -d "$MOD_BUILD_PATH" ]; then
+ cd "$MOD_BUILD_PATH/.."
+ rm *.deb *.dsc *.changes *.tar.bz2 *.tar.gz *.tar.xz *.log *.buildinfo &>/dev/null
+fi
+
+# copy main repo source files, if needed
+if [ "$bool_COPY_MOD_SRC" = "y" ]; then
+ bool_COPY_PKGING_FILES="y"
+ recreate_folder "$MOD_BUILD_PATH"
+ if [ "$bool_EXTRADEP_MOD" != "y" ]; then
+ # Normal module
+ cp -R "$MOD_GIT_PATH" "$MOD_BUILD_PATH/.."
+ # Add SCM information for crash test report
+ [ -f "$MOD_BUILD_PATH/.tdescmmodule" ] && rm "$MOD_BUILD_PATH/.tdescmmodule"
+ [ -f "$MOD_BUILD_PATH/.tdescmrevision" ] && rm "$MOD_BUILD_PATH/.tdescmrevision"
+ # --> Module name
+ echo "$MOD_NAME" >"$MOD_BUILD_PATH/.tdescmmodule"
+ # --> SCM info
+ cd "$MOD_GIT_PATH"
+ MOD_BRANCH=`git branch --contains HEAD | grep -v "no branch" | head -n1 | cut -c 3-`
+ COMMIT_HASH=`git rev-parse HEAD`
+ echo "$MOD_BRANCH-$COMMIT_HASH" >"$MOD_BUILD_PATH/.tdescmrevision"
+ else
+ # Extra dependency module
+ if [ `find "$MOD_GIT_PATH" -name '*.dsc' | wc -l` == 1 ]; then
+ if [ -d "$MOD_BUILD_PATH" ]; then
+ rm -R "$MOD_BUILD_PATH"
+ fi
+ if [ "$bool_SHOW_BUILD_LOGS" = "y" ]; then
+ dpkg-source --no-copy --no-check -x `find "$MOD_GIT_PATH" -name '*.dsc'` "$MOD_BUILD_PATH"
+ else
+ dpkg-source --no-copy --no-check -x `find "$MOD_GIT_PATH" -name '*.dsc'` "$MOD_BUILD_PATH" &>/dev/null
+ fi
+ else
+ echo "There must be one and only one .dsc file in \"$MOD_GIT_PATH\""
+ do_exit 9
+ fi
+ fi
+fi
+
+# copying packaging scripts, if needed
+if [ "$bool_EXTRADEP_MOD" != "y" -a "$bool_COPY_PKGING_FILES" = "y" ]; then
+ if [ -d "$MOD_BUILD_PKGING_PATH" ]; then
+ rm -R $MOD_BUILD_PKGING_PATH
+ fi
+ cp -R "$MOD_GIT_PKGING_PATH" "$MOD_BUILD_PKGING_PATH"
+
+ # TODO metapackage support
+
+ if [ "$USE_LOCAL_BUILD_NUMBER" != "y" ]; then
+ # Default package name (Slavek's repo style)
+ # Calculate package version
+ cd $MOD_GIT_PATH
+ branch=`git branch --contains HEAD | egrep -v "no branch|detached" | head -n1 | cut -c 3-`
+ target_tag=`git tag | grep -F "$TDE_RELEASE" | head -n1`
+ tag=`git tag | \
+ sed "s|^\([^0-9]\)|\1.|" | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr | sed "s|^\([^0-9]\)\.|\1|" | \
+ while read t; do \
+ git branch --contains $t | cut -c 3- | grep -x "$branch" >/dev/null && \
+ echo "$t..HEAD" && break; done`
+ count=`git log $tag --pretty=oneline | wc -l`
+ package=$(basename $PWD)-trinity-$TDE_RELEASE
+ if [[ "$count" -gt 0 ]] || [[ -z "$target_tag" ]]; then
+ package=$package~pre$count+$(git rev-parse HEAD | cut -c 1-8)
+ fi
+ REL=4:$TDE_RELEASE${package#*$TDE_RELEASE}
+ REL=${REL%+*}
+ REL=${REL/4:14.0.0/4:14.0.0-s}
+ REL=${REL/4:14.0.0-s~pre/4:14.0.0-s~}
+ REL=${REL/.0~pre/.0~s}
+ # Get package name and packaging release
+ PKG_NAME=$(head -n1 $MOD_BUILD_PKGING_PATH/changelog)
+ PKG_NAME=${PKG_NAME%% *}
+ PKG_TAG=$(cd "$GIT_TDE_PACKAGING/$MOD_NAME" &&
+ git tag | \
+ sed "s|^\([^0-9]\)|\1.|" | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr | sed "s|^\([^0-9]\)\.|\1|" | \
+ while read t; do \
+ git branch --contains $t | cut -c 3- | grep -x "$branch" >/dev/null && \
+ echo "$t..HEAD" && break; done)
+ PKG_REL=$(cd "$GIT_TDE_PACKAGING/$MOD_NAME" &&
+ git log $PKG_TAG --pretty=oneline . | wc -l)
+ if [ -n "$REL_SUFFIX" ]; then
+ PKG_REL="${PKG_REL}${REL_SUFFIX}"
+ fi
+ # TODO add relative patch count
+ ADD_REL=0
+
+ DATE=$(date -R)
+ GITUSER="$(git config --get user.name) <$(git config --get user.email)>"
+ echo "$PKG_NAME ($REL-0$DISTRO$D_VERSION.$ADD_REL+$PKG_REL) $D_VERSION; urgency=low" > "$MOD_BUILD_PKGING_PATH/changelog"
+ echo -e "\n * Automated git build\n\n -- $GITUSER $DATE\n" >> "$MOD_BUILD_PKGING_PATH/changelog"
+ cat "$GIT_TDE_PACKAGING/$MOD_NAME/debian/changelog" >> "$MOD_BUILD_PKGING_PATH/changelog"
+ else
+ # Local build version
+ if [ "$BUILD_DATE" = "" ]; then
+ BUILD_DATE=`date +%Y%m%d+%H%M`
+ fi
+ BUILD_VERSION="4:$TDE_RELEASE-${BUILD_NUMBER}+$BUILD_DATE" # Module build version number (quilt format)
+ dch -b -v "$BUILD_VERSION" -D "$D_VERSION" -c "$MOD_BUILD_PKGING_PATH/changelog" "Autogenerated by building script" &>/dev/null
+ fi
+fi
+
+# prepare destination directory for building
+MOD_DEB_PATH="$TDE_DEBS_DIR/$MOD_NAME"
+MOD_DEBSRC_PATH="$MOD_DEB_PATH/src"
+recreate_folder "$MOD_DEB_PATH"
+recreate_folder "$MOD_DEBSRC_PATH"
+
+
+#----------------------------
+# Apply pre-build hooks if present
+#----------------------------
+if [ -x "$HOOK_DIR/$MOD_NAME/pre_build.sh" ]; then
+ echo -e "${CYellow}> Applying pre-build hook${CNone}"
+ . "$HOOK_DIR/$MOD_NAME/pre_build.sh"
+ if [ $? -eq 0 ]; then
+ echo -e "> ${CBrown}Pre-build hook applied successfully${CNone}"
+ else
+ echo -e "> ${CLightBlue}Pre-build hook failed${CNone}"
+ fi
+fi
+
+
+#----------------------------
+# Switch to 3.0(quilt) format
+#----------------------------
+# create orig tarball
+cd "$MOD_BUILD_PATH"
+MOD_BASENAME=`head -n 1 "$MOD_BUILD_PKGING_PATH/changelog" | sed -r "s/^([^ ]+).*/\1/"`
+MOD_MAJOR_VER=`head -n 1 "$MOD_BUILD_PKGING_PATH/changelog" | sed -r "s/^[^ ]+ \(([^:]+:)?.*/\1/"`
+MOD_UP_VER=`head -n 1 "$MOD_BUILD_PKGING_PATH/changelog" | sed -r "s/^[^ ]+ \(([^:]+:)?([^-]+).*/\2/"`
+MOD_DEB_VER=`head -n 1 "$MOD_BUILD_PKGING_PATH/changelog" | sed -r "s/^[^ ]+ \([^-]+-([^\)]+).*/\1/"`
+
+tar cJf "../${MOD_BASENAME}_${MOD_UP_VER}.orig.tar.xz" --exclude="debian" --exclude=".git*" .
+
+# switch to quilt format
+if [ -f "$MOD_BUILD_PKGING_PATH/source/format" ]; then
+ grep -q "(native)" "$MOD_BUILD_PKGING_PATH/source/format" && \
+ sed -i "s/(native)/(quilt)/" "$MOD_BUILD_PKGING_PATH/source/format"
+else
+ [ -d "$MOD_BUILD_PKGING_PATH/source" ] || mkdir -p "$MOD_BUILD_PKGING_PATH/source"
+ echo "3.0 (quilt)" >"$MOD_BUILD_PKGING_PATH/source/format"
+fi
+
+# remove quilt references from rules file
+grep -q "^include.*/usr/share/cdbs/1/rules/patchsys-quilt\.mk" "$MOD_BUILD_PKGING_PATH/rules" && \
+sed -i "s/^\(include.*\/usr\/share\/cdbs\/1\/rules\/patchsys-quilt\.mk\)/#\1/" "$MOD_BUILD_PKGING_PATH/rules"
+
+if [ "$bool_PREPARE_ONLY" = "y" ]; then
+ echo -e "${CBrown}Source code prepared for building${CNone}"
+ do_exit 0
+fi
+
+
+#----------------------------
+# Enable debug mode if required
+#----------------------------
+if [ "$bool_DEBUG_MODE" = "y" ]; then
+ echo -e "${CBrown}Enable debug mode${CNone}"
+ sed -i "s/RelWithDebInfo/Debug/" "$MOD_BUILD_PKGING_PATH/rules"
+fi
+
+
+#----------------------------
+# Build
+#----------------------------
+BUILDING_LOG_FILE="$MOD_DEBSRC_PATH/__build__.log"
+cd "$MOD_BUILD_PATH"
+
+if [ "$bool_BUILD_LOCALLY" = "y" ]; then
+ ## Build module locally
+ echo -e "${CYellow}> Building locally${CNone}"
+ if [ "$bool_SHOW_BUILD_LOGS" = "y" ]; then
+ dpkg-buildpackage -us -uc | tee "$BUILDING_LOG_FILE"
+ else
+ dpkg-buildpackage -us -uc &>"$BUILDING_LOG_FILE"
+ fi
+ build_retval=$?
+ #
+else
+ ## Build module in a clean chroot environment using pbuilder
+ # Install/remove shell hook
+ if [ "$bool_SHELL_HOOK" = "y" ]; then
+ if [ -x "$PBUILDER_SHELL_HOOK_TEMPLATE" ]; then
+ cp "$PBUILDER_SHELL_HOOK_TEMPLATE" "$PBUILDER_SHELL_HOOK" &>/dev/null
+ else
+ echo "pbuilder shell hook template file not found! ($PBUILDER_SHELL_HOOK_TEMPLATE)"
+ fi
+ else
+ if [ -x "$PBUILDER_SHELL_HOOK" ]; then
+ rm "$PBUILDER_SHELL_HOOK" &>/dev/null
+ fi
+ fi
+ # Build
+ mount --bind "$TDE_DEBS_DIR" "$PBUILDER_REPO"
+ if [ $? -ne 0 ]; then
+ echo "Unable to mount folder \"$TDE_DEBS_DIR\" to \"$PBUILDER_REPO\". Can not proceed :("
+ do_exit 11
+ fi
+ #
+ echo -e "${CYellow}> Building using pbuilder${CNone}"
+ if [ "$bool_SHOW_BUILD_LOGS" = "y" ]; then
+ if [ "$bool_INTERNAL_PBUILDER" = "y" ]; then
+ pdebuild --use-pdebuild-internal --architecture $ARCHITECTURE --buildresult "$MOD_DEB_PATH" --pbuilderroot "sudo DIST=$D_VERSION ARCH=$ARCHITECTURE" --logfile "$BUILDING_LOG_FILE"
+ else
+ pdebuild --architecture $ARCHITECTURE --buildresult "$MOD_DEB_PATH" --pbuilderroot "sudo DIST=$D_VERSION ARCH=$ARCHITECTURE" --logfile "$BUILDING_LOG_FILE"
+ fi
+ else
+ if [ "$bool_INTERNAL_PBUILDER" = "y" ]; then
+ pdebuild --use-pdebuild-internal --architecture $ARCHITECTURE --buildresult "$MOD_DEB_PATH" --pbuilderroot "sudo DIST=$D_VERSION ARCH=$ARCHITECTURE" --logfile "$BUILDING_LOG_FILE" &>"$BUILDING_LOG_FILE"
+ else
+ pdebuild --architecture $ARCHITECTURE --buildresult "$MOD_DEB_PATH" --pbuilderroot "sudo DIST=$D_VERSION ARCH=$ARCHITECTURE" --logfile "$BUILDING_LOG_FILE" &>"$BUILDING_LOG_FILE"
+ fi
+ fi
+ build_retval=$?
+ umount "$PBUILDER_REPO"
+fi
+
+if [ $build_retval -eq 0 ]; then
+ echo -e "${CLightGreen}> Building completed SUCCESSFULLY${CNone}"
+else
+ echo -e "${CLightRed}> Building completed WITH ERRORS${CNone}"
+fi
+
+
+#----------------------------
+# Apply post-build hooks if present
+#----------------------------
+if [ -x "$HOOK_DIR/$MOD_NAME/post_build.sh" ]; then
+ echo -e "${CYellow}> Applying post-build hook${CNone}"
+ . "$HOOK_DIR/$MOD_NAME/post_build.sh"
+ if [ $? -eq 0 ]; then
+ echo -e "${CBrown}Post-build hook applied successfully${CNone}"
+ else
+ echo -e "${CLightBlue}Post-build hook failed${CNone}"
+ fi
+fi
+
+#----------------------------
+# Move compiled module files to destination folders
+#----------------------------
+if [ "$bool_BUILD_LOCALLY" = "y" ]; then
+ cd "$MOD_BUILD_PATH/.."
+ if [ "$bool_BUILD_LOCALLY" == "y" ]; then
+ mv *.deb "$MOD_DEB_PATH" &>/dev/null
+ fi
+ mv *.dsc *.changes *.tar.xz *.tar.bz2 *.tar.gz *.buildinfo "$MOD_DEBSRC_PATH" &>/dev/null
+else
+ cd "$MOD_DEB_PATH"
+ mv *.dsc *.changes *.tar.xz *.tar.bz2 *.tar.gz *.buildinfo "$MOD_DEBSRC_PATH" &>/dev/null
+fi
+cd "$MOD_BUILD_PATH/.."
+mv *.orig.tar.xz "$MOD_DEBSRC_PATH" &>/dev/null
+
+
+#----------------------------
+# Removing leftover files
+#----------------------------
+cd "$MOD_BUILD_PATH/.."
+rm *.deb *.dsc *.changes *.tar.xz *.tar.bz2 *.tar.gz *.log *.buildinfo &>/dev/null
+cd "$MOD_DEB_PATH"
+rm *.dsc *.changes *.tar.xz *.tar.bz2 *.tar.gz *.log *.buildinfo &>/dev/null
+
+
+#----------------------------
+# Building completed
+#----------------------------
+exec_time_stop $_BUILDMOD_TIMER_NUM "_BUILDMOD_TIME"
+do_exit $build_retval