>From 25a196a521613ad35419627c327ed9d83b73c62a Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Wed, 9 Jul 2014 14:29:45 +0200 Subject: [PATCH 1/2] 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 --- contrib/fedora/make_srpm.sh | 60 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/contrib/fedora/make_srpm.sh b/contrib/fedora/make_srpm.sh index 41bc6fa7dd29b029c92fb5c5715f3f1f73b91f5f..f4828232346f5dbc4dfaa8fbf5cc679d429d4b98 100755 --- a/contrib/fedora/make_srpm.sh +++ b/contrib/fedora/make_srpm.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Authors: # Lukas Slebodnik @@ -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 ...]" + 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 @@ -114,6 +157,9 @@ git archive --format=tar.gz --prefix="$NAME"/ \ HEAD cp "$SRC_DIR"/contrib/*.patch "$RPMBUILD/SOURCES" +add_patches "$RPMBUILD/SPECS/$PACKAGE_NAME.spec" \ + "$RPMBUILD/SOURCES" \ + "${patches[@]}" cd $RPMBUILD rpmbuild --define "_topdir $RPMBUILD" \ -- 1.9.3