Build RPMs totally based on external build_vars 32/26932/2
authorDaniel Farrell <dfarrell@redhat.com>
Mon, 14 Sep 2015 20:42:13 +0000 (16:42 -0400)
committerDaniel Farrell <dfarrell@redhat.com>
Mon, 14 Sep 2015 21:36:11 +0000 (17:36 -0400)
Connect recent refactoring in opendaylight.spec and build.sh to fully
define RPM builds based on external build variable files.

This is necessary for supporting multiple RPM releases at the same time,
like Lithium, Lithium SR1 and Helium SR4.

To add additional RPM builds, we now simply define additional var files.

Change-Id: I7b32041b2e99a51b6823b47a002b9834e022422c
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
rpm/build.sh
rpm/build_vars/default_vars.sh [new file with mode: 0644]
rpm/build_vars/vars_3.0.0-2.sh
rpm/opendaylight.spec

index 2f41725f2fc846f1bec441b12b3606d028550223..7ad4d63c24c1cd755ac014b70cab110fa999a9dc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env sh
-# Build the ODL SRPM and noarch RPM described in opendaylight.spec
-# This is designed to be run in the included Vagrant environment.
+# Reads build info from build_vars files to build ODL RPMs and SRPMs
+# This is designed to be run in the included Vagrant environment
 
 # Echo commands as they are run
 set -x
@@ -8,8 +8,6 @@ set -x
 build()
 {
     # Common names used in this script
-    odl_version="0.$version_major.$version_minor"
-    rpm_version="$version_major.$version_minor.$version_patch"
     odl_srpm="opendaylight-$rpm_version-$rpm_release.$rpm_disttag.src.rpm"
     odl_rpm="opendaylight-$rpm_version-$rpm_release.$rpm_disttag.noarch.rpm"
     odl_tarball="distribution-karaf-$odl_version-$codename.tar.gz"
@@ -63,10 +61,19 @@ build()
     cp $specfile_path $rpmbuild_spec_dir
 
     # Build ODL SRPM and noarch RPM
-    # Override disttag from .el7.centos to .el7 per best-practices/expected norms
-    #   See: https://bugs.centos.org/view.php?id=9098
+    # Override specfile macros with values that define the build
     cd $rpmbuild_spec_dir
-    rpmbuild -ba --define "dist .$rpm_disttag" opendaylight.spec
+    rpmbuild -ba --define "dist .$rpm_disttag" \
+                 --define "codename $codename" \
+                 --define "version_major $version_major" \
+                 --define "version_minor $version_minor" \
+                 --define "version_patch $version_patch" \
+                 --define "rpm_release $rpm_release" \
+                 --define "odl_version $odl_version" \
+                 --define "rpm_version $rpm_version" \
+                 --define "java_version $java_version" \
+                 --define "sysd_commit $sysd_commit" \
+                 opendaylight.spec
 
     # Confirm SRPM found in expected location
     if [ -f  $srpm_out_path ]; then
@@ -96,7 +103,7 @@ build()
 # Accept path to build vars file as a param, build all if absent
 if [[ $# -eq 0 ]]; then
   # If no build vars file passed, do all builds described in build_vars dir
-  for vars_file in /vagrant/build_vars/*; do
+  for vars_file in /vagrant/build_vars/vars_*; do
     source $vars_file
     build
   done
diff --git a/rpm/build_vars/default_vars.sh b/rpm/build_vars/default_vars.sh
new file mode 100644 (file)
index 0000000..a632496
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env sh
+# Variables to define an OpenDaylight RPM build
+# `build.sh` reads these and passes them to opendaylight.spec
+# To define a new ODL RPM build, copy one of these and adjust as-needed
+
+# Version fields for the ODL release
+version_patch=0
+
+# Override disttag from .el7.centos to .el7 per best-practices/expected norms
+#   See: https://bugs.centos.org/view.php?id=9098
+rpm_disttag="el7"
+
+# Java versions supported by this ODL release
+java_version=">= 1:1.7.0"
+
+# Version of ODL systemd unitfile to download and package in ODL RPM
+# Update this commit if systemd unit file is updated
+sysd_commit="4a872270893f0daeebcbbcc0ff0014978e3c5f68"
+
+# Directory used for caching build artifacts
+# Being able to customize this is useful for some offline builds
+cache_dir="/vagrant"
+
+# ODL version translation
+# Note that the RPM is shifting ODL's version to the left by one value
+#   to be consistent with the major.minor.patch scheme used universally
+#   by RPMs. ODL's version is currently prefixed with a static, useless
+#   leading 0, which is widely ignored in practice. For now the version
+#   translation happens here. This will likely be fixed as ODL moves to
+#   a continuous release model.
+odl_version="0.$version_major.$version_minor"
+rpm_version="$version_major.$version_minor.$version_patch"
index 94ed17e725f58b246b1254f9ab526f32bf33b7b0..354b5079f48916aab86748e92dddb4640a363c42 100755 (executable)
@@ -1,9 +1,24 @@
-codename="Lithium"
+#!/usr/bin/env sh
+# Variables to define an OpenDaylight RPM build
+# `build.sh` reads these and passes them to `opendaylight.spec`
+# To define a new ODL RPM build, copy one of these and adjust as-needed
+
+# Directory used for caching build artifacts
+# Customizing this is useful for some offline builds
+cache_dir="/vagrant"
+
+# Version fields for the ODL release
 version_major=3
 version_minor=0
-version_patch=0
+
+# Include variable defaults that are common to many builds
+# NB: To use vars in default_vars.sh, define them before this source cmd
+#     Example: version_[major,minor,patch] is used for [odl,rpm]_version
+# NB: To override vars things defined in default_vars, define them after
+source $cache_dir/build_vars/default_vars.sh
+
+# Elemental codename for the ODL release, including SR if applicable
+codename="Lithium"
+
+# RPM version for the given ODL major.minor.patch
 rpm_release=2
-rpm_disttag="el7"
-java_version=">= 1:1.7.0"
-sysd_commit="4a87227"
-cache_dir="/vagrant"
index d31e9500b2327936f8fb22ac674c9888ee2f75d2..eff85b87c212f4d27dcfb02bbceda39bdeb5b8ca 100644 (file)
@@ -1,45 +1,21 @@
 # ODL is a noarch package, so this isn't necessary. It's also very slow.
 %define __jar_repack 0
 
-# Override the %define macros below build multiple versions of ODL's RPM
-# Default values are for the latest supported ODL release
-
-# Version of ODL systemd unitfile to download and package in ODL RPM
-# Update this commit if systemd unit file is updated
-%define commit 4a872270893f0daeebcbbcc0ff0014978e3c5f68
-%define shortcommit %(c=%{commit}; echo ${c:0:7})
-
-# ODL version variables
-# Note that the RPM is shifting ODL's version to the left by one value
-#   to be consistent with the major.minor.patch scheme used universally
-#   by RPMs. ODL's version is currently prefixed with a static, useless
-#   leading 0, which is widely ignored in practice. For now the version
-#   translation happens here. This will likely be fixed as ODL moves to
-#   a continuous release model.
-%define odl_codename Lithium
-%define odl_version_major 3
-%define odl_version_minor 0
-%define odl_version_patch 0
-%define odl_version 0.%{odl_version_major}.%{odl_version_minor}
-%define odl_rpm_version %{odl_version_major}.%{odl_version_minor}.%{odl_version_patch}
-%define odl_rpm_release 2
-%define java_version >= 1:1.7.0
-
 Name:       opendaylight
-Version:    %{odl_rpm_version}
+Version:    %{rpm_version}
 # The Fedora/CentOS packaging guidelines *require* the use of a disttag. ODL's
 #   RPM build doesn't do anything Fedora/CentOS specific, so the disttag is
 #   unnecessary and unused in our case, but both the docs and the pros (apevec)
 #   agree that we should include it.
 # See: https://fedoraproject.org/wiki/Packaging:DistTag
-Release:    %{odl_rpm_release}%{dist}
+Release:    %{rpm_release}%{dist}
 BuildArch:  noarch
 Summary:    OpenDaylight SDN Controller
 Group:      Applications/Communications
 License:    EPL-1.0
 URL:        http://www.opendaylight.org
-Source0:    https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/%{odl_version}-%{odl_codename}/distribution-karaf-%{odl_version}-%{odl_codename}.tar.gz
-Source1:    https://github.com/dfarrell07/opendaylight-systemd/archive/%{shortcommit}/opendaylight-systemd-%{shortcommit}.tar.gz
+Source0:    https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/%{odl_version}-%{codename}/distribution-karaf-%{odl_version}-%{codename}.tar.gz
+Source1:    https://github.com/dfarrell07/opendaylight-systemd/archive/%{sysd_commit}/opendaylight-systemd-%{sysd_commit}.tar.gz
 Buildroot:  /tmp
 # Required for ODL at run time
 Requires:   java %{java_version}
@@ -56,23 +32,23 @@ getent passwd odl > /dev/null || useradd odl -M -d $RPM_BUILD_ROOT/opt/%name
 getent group odl > /dev/null || groupadd odl
 
 %description
-OpenDaylight %{odl_codename}
+OpenDaylight %{codename}
 
 %prep
 # Extract Source0 (ODL archive)
-%autosetup -n distribution-karaf-%{odl_version}-%{odl_codename}
+%autosetup -n distribution-karaf-%{odl_version}-%{codename}
 # Extract Source1 (systemd config)
-%autosetup -T -D -b 1 -n opendaylight-systemd-%{commit}
+%autosetup -T -D -b 1 -n opendaylight-systemd-%{sysd_commit}
 
 %install
 # Create directory in build root for ODL
 mkdir -p $RPM_BUILD_ROOT/opt/%name
 # Copy ODL from archive to its dir in build root
-cp -r ../distribution-karaf-%{odl_version}-%{odl_codename}/* $RPM_BUILD_ROOT/opt/%name
+cp -r ../distribution-karaf-%{odl_version}-%{codename}/* $RPM_BUILD_ROOT/opt/%name
 # Create directory in build root for systemd .service file
 mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
 # Copy ODL's systemd .service file to correct dir in build root
-cp ../../BUILD/opendaylight-systemd-%{commit}/opendaylight.service $RPM_BUILD_ROOT/%{_unitdir}
+cp ../../BUILD/opendaylight-systemd-%{sysd_commit}/opendaylight.service $RPM_BUILD_ROOT/%{_unitdir}
 
 %postun
 # When the RPM is removed, the subdirs containing new files wouldn't normally