summaryrefslogtreecommitdiff
path: root/macros.in
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-06-21 13:45:13 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-06-21 13:59:00 +0300
commit6c5214950e5885c33c498969ca256c9550f5936b (patch)
treed422a83f3279fadd014db85a8bd284513c80efbf /macros.in
parent7c8c36c3342cacc860796b28aaaef4cfb3461901 (diff)
downloadlibrpm-tizen-6c5214950e5885c33c498969ca256c9550f5936b.tar.gz
librpm-tizen-6c5214950e5885c33c498969ca256c9550f5936b.tar.bz2
librpm-tizen-6c5214950e5885c33c498969ca256c9550f5936b.zip
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.
Diffstat (limited to 'macros.in')
-rw-r--r--macros.in56
1 files changed, 56 insertions, 0 deletions
diff --git a/macros.in b/macros.in
index e06146dbd..31bb70c78 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 <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<scm name> Sets the used patch application style, eg '-S git' enables
+# usage of git repository and per-patch commits.
+# -A Automatically apply all patches
+# -p<num> Use -p<num> 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
#*/