[SSSD] [PATCH] CONTRIB: make_srpm.sh can prepare SRPM with patches

Lukas Slebodnik lslebodn at redhat.com
Wed Jul 9 16:52:26 UTC 2014


On (09/07/14 18:11), Jakub Hrozek wrote:
>On Wed, Jul 09, 2014 at 06:06:48PM +0200, Jakub Hrozek wrote:
>> On Wed, Jul 09, 2014 at 03:05:07PM +0200, Lukas Slebodnik wrote:
>> > ehlo,
>> > 
>> > 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.
>> > 
>> > 
>> > The seond patch is fix, which was reported on sssd-users[1] and fix problem
>> > git-archive on RHEL6
>> > 
>> > [1]https://lists.fedorahosted.org/pipermail/sssd-users/2013-November/001164.html
>> > 
>> > LS
>> 
>> > From 25a196a521613ad35419627c327ed9d83b73c62a Mon Sep 17 00:00:00 2001
>> > From: Lukas Slebodnik <lslebodn at redhat.com>
>> > 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
>> 
>> Could we suppress stderr from cp? Currently there is an error message
>> from cp if you call make_srpm without any extra arguments:
>> 
>> $ bash contrib/fedora/make_srpm.sh
>> cp: cannot stat ‘/home/remote/jhrozek/devel/sssd/contrib/*.patch’: No
>> such file or directory
Fixed.
It was also in previous version ;-)

>> Creating SRPM without extra patches.
>> Wrote: /home/remote/jhrozek/devel/sssd/rpmbuild/SRPMS/sssd-1.11.92-0.fc20.src.rpm
>
>Also, that's not a hard nack but what do you think about using $(cmd)
>expansion instead of backticks like `cmd` ? I'm not sure about
>portability honestly, but $(cmd) is more readable and can be nested.
Changed. This part was copied from Mark Reynolds

LS
-------------- next part --------------
>From eb360dd0afa62b6865a9813f5a911dc02155d729 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Wed, 9 Jul 2014 14:29:45 +0200
Subject: [PATCH] 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 | 62 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 54 insertions(+), 8 deletions(-)

diff --git a/contrib/fedora/make_srpm.sh b/contrib/fedora/make_srpm.sh
index 41bc6fa7dd29b029c92fb5c5715f3f1f73b91f5f..0e16617f0a1fec5d633c8b59ec36ff8cd25e4d6d 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 at 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" \
-- 
1.9.3

-------------- next part --------------
>From ab9916ffb24bba56e078d6b8c48c111b8ba96dee Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Wed, 9 Jul 2014 14:57:17 +0200
Subject: [PATCH 2/2] CONTRIB: Fix creation of tar.gz with old version of git

git archive needn't have support for tar.gz format:
[testm1 contrib]# git --version
git version 1.7.1

Thanks Sami K
---
 contrib/fedora/make_srpm.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/fedora/make_srpm.sh b/contrib/fedora/make_srpm.sh
index f4828232346f5dbc4dfaa8fbf5cc679d429d4b98..3bb561a0ebda716af4a4f48af02f5f9e9ac5fc77 100755
--- a/contrib/fedora/make_srpm.sh
+++ b/contrib/fedora/make_srpm.sh
@@ -151,10 +151,10 @@ sed -e "s/@PACKAGE_NAME@/$PACKAGE_NAME/" \
     > "$RPMBUILD/SPECS/$PACKAGE_NAME.spec"
 
 NAME="$PACKAGE_NAME-$PACKAGE_VERSION"
-git archive --format=tar.gz --prefix="$NAME"/ \
-            --output "$RPMBUILD/SOURCES/$NAME.tar.gz" \
+git archive --format=tar --prefix="$NAME"/ \
             --remote="file://$SRC_DIR" \
-            HEAD
+            HEAD \
+            | gzip > "$RPMBUILD/SOURCES/$NAME.tar.gz"
 
 cp "$SRC_DIR"/contrib/*.patch "$RPMBUILD/SOURCES"
 add_patches "$RPMBUILD/SPECS/$PACKAGE_NAME.spec" \
-- 
1.9.3



More information about the sssd-devel mailing list