You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/07/03 16:05:03 UTC

[trafficcontrol] branch master updated: Modify the grove/build/build_rpm.sh script to incorporate the last 9 digit commit hash on the grove/ directory as the release when building the grove rpm.

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new e8fa8ea  Modify the grove/build/build_rpm.sh script to incorporate the last 9 digit commit hash on the grove/ directory as the release when building the grove rpm.
e8fa8ea is described below

commit e8fa8ea5a0b61c594d229da9e8027712f5c89abb
Author: John Rushford <jr...@apache.org>
AuthorDate: Thu Jun 28 17:49:23 2018 +0000

    Modify the grove/build/build_rpm.sh script to incorporate the
    last 9 digit commit hash on the grove/ directory as the release
    when building the grove rpm.
---
 grove/build/build_rpm.sh | 107 +++++++++++++++++++++++++++++++++--------------
 grove/build/grove.spec   |   2 +-
 2 files changed, 77 insertions(+), 32 deletions(-)

diff --git a/grove/build/build_rpm.sh b/grove/build/build_rpm.sh
index 9363f94..fd17cc9 100755
--- a/grove/build/build_rpm.sh
+++ b/grove/build/build_rpm.sh
@@ -12,44 +12,89 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-ROOTDIR=$(git rev-parse --show-toplevel)
-[ ! -z "$ROOTDIR" ] || { echo "Cannot find repository root." >&2 ; exit 1; }
+#----------------------------------------
+function importFunctions() {
+  TC_DIR=$(git rev-parse --show-toplevel)
+  [ ! -z "$TC_DIR" ] || { echo "Cannot find repository root." >&2 ; exit 1; }
+  export TC_DIR
+	functions_sh="$TC_DIR/build/functions.sh"
+	if [[ ! -r $functions_sh ]]; then
+		echo "Error: Can't find $functions_sh"
+		exit 1
+	fi
+	. "$functions_sh"
+}
 
-cd "$ROOTDIR/grove"
+#----------------------------------------
+function checkGroveEnvironment() {
+	echo "Verifying the build configuration environment."
+	local script=$(readlink -f "$0")
+	local scriptdir=$(dirname "$script")
 
-BUILDDIR="$ROOTDIR/grove/rpmbuild"
-VERSION=`cat ./VERSION`.`git rev-list --all --count`
+	export GROVE_DIR=$(dirname "$scriptdir")
+  export GROVE_VERSION=`cat ${GROVE_DIR}/VERSION`
+	export PACKAGE="grove"
+	export BUILD_NUMBER=${BUILD_NUMBER:-$(getBuildNumber)}
+	export RPMBUILD="${GROVE_DIR}/rpmbuild"
+	export DIST="${TC_DIR}/dist"
+	export RPM="${PACKAGE}-${GROVE_VERSION}-${BUILD_NUMBER}.x86_64.rpm"
 
-# prep build environment
-[ -e $BUILDDIR ] && rm -rf $BUILDDIR
-[ ! -e $BUILDDIR ] || { echo "Failed to clean up rpm build directory '$BUILDDIR': $?" >&2; exit 1; }
-mkdir -p $BUILDDIR/{BUILD,RPMS,SOURCES} || { echo "Failed to create build directory '$BUILDDIR': $?" >&2; exit 1; }
+	echo "=================================================="
+  echo "TC_DIR: $TC_DIR"
+  echo "PACKAGE: $PACKAGE"
+  echo "GROVE_DIR: $GROVE_DIR"
+	echo "GROVE_VERSION: $GROVE_VERSION"
+	echo "BUILD_NUMBER: $BUILD_NUMBER"
+  echo "DIST: $DIST"
+	echo "RPM: $RPM"
+  echo "RPMBUILD: $RPMBUILD"
+	echo "--------------------------------------------------"
+}
 
-# build
-go get -v -d . || { echo "Failed to go get dependencies: $?" >&2; exit 1; }
-go build -v -ldflags "-X main.Version=$VERSION" || { echo "Failed to build grove: $?" >&2; exit 1; }
+# ---------------------------------------
+function initBuildArea() {
+  cd "$GROVE_DIR"
 
-# tar
-tar -cvzf $BUILDDIR/SOURCES/grove-${VERSION}.tgz grove conf/grove.cfg build/grove.init build/grove.logrotate || { echo "Failed to create archive for rpmbuild: $?" >&2; exit 1; }
+  # prep build environment
+  [ -e $RPMBUILD ] && rm -rf $RPMBUILD
+  [ ! -e $RPMBUILD ] || { echo "Failed to clean up rpm build directory '$RPMBUILD': $?" >&2; exit 1; }
+  mkdir -p $RPMBUILD/{BUILD,RPMS,SOURCES} || { echo "Failed to create build directory '$RPMBUILD': $?" >&2; exit 1; }
+}
 
-# Work around bug in rpmbuild. Fixed in rpmbuild 4.13.
-# See: https://github.com/rpm-software-management/rpm/commit/916d528b0bfcb33747e81a57021e01586aa82139
-# Takes ownership of the spec file.
-spec=build/grove.spec
-spec_owner=$(stat -c%u $spec)
-spec_group=$(stat -c%g $spec)
-if ! id $spec_owner >/dev/null 2>&1; then
-	chown $(id -u):$(id -g) build/grove.spec
+# ---------------------------------------
+function buildRpmGrove() {
+  # build
+  go get -v -d . || { echo "Failed to go get dependencies: $?" >&2; exit 1; }
+  go build -v -ldflags "-X main.Version=$GROVE_VERSION" || { echo "Failed to build grove: $?" >&2; exit 1; }
 
-	function give_spec_back {
+  # tar
+  tar -cvzf $RPMBUILD/SOURCES/grove-${GROVE_VERSION}.tgz grove conf/grove.cfg build/grove.init build/grove.logrotate || { echo "Failed to create archive for rpmbuild: $?" >&2; exit 1; }
+
+  # Work around bug in rpmbuild. Fixed in rpmbuild 4.13.
+  # See: https://github.com/rpm-software-management/rpm/commit/916d528b0bfcb33747e81a57021e01586aa82139
+  # Takes ownership of the spec file.
+  spec=build/grove.spec
+  spec_owner=$(stat -c%u $spec)
+  spec_group=$(stat -c%g $spec)
+  if ! id $spec_owner >/dev/null 2>&1; then
+	  chown $(id -u):$(id -g) build/grove.spec
+
+	  function give_spec_back {
 		chown ${spec_owner}:${spec_group} build/grove.spec
-	}
-	trap give_spec_back EXIT
-fi
+	  }
+	  trap give_spec_back EXIT
+  fi
+
+  # build RPM
+  rpmbuild --define "_topdir $RPMBUILD" --define "version ${GROVE_VERSION}" --define "build_number ${BUILD_NUMBER}" -ba build/grove.spec || { echo "rpmbuild failed: $?" >&2; exit 1; }
+
+  # copy build RPM to .
+  [ -e $DIST ] || mkdir -p $DIST
+  cp $RPMBUILD/RPMS/x86_64/${RPM} $DIST
+}
 
-# build RPM
-rpmbuild --define "_topdir $BUILDDIR" --define "version ${VERSION}" -ba build/grove.spec || { echo "rpmbuild failed: $?" >&2; exit 1; }
+importFunctions
+checkGroveEnvironment
+initBuildArea
+buildRpmGrove
 
-# copy build RPM to .
-[ -e ../dist ] || mkdir -p ../dist
-cp $BUILDDIR/RPMS/x86_64/grove-${VERSION}-1.x86_64.rpm ../dist
diff --git a/grove/build/grove.spec b/grove/build/grove.spec
index 6ed87f0..2f0f345 100644
--- a/grove/build/grove.spec
+++ b/grove/build/grove.spec
@@ -13,7 +13,7 @@
 Summary: Grove HTTP Caching Proxy
 Name: grove
 Version: %{version}
-Release: 1
+Release: %{build_number}
 License: Apache License, Version 2.0
 Group: Base System/System Tools
 Prefix: /usr/sbin/%{name}