[Build-common-hackers] Bug#395189: Running commands from
cdbs-edit-patch
Loïc Minier
lool at dooz.org
Wed Oct 25 14:16:31 UTC 2006
Package: cdbs
Version: 0.4.46
Severity: wishlist
Tags: patch
Hi,
This might seem completely superfluous, but I'm sure you're going to
enjoy it.
The proposed patch to cdbs-edit-patch adds support for running commands
instead of a shell; the default is still to run a shell.
Here's why I find it useful: I wrote my own "relibtoolize" shell
snippet which will run libtoolize, aclocal, autoconf appropriately and
cleanup. Ultimately, I'm chaining commands like this:
svn-do cdbs-edit-patch 70_relibtoolize relibtoolize
to merge the SVN debian/ with the tarball (svn-do) edit a new patch (or
existing patch) named 70_relibtoolize, run the relibtoolizing script,
update the patch (cdbs-edit-patch), merge back to SVN (svn-do).
Obviously, there are many possibilities, such as:
cdbs-edit-patch 40_missing-macros cp /usr/share/aclocal/pkg.m4 macros
cdbs-edit-patch 80_frobinate sed 's///g' Makefile
cdbs-edit-patch 99_autoreconf autoreconf
The attached patch is between a cdbs-edit-patch with fixed return code
(#389929) and patch level order (#395180) and one supporting passing a
command on the command-line.
Bye,
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-1-686
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
cdbs depends on no packages.
Versions of packages cdbs recommends:
ii autotools-dev 20060920.1 Update infrastructure for config.{
ii debhelper 5.0.40 helper programs for debian/rules
-- no debconf information
--
Loïc Minier <lool at dooz.org>
-------------- next part --------------
--- /usr/bin/cdbs-edit-patch 2006-10-25 15:00:06.000000000 +0200
+++ /home/lool/bin/cdbs-edit-patch 2006-10-25 15:02:04.000000000 +0200
@@ -25,12 +25,20 @@
dh_testdir
if [ -z "$1" ] || [ "$1" = "--help" ]; then
- echo "Usage: $0 <patch name>"
+ echo "Usage: $0 <patch name> [command]"
exit 0
fi
+getshell() {
+ SH=$(getent passwd $USER | cut -f 7 -d:)
+ [ "$SH" ] || SH=/bin/sh
+ echo "$SH"
+}
+
SRCDIR=$(pwd)
PATCHNAME=${1%.patch}.patch
+shift
+COMMAND="${@:-$(getshell)}"
TMP=$(mktemp -t -d cdbs-new-patch.XXXXXX)
TMP2=$(mktemp -t cdbs-old-patch-header.XXXXXX)
trap "rm -rf $TMP $TMP2" 0 1 2 3 9 11 13 15
@@ -81,16 +89,20 @@
}
fi
-echo "
+if [ "$COMMAND" = "$SHELL" ]; then
+ echo "
You are now in a subshell in a cleaned copy of your source package.
Please make the changes necessary for the patch $PATCHNAME
in this directory and exit with status 0 to create/update the patch.
Exiting with a non-zero value will cancel the patch modification."
+else
+ echo "Running command: $COMMAND"
+fi
-SH=$(getent passwd $USER | cut -f 7 -d:)
-[ "$SH" ] || SH=/bin/sh
+($COMMAND)
+err="$?"
-if $SH; then
+if [ $err = 0 ]; then
if [ -f $SRCDIR/debian/patches/$PATCHNAME ]; then
cat $SRCDIR/debian/patches/$PATCHNAME | patch_header > $TMP2
cat $TMP2 > $SRCDIR/debian/patches/$PATCHNAME
@@ -98,3 +110,5 @@
cd $TMP
diff -Nur $ORIGDIR $NEWDIR >> $SRCDIR/debian/patches/$PATCHNAME || true
fi
+
+exit $err
-------------- next part --------------
#!/bin/sh -e
# create or edit a cdbs simple-patchsys.mk patch
#
# (C) 2005 Martin Pitt <mpitt at debian.org>
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# Stolen from quilt
patch_header()
{
awk '
$1 == "***" || $1 == "---" \
{ exit }
/^Index:[ \t]|^diff[ \t]|^==*$|^RCS file: |^retrieving revision [0-9]+(\.[0-9]+)*$/ \
{ eat = eat $0 "\n"
next }
{ print eat $0
eat = "" }
'
}
dh_testdir
if [ -z "$1" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 <patch name> [command]"
exit 0
fi
getshell() {
SH=$(getent passwd $USER | cut -f 7 -d:)
[ "$SH" ] || SH=/bin/sh
echo "$SH"
}
SRCDIR=$(pwd)
PATCHNAME=${1%.patch}.patch
shift
COMMAND="${@:-$(getshell)}"
TMP=$(mktemp -t -d cdbs-new-patch.XXXXXX)
TMP2=$(mktemp -t cdbs-old-patch-header.XXXXXX)
trap "rm -rf $TMP $TMP2" 0 1 2 3 9 11 13 15
ORIGDIR=$(basename $(pwd))
NEWDIR=$ORIGDIR.new
mkdir -p debian/patches
# create clean source package in temporary dir
cp -a . $TMP/$ORIGDIR
cd $TMP/$ORIGDIR
debclean
# create an empty patch if necessary so that the following loop stops at the
# lexicographic patch position
[ -e "debian/patches/$PATCHNAME" ] || touch "debian/patches/$PATCHNAME"
# remove all patches later than the one to edit
for p in $(find debian/patches -type f -name "*.patch" | LC_COLLATE=C sort -r); do
rm -f "$p"
pname=$(basename "$p")
[ "$pname" != "$PATCHNAME" ] || break
done
debian/rules apply-patches
# create new source dir
cp -a . $TMP/$NEWDIR
cd $TMP/$NEWDIR
# if we edit a patch, apply the already existing one to the new directory
if [ -e "$SRCDIR/debian/patches/$PATCHNAME" ]; then
echo -n "Applying already existing patch to edit directory at level"
for level in 1 0 2; do
echo -n " $level"
if patch --dry-run -E -p$level < "$SRCDIR/debian/patches/$PATCHNAME" > /dev/null 2>&1; then
if patch --no-backup-if-mismatch -V never -p$level < "$SRCDIR/debian/patches/$PATCHNAME" > /dev/null 2>&1; then
echo " success"
success=1
break;
fi
fi
done
[ "$success" ] || {
echo " failure"
exit 1
}
fi
if [ "$COMMAND" = "$SHELL" ]; then
echo "
You are now in a subshell in a cleaned copy of your source package.
Please make the changes necessary for the patch $PATCHNAME
in this directory and exit with status 0 to create/update the patch.
Exiting with a non-zero value will cancel the patch modification."
else
echo "Running command: $COMMAND"
fi
($COMMAND)
err="$?"
if [ $err = 0 ]; then
if [ -f $SRCDIR/debian/patches/$PATCHNAME ]; then
cat $SRCDIR/debian/patches/$PATCHNAME | patch_header > $TMP2
cat $TMP2 > $SRCDIR/debian/patches/$PATCHNAME
fi
cd $TMP
diff -Nur $ORIGDIR $NEWDIR >> $SRCDIR/debian/patches/$PATCHNAME || true
fi
exit $err
More information about the Build-common-hackers
mailing list