From 5a9618ce74cfe0199dc94141edf6cb769f28f676 Mon Sep 17 00:00:00 2001 From: Jason Tibbitts Date: Apr 02 2016 05:01:20 +0000 Subject: Add %autosetup macro and necessary support code. --- diff --git a/epel-rpm-macros.spec b/epel-rpm-macros.spec index d485391..43332c6 100644 --- a/epel-rpm-macros.spec +++ b/epel-rpm-macros.spec @@ -1,6 +1,6 @@ Name: epel-rpm-macros Version: 5 -Release: 2 +Release: 3 Summary: Extra Packages for Enterprise Linux RPM macros Group: System Environment/Base @@ -13,7 +13,8 @@ URL: http://download.fedoraproject.org/pub/epel # Please see the file itself for an explanation of its odd name. Source0: macros.zzz-epel -Source1: GPL +Source1: macros.zzz-epel-autosetup +Source9: GPL # Can't use automatic BuildRoot: yet BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) @@ -26,7 +27,7 @@ packaging process between Fedora and EPEL. %prep %setup -c %name-%version -T -install -pm 644 %{SOURCE1} . +install -pm 644 %{SOURCE9} . %build %install @@ -34,6 +35,8 @@ install -pm 644 %{SOURCE1} . rm -rf %{buildroot} install -Dpm 644 %{SOURCE0} \ %{buildroot}/etc/rpm/macros.zzz-epel +install -Dpm 644 %{SOURCE1} \ + %{buildroot}/etc/rpm/macros.zzz-epel-autosetup # Can't use automatic %%clean yet. %clean @@ -43,8 +46,12 @@ rm -rf %{buildroot} # Can't use %%license here yet %doc GPL /etc/rpm/macros.zzz-epel +/etc/rpm/macros.zzz-epel-autosetup %changelog +* Fri Apr 01 2016 Jason L Tibbitts III - 5-3 +- Add %%autosetup. (!) + * Wed Mar 30 2016 Jason L Tibbitts III - 5-2 - Add %%epel. - Add %%rpmmacrodir. diff --git a/macros.zzz-epel b/macros.zzz-epel index 362ab00..a1fead1 100644 --- a/macros.zzz-epel +++ b/macros.zzz-epel @@ -74,6 +74,49 @@ error("Error: macro " .. macro .. " has non-true/false value.") end \ + -- Return the value of a particular macro + function getval(macro, default) + db("getval <= " .. macro) + macro = '%' .. macro + local val = rpm.expand(macro) + if val == macro then + return default + end + return val + end +\ + -- Quiet debugging output + function db_silent() + savedtrace = trace + trace = 0 + end +\ + -- Restore debugging output, but does nothing if it wasn't enabled to begin + -- with. + function db_endsilent() + trace = savedtrace + end +\ + -- Iterate through a bunch of numbered macros, accumulating any found + -- values in a table + function get_numbered_macros(macrobase, max) + db("get_numbered_macros <= " .. macrobase .. ", " .. max) +\ + local val + local out = {} +\ + db_silent() -- Doing a load of getvals, so make them quiet + for i=0,maxcheck do + val = getval(macrobase .. i) + if val ~= nil then + table.insert(out, val) + end + end + db_endsilent() +\ + return out + end +\ rpm.define("epel_macros_init %{nil}") } @@ -168,3 +211,31 @@ # Add a directory for RPM macros that can be used consistently across Fedora and EPEL %rpmmacrodir %{_sysconfdir}/rpm + +# RPM before 4.6.0 does not provide the patches and sources tables to lua code. +# This means that the autosetup macro, if copied over to EL5, won't find any +# patches to apply. However, it is possible to fill those tables manually by +# iterating over a large number of possible 'SOURCE' tags and seeing if they +# exist. +%el5_sources_limit 100000 +%el5_patches_limit 100000 + +%el5_setup_sources %epel_macros_init%{lua: + maxcheck = getval("el5_sources_limit") +\ + sources = get_numbered_macros("SOURCE", maxcheck) +\ + for i,v in ipairs(sources) do + db("Found source: " .. v) + end +} + +%el5_setup_patches() %{lua: + maxcheck = getval("el5_patches_limit") +\ + patches = get_numbered_macros("PATCH", maxcheck) +\ + for i,v in ipairs(patches) do + db("Found patch: " .. v) + end +} diff --git a/macros.zzz-epel-autosetup b/macros.zzz-epel-autosetup new file mode 100644 index 0000000..2abdc31 --- /dev/null +++ b/macros.zzz-epel-autosetup @@ -0,0 +1,95 @@ +# EPEL6-specific macros - autosetup +# +# Define some SCM locations which are not defined by default on EL6 +%__bzr /usr/bin/bzr +%__git /usr/bin/git +%__hg /usr/bin/hg +%__quilt /usr/bin/quilt + +# These were copied verbatim from the Fedora 23 rpm macros on 2016-02-17. + +%patches %{lua: for i, p in ipairs(patches) do print(p.." ") end} +%sources %{lua: for i, s in ipairs(sources) do print(s.." ") end} + +# Macros for further automated spec %setup and patch application +# default to plain patch +%__scm patch +# meh, figure something saner +%__scm_username rpm-build +%__scm_usermail +%__scm_author %{__scm_username} %{__scm_usermail} + +# Plain patch (-m is unused) +%__scm_setup_patch(q) %{nil} +%__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} config user.name "%{__scm_username}"\ +%{__git} config user.email "%{__scm_usermail}"\ +%{__git} add .\ +%{__git} commit %{-q} -a\\\ + --author "%{__scm_author}" -m "%{name}-%{version} base" + +%__scm_apply_git(qp:m:)\ +%{__git} apply --index %{-p:-p%{-p*}} -\ +%{__git} commit %{-q} -m %{-m*} --author "%{__scm_author}" + +# Git, using "git am" (-m is unused) +%__scm_setup_git_am(q)\ +%{expand:%__scm_setup_git %{-q}} + +%__scm_apply_git_am(qp:m:)\ +%{__git} am %{-q} %{-p:-p%{-p*}} + +# Quilt +%__scm_setup_quilt(q) %{nil} +%__scm_apply_quilt(qp:m:)\ +%{__quilt} import %{-p:-p%{-p*}} %{1} && %{__quilt} push + +# Bzr +%__scm_setup_bzr(q)\ +%{__bzr} init %{-q}\ +%{__bzr} whoami --branch "%{__scm_author}"\ +%{__bzr} add .\ +%{__bzr} commit %{-q} -m "%{name}-%{version} base" + +# bzr doesn't seem to have its own command to apply patches? +%__scm_apply_bzr(qp:m:)\ +%{__patch} %{-p:-p%{-p*}} %{-q:-s}\ +%{__bzr} commit %{-q} -m %{-m*} + +# 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:\ +local options = rpm.expand("%{!-v:-q} %{-p:-p%{-p*}} ")\ +for i, p in ipairs(patches) do\ + print(rpm.expand("%apply_patch -m %{basename:"..p.."} "..options..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. +# -N Disable automatic patch application +# -p Use -p for patch application +%autosetup(a:b:cDn:TvNS:p:)\ +%setup %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{!-v:-q}\ +%{-S:%global __scm %{-S*}}\ +%{-S:%{expand:%__scm_setup_%{-S*} %{!-v:-q}}}\ +%{!-N:%el5_setup_patches}\ +%{!-N:%autopatch %{-v} %{-p:-p%{-p*}}}