Skip to content

Commit

Permalink
Merge pull request #5333 from daniviga/better-rpm
Browse files Browse the repository at this point in the history
Improve buildrpms.sh for nightly builds
  • Loading branch information
m-kuhn authored Oct 16, 2017
2 parents f579f1a + fa1d299 commit afb2a6a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 28 deletions.
2 changes: 1 addition & 1 deletion rpm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
result
*.tar.gz
*.tar.bz2
local.cfg
version.cfg
qgis.spec
45 changes: 45 additions & 0 deletions rpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## QGIS RPM generator

### Build RPM using mock

```bash
$ ./buildrpms.sh
```

### Generate a valid spec file from template

```bash
$ ./buildrpms.sh -c
```

### Build SRPM using mock

```bash
$ ./buildrpms.sh -s
```

### Rebuild last generated RPM using mock

```bash
$ ./buildrpms.sh -b
```

### Build an unstable release

```bash
$ ./buildrpms.sh [flags] -u
```

This generates an RPM with release `.git<short commit ID>`


### MOCK old chroot

It is possible to execute `mock` using the 'old chroot' behavior (which does not uses `systemd-nspawn`) setting
the environment variable `_MOCK_OLD_CHROOT` before running `buildrpms.sh`:

```bash
export _MOCK_OLD_CHROOT=1
```

This may be useful when running `mock` inside environments that do not play well with `systemd-nspawn` (LXC/LXD, Docker...).
85 changes: 58 additions & 27 deletions rpm/buildrpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,36 @@ function print_help
Creates RPM packages.
Usage:
-c only compile spec file
-s only create srpm, nothing will be compiled
-u build unstable, release will include the short commit id
-b build last srpm, the package release number will not be increased
-h show help
'
}

if [ $_MOCK_OLD_CHROOT ]
then
mock_args="--old-chroot"
fi

compile_spec_only=0
build_only=0
srpm_only=0
build_unstable=0

while getopts "shb" opt; do
while getopts "csuhb" opt; do
case ${opt} in
c)
compile_spec_only=1
;;
s)
srpm_only=1
;;
[\?|h])
u)
build_unstable=1
;;
\?|h)
print_help
exit 0
;;
Expand All @@ -62,16 +77,23 @@ then
source local.cfg
fi

# Get next release version number and increment after
if [ ! -f version.cfg ]
then
echo "RELVER=1" > version.cfg
fi
source version.cfg
if [ "$build_only" -ne "1" ]
if [ $build_unstable -ne 1 ]
then
let RELVER+=1
echo "RELVER=$RELVER" > version.cfg
# Get next release version number and increment after
if [ ! -f version.cfg ]
then
echo "relver=1" > version.cfg
fi
source version.cfg
if [ "$build_only" -ne "1" ]
then
let relver+=1
echo "relver=$relver" > version.cfg
fi
timestamp=1
else
relver="git$(git rev-parse --short HEAD)"
timestamp=$(date +'%s')
fi

# Clean logfiles
Expand All @@ -91,28 +113,33 @@ patch=$(grep -e 'SET(CPACK_PACKAGE_VERSION_PATCH' ../CMakeLists.txt |

version=$(echo $major.$minor.$patch)

timestamp=$(date +'%s')

print_info "Building version $version-$RELVER"

print_info "Building version $version-$relver"
if [ "$build_only" -ne "1" ]
then
# Current git branch name
branch=$(git branch --no-color 2> /dev/null |
sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
print_info "Creating spec file from template"
# Create spec file
cat qgis.spec.template \
| sed -e s/%{_version}/$version/g \
| sed -e s/%{_relver}/$relver/g \
| sed -e s/%{_timestamp}/$timestamp/g \
| tee qgis.spec 1>/dev/null

if [ "$compile_spec_only" -eq "1" ]
then
exit 0
fi

print_info "Creating source tarball"
# Create source tarball
git -C .. archive --format=tar --prefix=qgis-$version/ $BRANCH | bzip2 > sources/qgis-$version.tar.bz2
git -C .. archive --format=tar --prefix=qgis-$version/ HEAD | bzip2 > sources/qgis-$version.tar.bz2

print_info "Creating source package"
# Create spec file
cat qgis.spec.template | sed -e s/%{_version}/$version/g \
| sed -e s/%{_relver}/$RELVER/g \
| sed -e s/%{_timestamp}/$timestamp/g \
| tee qgis.spec 1>/dev/null
# Build source package
mock --buildsrpm --spec qgis.spec --sources ./sources --define "_relver $RELVER" --define "_version $version" --resultdir=$OUTDIR
mock --buildsrpm --spec qgis.spec --sources ./sources \
--define "_relver $relver" \
--define "_version $version" \
--define "_timestamp $timestamp" \
--resultdir=$OUTDIR $mock_args
if [ $? -ne 0 ]
then
print_error "Creating source package failed"
Expand Down Expand Up @@ -140,11 +167,15 @@ do :
rm $OUTDIR/$arch/build.log
fi
mkdir $OUTDIR/$arch
mock -r $arch --rebuild $OUTDIR/$srpm --define "_relver $RELVER" --define "_version $version" --resultdir=$OUTDIR/$arch
mock -r $arch --rebuild $OUTDIR/$srpm \
--define "_relver $relver" \
--define "_version $version" \
--define "_timestamp $timestamp" \
--resultdir=$OUTDIR/$arch $mock_args
if [ $? -eq 0 ]
then
# Add to package list
packages="$packages $(ls $OUTDIR/$arch/*-$version-$RELVER.*.rpm)"
packages="$packages $(ls $OUTDIR/$arch/*-$version-$relver.*.rpm)"
else
print_error "Package creation for $arch failed. Abort"
exit 1
Expand Down
8 changes: 8 additions & 0 deletions rpm/qgis.spec.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# vi:syntax=spec
# TODO: Run test suite (see debian/rules)

# Template variables
# - _version
# - _relver
# - _timestamp (optional)

Name: qgis
Version: %{_version}
Release: %{_relver}%{?dist}
Expand All @@ -10,6 +15,9 @@ Group: Applications/Engineering
License: GPLv3+ with exceptions
URL: http://www.qgis.org

# Epoch is used when building packages from master, otherwise is set to 1
Epoch: %{_timestamp}

Source0: http://qgis.org/downloads/%{name}-%{version}.tar.bz2

# Sample configuration files for QGIS server
Expand Down

0 comments on commit afb2a6a

Please sign in to comment.