[ruby] Extract load macro into external file and include it.

Vít Ondruch vondruch at fedoraproject.org
Tue May 6 12:32:23 UTC 2014


commit 0a113b08ab42965229d4bc12a472d2db8917f176
Author: Vít Ondruch <vondruch at redhat.com>
Date:   Tue May 6 14:31:57 2014 +0200

    Extract load macro into external file and include it.

 load.inc  |   30 ++++++++++++++++++++++++++++++
 ruby.spec |   37 +++++++------------------------------
 2 files changed, 37 insertions(+), 30 deletions(-)
---
diff --git a/load.inc b/load.inc
new file mode 100644
index 0000000..bf9c07e
--- /dev/null
+++ b/load.inc
@@ -0,0 +1,30 @@
+%{lua:
+
+function source_macros(file)
+  local macro = nil
+
+  for line in io.lines(file) do
+    if not macro and line:match("^%%") then
+      macro = line:match("^%%(.*)$")
+      line = nil
+    end
+
+    if macro then
+      if line and macro:match("^.-%s*\\%s*$") then
+        macro = macro .. '\n' .. line
+      end
+
+      if not macro:match("^.-%s*\\%s*$") then
+        rpm.define(macro)
+        macro = nil
+      end
+    end
+  end
+end
+
+}
+
+# Include the constants defined in macros files. Could be dropped as soon as
+# RPM supports the %%load macro (RPM 4.12+ probably).
+# http://lists.rpm.org/pipermail/rpm-maint/2014-February/003659.html
+%define load() %{lua:source_macros(rpm.expand("%1"))}
diff --git a/ruby.spec b/ruby.spec
index 190decb..655437b 100644
--- a/ruby.spec
+++ b/ruby.spec
@@ -86,37 +86,13 @@ Source8: rubygems.attr
 Source9: rubygems.req
 Source10: rubygems.prov
 
+# %%load function should be supported in RPM 4.12+.
+# http://lists.rpm.org/pipermail/rpm-maint/2014-February/003659.html
+Source100: load.inc
+%include %{SOURCE100}
 
-# Include the constants defined in macros files.
-# http://rpm.org/ticket/866
-%{lua:
-
-function source_macros(file)
-  local macro = nil
-
-  for line in io.lines(file) do
-    if not macro and line:match("^%%") then
-      macro = line:match("^%%(.*)$")
-      line = nil
-    end
-
-    if macro then
-      if line and macro:match("^.-%s*\\%s*$") then
-        macro = macro .. '\n' .. line
-      end
-
-      if not macro:match("^.-%s*\\%s*$") then
-        rpm.define(macro)
-        macro = nil
-      end
-    end
-  end
-end
-
-source_macros(rpm.expand("%{SOURCE4}"))
-source_macros(rpm.expand("%{SOURCE5}"))
-
-}
+%{load %{SOURCE4}}
+%{load %{SOURCE5}}
 
 # http://bugs.ruby-lang.org/issues/7807
 Patch0: ruby-2.1.0-Prevent-duplicated-paths-when-empty-version-string-i.patch
@@ -885,6 +861,7 @@ OPENSSL_ENABLE_MD5_VERIFY=1 make check TESTS="-v $DISABLE_TESTS"
 %changelog
 * Tue May 06 2014 Vít Ondruch <vondruch at redhat.com> - 2.1.1-20
 - Remove useless exclude (rhbz#1065897).
+- Extract load macro into external file and include it.
 
 * Wed Apr 23 2014 Vít Ondruch <vondruch at redhat.com> - 2.1.1-19
 - Correctly expand $(prefix) in some Makefiles, e.g. eruby.


More information about the scm-commits mailing list