Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add conditional builds for rpm build customization and related build script refactoring #541

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 0 additions & 1 deletion .automation/milestone-config.sh.in

This file was deleted.

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ target

# build-time files
###########################
rpmbuild/
/ovirt-engine*.tar.gz
.metadata
*.class
*.swp
Expand Down Expand Up @@ -46,7 +48,6 @@ __pycache__

# Files generated from templates
###########################
.automation/milestone-config.sh
ovirt-engine.spec
build/helptag.py
build/helptag_checker.py
Expand Down
2 changes: 2 additions & 0 deletions .gitignore.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ target

# build-time files
###########################
rpmbuild/
/ovirt-engine*.tar.gz
.metadata
*.class
*.swp
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ BUILD_TARGET=install
# Once add new template file, if required chmod, add it in generated-files target.
GENERATED = \
.gitignore \
.automation/milestone-config.sh \
ovirt-engine.spec \
build/helptag.py \
build/helptag_checker.py \
Expand Down Expand Up @@ -372,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