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

Lukas Slebodnik lslebodn at redhat.com
Wed Jul 9 13:05:07 UTC 2014


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
-------------- next part --------------
>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
---
 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 <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
@@ -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

-------------- 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