diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2014-07-09 14:29:45 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-07-09 19:06:52 +0200 |
commit | 772f80ea8bc2eefa2bff3873187ea9433b14562a (patch) | |
tree | 9d2d54570e1adac19e3580a065c6b9a5d41d6fad | |
parent | 93760585cc6a9b403ede0211f517adfba713d5c9 (diff) | |
download | sssd-772f80ea8bc2eefa2bff3873187ea9433b14562a.tar.gz sssd-772f80ea8bc2eefa2bff3873187ea9433b14562a.tar.xz sssd-772f80ea8bc2eefa2bff3873187ea9433b14562a.zip |
CONTRIB: make_srpm.sh can prepare SRPM with patches
Creating SRPM with patches is useful for some static analysers, which can do
two builds. The first time without patches and the second with patches.
Bash function add_patches is inspired by file rpm/add_patches.sh from project\
389-ds-base.
commit 2a92a6cccd1002f4fe976ee7a5b79d779b009f87
Author: Mark Reynolds
Thanks.
Resolves:
https://fedorahosted.org/sssd/ticket/2149
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
-rwxr-xr-x | contrib/fedora/make_srpm.sh | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/contrib/fedora/make_srpm.sh b/contrib/fedora/make_srpm.sh index 41bc6fa7d..0e16617f0 100755 --- a/contrib/fedora/make_srpm.sh +++ b/contrib/fedora/make_srpm.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Authors: # Lukas Slebodnik <lslebodn@redhat.com> @@ -21,27 +21,70 @@ PACKAGE_NAME="sssd" usage(){ - echo "$(basename $0) [OPTIONS]" - echo "\t-p, --prerelease Create prerelease SRPM" - echo "\t-d, --debug Enable debugging." - echo "\t-c, --clean Remove directory rpmbuild and exit." - echo "\t-h, --help Print this help and exit." - echo "\t-?, --usage" + echo "$(basename $0) [OPTIONS] [-P|--patches <patch>...]" + echo -e "\t-p, --prerelease Create prerelease SRPM" + echo -e "\t-d, --debug Enable debugging." + echo -e "\t-c, --clean Remove directory rpmbuild and exit." + echo -e "\t-P, --patches Requires list of patches for SRPM." + echo -e "\t-h, --help Print this help and exit." + echo -e "\t-?, --usage" exit 1 } +add_patches(){ + spec_file=$1 + shift + source_dir=$1 + shift + + patches=("${@}") + + # These keep track of our spec file substitutions. + i=1 + prefix="Source0:" + prepprefix="%setup" + + # If no patches exist, just exit. + if [ -z "$patches" ]; then + echo Creating SRPM without extra patches. + return 0 + fi + + # Add the patches to the specfile. + for p in "${patches[@]}"; do + cp "$p" "$source_dir" + p=$(basename $p) + echo "Adding patch to spec file - $p" + sed -i -e "/${prefix}/a Patch${i}: ${p}" \ + -e "/$prepprefix/a %patch${i} -p1" \ + "$spec_file" + + prefix="Patch${i}:" + prepprefix="%patch${i}" + i=$(($i+1)) + done +} + for i in "$@" do case $i in -p|--prerelease) PRERELEASE=1 + shift ;; -d|--debug) set -x + shift ;; -c|--clean) CLEAN=1 + shift + ;; + -P|--patches) + shift + patches=("$@") + break ;; -h|--help|-\?|--usage) usage @@ -113,7 +156,10 @@ git archive --format=tar.gz --prefix="$NAME"/ \ --remote="file://$SRC_DIR" \ HEAD -cp "$SRC_DIR"/contrib/*.patch "$RPMBUILD/SOURCES" +cp "$SRC_DIR"/contrib/*.patch "$RPMBUILD/SOURCES" 2>/dev/null +add_patches "$RPMBUILD/SPECS/$PACKAGE_NAME.spec" \ + "$RPMBUILD/SOURCES" \ + "${patches[@]}" cd $RPMBUILD rpmbuild --define "_topdir $RPMBUILD" \ |