From: Panu Matilainen Date: Thu, 21 Jun 2012 10:45:13 +0000 (+0300) Subject: Add a set of macros to further automate spec %prep tasks X-Git-Tag: tznext/4.11.0.1.tizen20130304~447 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c5214950e5885c33c498969ca256c9550f5936b;p=tools%2Flibrpm-tizen.git Add a set of macros to further automate spec %prep tasks - This adds two main macros (+ bunch of helpers) to automate the common case tasks in %prep: 1) %autopatch which automatically applies all patches from a spec 2) %autosetup which (optionally) takes care of it all, and (also optionally) sets up a git/hg repository of the unpacked source + applied patches as it goes. - This should be considered a starting point only, there are various things to improve. Eg we'd like to be able to make backups with plain patch (based on patch number maybe) and at least with git, we'd like to be able be (optionally) use 'git am' patching style to preserve original authors + commit messages etc. - A noteworthy point here is that as these are fully implemented as macros, they are compatible with several older rpm versions as well. --- diff --git a/configure.ac b/configure.ac index 7604f16..55ba214 100644 --- a/configure.ac +++ b/configure.ac @@ -142,6 +142,9 @@ AC_PATH_PROG(__OBJCOPY, objcopy, /usr/bin/objcopy, $MYPATH) AC_PATH_PROG(__OBJDUMP, objdump, /usr/bin/objdump, $MYPATH) AC_PATH_PROG(__STRIP, strip, /usr/bin/strip, $MYPATH) +AC_PATH_PROG(__GIT, git, /usr/bin/git, $MYPATH) +AC_PATH_PROG(__HG, hg, /usr/bin/hg, $MYPATH) + AC_PATH_PROG(__FAKECHROOT, fakechroot, no, $MYPATH) AM_CONDITIONAL(HAVE_FAKECHROOT, [test "$__FAKECHROOT" != "no"]) diff --git a/macros.in b/macros.in index e06146d..31bb70c 100644 --- a/macros.in +++ b/macros.in @@ -68,6 +68,8 @@ %__ssh @__SSH@ %__tar @__TAR@ %__unzip @__UNZIP@ +%__git @__GIT@ +%__hg @__HG@ #============================================================================== # ---- Build system path macros. @@ -1022,5 +1024,59 @@ done \ %__collection_sepolicy %{__plugindir}/sepolicy.so %__collection_sepolicy_flags 1 +#------------------------------------------------------------------------------ +# Macros for further automated spec %setup and patch application + +# default to plain patch +%__scm patch +# meh, figure something saner +%__scm_author rpm-build + +# Plain patch (-m is unused) +%__scm_apply_patch(qp:m:)\ +%{__patch} %{-p:-p%{-p*}} %{-q:-s} + +# Mercurial (aka hg) +%__scm_setup_hg(q)\ +%{__hg} init %{-q} .\ +%{__hg} add %{-q} .\ +%{__hg} commit %{-q} --user "%{__scm_author}" -m "%{name}-%{version} base" + +%__scm_apply_hg(qp:m:)\ +%{__hg} import - %{-p:-p%{-p*}} %{-q} -m %{-m*} --user "%{__scm_author}" + +# Git +%__scm_setup_git(q)\ +%{__git} init %{-q}\ +%{__git} add .\ +%{__git} commit %{-q} -a\\\ + --author "%{__scm_author}" -m "%{name}-%{version} base" + +%__scm_apply_git(qp:m:)\ +%{__git} apply %{-p:-p%{-p*}} -\ +%{__git} commit %{-q} -a -m %{-m*} --author "%{__scm_author}" + +# Single patch application +%apply_patch(qp:m:)\ +%{uncompress:%{1}} | %{expand:%__scm_apply_%{__scm} %{-q} %{-p:-p%{-p*}} %{-m:-m%{-m*}}} + +# Automatically apply all patches +%autopatch(vp:)\ +%{lua:\ +for i, p in ipairs(patches) do\ + print(rpm.expand("%apply_patch -m %{basename:"..p.."} "..rpm.expand("%{!-v:-q} %{-p:-p%{-p*}} ")..p.."\\n"))\ +end} + +# One macro to (optionally) do it all. +# -S Sets the used patch application style, eg '-S git' enables +# usage of git repository and per-patch commits. +# -A Automatically apply all patches +# -p Use -p for patch application +%autosetup(a:b:cDn:TvAS:p:)\ +%setup %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{!-v:-q}\ +%{-S:%global __scm %{-S*}}\ +%{-S:%{expand:%__scm_setup_%{-S*} %{!-v:-q}}}\ +%{-A:%autopatch %{-v} %{-p:-p%{-p*}}} + # \endverbatim #*/