-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Add conditional builds for rpm build customization
Instead of sed swapping in a 0 or 1 for a `%define` variable in the `spec.in` file, or running rpmbuild with a `--define`, use conditional builds. See [1] for how they work. With a conditional build, source rpms retain the ability to build with different options depending on how `rpmbuild` is called. This allows a minimal (en_US, Firefox, Safari) or full (all locales, all browsers) build from srpm to be selected at build time using `--with` or `--without` build options. Since at least copr builds chroots directly from a srpm, conditional builds can be used to change build options. With this change, a "full build" can be forced simply by configuring the target chroot setting "without" to include "ovirt_build_full". Notes: - A `ovirt_build_full` is the is the default - For GitHub CI, a minimal build with unit tests is used - For copr builds, use `build-srpm.sh -c` to keep CI and copr srpm builds in the same place - Refactored `build-srpm.sh` and `build-rpm.sh`: - each script has only the envvars setup that the work needs to run - use `getopts` to parse options so they don't positionally clash - add a snapshot build release suffix if the Makefile var `MILESTONE` is not empty [1] - https://rpm-software-management.github.io/rpm/manual/conditionalbuilds.html
- Loading branch information
Showing
9 changed files
with
212 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
#!/bin/bash -xe | ||
|
||
# Directory, where build artifacts will be stored, should be passed as '-a' parameter | ||
ARTIFACTS_DIR=exported-artifacts | ||
|
||
# Process options | ||
while getopts ":a:" options; do | ||
case $options in | ||
a) ARTIFACTS_DIR=$OPTARG;; | ||
\?) | ||
echo "Error: Invalid option" | ||
exit;; | ||
esac | ||
done | ||
|
||
# Build source packages | ||
source $(dirname "$(readlink -f "$0")")/build-srpm.sh | ||
|
||
# Install build dependencies | ||
dnf builddep -y rpmbuild/SRPMS/*src.rpm | ||
# GWT build memory needs to be limited | ||
EXTRA_BUILD_FLAGS="--no-transfer-progress" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} -Dgwt.compiler.localWorkers=1" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} -Dgwt.jvmArgs='-Xms1G -Xmx3G'" | ||
|
||
# Perform reasonable quick build with unit tests execution | ||
BUILD_UT=1 | ||
BUILD_ALL_USER_AGENTS=0 | ||
BUILD_LOCALES=0 | ||
# Maven memory needs to be limited | ||
export MAVEN_OPTS="-Xms1G -Xmx2G" | ||
|
||
# Set the location of the JDK that will be used for compilation | ||
export JAVA_HOME="${JAVA_HOME:=/usr/lib/jvm/java-11}" | ||
|
||
# Install build dependencies | ||
if [[ $(id -u) -ne 0 ]]; then | ||
sudo dnf builddep -y ${top_dir}/SRPMS/*src.rpm | ||
else | ||
dnf builddep -y ${top_dir}/SRPMS/*src.rpm | ||
fi | ||
|
||
# Build binary package | ||
# Build binary package with the minimal build. GH RPM builds | ||
# will be used only for OST so Firefox and Chrome are enough. | ||
rpmbuild \ | ||
-D "_topmdir rpmbuild" \ | ||
-D "_rpmdir rpmbuild" \ | ||
${RELEASE:+-D "release_suffix ${RELEASE}"} \ | ||
-D "ovirt_build_ut ${BUILD_UT}" \ | ||
-D "ovirt_build_all_user_agents ${BUILD_ALL_USER_AGENTS}" \ | ||
-D "ovirt_build_locales ${BUILD_LOCALES}" \ | ||
-D "_topdir ${top_dir}" \ | ||
-D "release_suffix ${SNAPSHOT_SUFFIX}" \ | ||
-D "ovirt_build_extra_flags ${EXTRA_BUILD_FLAGS}" \ | ||
--rebuild rpmbuild/SRPMS/*src.rpm | ||
--with ovirt_build_minimal \ | ||
--with ovirt_build_ut \ | ||
--rebuild ${top_dir}/SRPMS/*src.rpm | ||
|
||
# Move RPMs to exported artifacts | ||
[[ -d $ARTIFACTS_DIR ]] || mkdir -p $ARTIFACTS_DIR | ||
find rpmbuild -iname \*rpm | xargs mv -t $ARTIFACTS_DIR | ||
[[ -d ${ARTIFACTS_DIR} ]] || mkdir -p ${ARTIFACTS_DIR} | ||
find ${top_dir} -iname \*rpm -print0 | xargs -0 mv -t ${ARTIFACTS_DIR} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
#!/bin/bash -xe | ||
|
||
# git hash of current commit should be passed as the 1st paraameter | ||
if [ "${GITHUB_SHA}" == "" ]; then | ||
GIT_HASH=$(git rev-list HEAD | wc -l) | ||
else | ||
GIT_HASH=$(git rev-parse --short $GITHUB_SHA) | ||
fi | ||
|
||
# Directory, where build artifacts will be stored, should be passed as the 1st parameter | ||
ARTIFACTS_DIR=${1:-exported-artifacts} | ||
|
||
# Prepare the version string (with support for SNAPSHOT versioning) | ||
VERSION=$(mvn help:evaluate -q -DforceStdout -Dexpression=project.version) | ||
VERSION=${VERSION/-SNAPSHOT/-0.${GIT_HASH}.$(date +%04Y%02m%02d%02H%02M)} | ||
IFS='-' read -ra VERSION <<< "$VERSION" | ||
RELEASE=${VERSION[1]-1} | ||
MILESTONE=master | ||
|
||
# GH RPM builds will be used only for OST so Firefox and Chrome are enough | ||
# GWT build memory needs to be limited | ||
EXTRA_BUILD_FLAGS="" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} --no-transfer-progress" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} -Dgwt.userAgent=gecko1_8,safari" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} -Dgwt.compiler.localWorkers=1" | ||
EXTRA_BUILD_FLAGS="${EXTRA_BUILD_FLAGS} -Dgwt.jvmArgs='-Xms1G -Xmx3G'" | ||
# Building srpm for copr? | ||
copr_build=0 | ||
|
||
# Process options | ||
while getopts ":c" options; do | ||
case $options in | ||
c) copr_build=1;; | ||
\?) | ||
echo "Error: Invalid option" | ||
exit;; | ||
esac | ||
done | ||
|
||
# Ensure the build validation passes | ||
make validations | ||
|
||
export MAVEN_OPTS="-Xms1G -Xmx2G" | ||
# git hash of the HEAD commit (GH action may be the PR merge commit) | ||
GIT_HASH=$(git rev-parse --short HEAD) | ||
|
||
# Set the location of the JDK that will be used for compilation: | ||
export JAVA_HOME="${JAVA_HOME:=/usr/lib/jvm/java-11}" | ||
# Prepare the SNAPSHOT release suffix if a MILESTONE is available | ||
SNAPSHOT_SUFFIX= | ||
if [[ "$(make -f version.mak print-MILESTONE)" != "MILESTONE=" ]]; then | ||
SNAPSHOT_SUFFIX=".git${GIT_HASH}" | ||
fi | ||
export SNAPSHOT_SUFFIX | ||
|
||
[ -d ${ARTIFACTS_DIR} ] || mkdir -p ${ARTIFACTS_DIR} | ||
[ -d rpmbuild/SOURCES ] || mkdir -p rpmbuild/SOURCES | ||
# For a copr snapshot build, burn in the release_suffix as -D options are not preserved when rebuilding from srpm | ||
if [[ ${copr_build} -eq 1 && "${SNAPSHOT_SUFFIX}" != "" ]]; then | ||
sed "s:%{?release_suffix}:${SNAPSHOT_SUFFIX}:" -i ovirt-engine.spec.in | ||
fi | ||
|
||
make validations | ||
# Create RPM build directories | ||
export top_dir="${PWD}/rpmbuild" | ||
test -d "${top_dir}" && rm -rf "${top_dir}" || : | ||
mkdir -p "${top_dir}/SOURCES" | ||
|
||
# Get the tarball | ||
make dist | ||
mv *.tar.gz rpmbuild/SOURCES | ||
mv *.tar.gz ${top_dir}/SOURCES | ||
|
||
# create the src.rpm | ||
# Create the src.rpm | ||
rpmbuild \ | ||
-D "_topdir rpmbuild" \ | ||
-ts rpmbuild/SOURCES/*.gz | ||
-D "_topdir ${top_dir}" \ | ||
${SNAPSHOT_SUFFIX:+-D "release_suffix ${SNAPSHOT_SUFFIX}"} \ | ||
-ts ${top_dir}/SOURCES/*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.