Skip to content

Commit

Permalink
build: Add conditional builds for rpm build customization
Browse files Browse the repository at this point in the history
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
sjd78 committed Jul 20, 2022
1 parent 3c8214e commit 3c02510
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 142 deletions.
55 changes: 39 additions & 16 deletions .automation/build-rpm.sh
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}
70 changes: 36 additions & 34 deletions .automation/build-srpm.sh
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
11 changes: 2 additions & 9 deletions .copr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,5 @@ git_cfg_safe:
git config --global --add safe.directory "$(shell pwd)"

srpm: installdeps git_cfg_safe
$(eval SUFFIX=.git$(shell git rev-parse --short HEAD))
# changing the spec file as passing -D won't preserve the suffix when rebuilding in mock
sed "s:%{?release_suffix}:${SUFFIX}:" -i ovirt-engine.spec.in
mkdir -p tmp.repos/SOURCES
make dist
rpmbuild \
-D "_topdir tmp.repos" \
-ts ./*.tar.gz
cp tmp.repos/SRPMS/*.src.rpm $(outdir)
./.automation/build-srpm.sh -c
cp rpmbuild/SRPMS/*.src.rpm $(outdir)
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: Perform build
run: |
.automation/build-rpm.sh $ARTIFACTS_DIR
.automation/build-rpm.sh -a $ARTIFACTS_DIR
- name: Create DNF repository
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ validations: generated-files
fi; \
fi
if [ "$(BUILD_VALIDATION)" != 0 ]; then \
echo "Performing build validation." &&\
echo "Performing build validation." &&\
build/shell-check.sh && \
build/python-check.sh && \
build/ansible-check.sh && \
Expand Down
56 changes: 39 additions & 17 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -580,34 +580,56 @@ And install a drop-in configuration file to override engine developement setup:
# yum-builddep @srpm@
# rpmbuild -tb @tarball@

The following spec file variables are available for package customization:
The following spec file options / conditional builds (set with `--with` or `--without`)
are available for package customization:

ovirt_build_quick:: Quick build, best for syntax checks. Default is `0`.
ovirt_build_quick::
Quick build, best for syntax checks. Default is `without`.

ovirt_build_minimal:: Build minimal Firefox only package. Default is
`0`.
ovirt_build_minimal::
Build minimal user agent (Gecko/Firefox and WebKit/Chrome/Safari) and locale (English)
package. For snapshot builds, the default is `with`, otherwise default is `without`.

ovirt_build_user_agent:: When using quick or minimal build, build only
for this user agent. Default is `gecko1_8` (Firefox). To build for
Chrome use `safari`.
ovirt_build_full::
Build all GWT components with all user agents and locales. Selected by default when
`ovirt_build_quick` or `ovirt_build_minimal` is not explicitly selected.

ovirt_build_gwt:: Build GWT components. Default is `1`.
ovirt_build_gwt::
Build GWT components. Default is `with`, but is `without` when the `ovirt_build_quick`
option is enalbed.

ovirt_build_all_user_agents:: Build GWT components for all supported
browsers. Default is `1`.
ovirt_build_all_user_agents::
Build GWT components for all supported browsers. Default is `with`, but is `without`
when the `ovirt_build_minimal` option is enabled.

ovirt_build_locales:: Build GWT components for all supported locales.
Default is `1`.
ovirt_build_all_locales::
Build GWT components for all supported locales. Default is `with`, but is `without`
when the `ovirt_build_minimal` option is enabled.

ovirt_build_ut::
Run unit tests with the build. Default is `with` when `ovirt_build_full` is selected,
otherwise defaults to `without`.

The following spec file variables (set with `--define`) are available for package customization:

ovirt_build_user_agent::
When using quick or minimal build, build only for this user agent. Default is
`gecko1_8,safari` (Firefox and Chrome/Safari).

ovirt_build_locales::
When using quick or minimal build, build only for this set of locales. Default is
`en_US`. To build for additional locales, use a comma separated list. For example,
setting to `en_US,ja_JP` will build for English and Japanese.

Examples:
==== Examples

Build minimal rpm package for Firefox::
Build minimal rpm package for Firefox and Chrome/Safari::

$ rpmbuild -D"ovirt_build_minimal 1" -tb @tarball@
$ rpmbuild --with ovirt_build_minimal -tb @tarball@

Build minimal rpm package for Chrome or Safari::
Build minimal rpm package for Chrome/Safari only::

$ rpmbuild -D"ovirt_build_minimal 1" -D"ovirt_build_user_agent safari" -tb @tarball@
$ rpmbuild --with ovirt_build_minimal --define "ovirt_build_user_agent safari" -tb @tarball@

=== Ansible Lint

Expand Down
20 changes: 1 addition & 19 deletions bump_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,7 @@ export CHANGELOG
# Add changelog to the spec file
sed -i "/^%changelog/a ${CHANGELOG}" ovirt-engine.spec.in

# Adjust copr build config for releasing
patch -p0 --ignore-whitespace .copr/Makefile <<'__EOF__'
diff --git a/.copr/Makefile b/.copr/Makefile
index 51e3299e3e5..b2d4a195740 100644
--- a/.copr/Makefile
+++ b/.copr/Makefile
@@ -9,9 +9,9 @@ git_cfg_safe:
git config --global --add safe.directory "$(shell pwd)"
srpm: installdeps git_cfg_safe
- $(eval SUFFIX=.git$(shell git rev-parse --short HEAD))
+ # $(eval SUFFIX=.git$(shell git rev-parse --short HEAD))
# changing the spec file as passing -D won't preserve the suffix when rebuilding in mock
- sed "s:%{?release_suffix}:${SUFFIX}:" -i ovirt-engine.spec.in
+ # sed "s:%{?release_suffix}:${SUFFIX}:" -i ovirt-engine.spec.in
mkdir -p tmp.repos/SOURCES
make dist
rpmbuild \
__EOF__
# copr/build-srpm.sh will skip the snapshot suffix if `version.mak` does not select a MILESTONE

# commit
git add -u
Expand Down
Loading

0 comments on commit 3c02510

Please sign in to comment.