diff mbox

[rdma-core,3/3] cbuild: use rpmspec for macro replacement

Message ID 8ad0438f-b4a5-aec9-1e44-a9c9dc1ca17b@suse.de (mailing list archive)
State Accepted
Headers show

Commit Message

Nicolas Morey-Chaisemartin Aug. 4, 2017, 4:59 p.m. UTC
Generate a temporary file with the spec file parsed and all its macro replaced.
Avoid manually replacing Version and handle extra macros

Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>
---
 .gitignore      | 3 +++
 buildlib/cbuild | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/.gitignore b/.gitignore
index f31a0617..52c7af2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,3 +69,6 @@  tramp
 Session.vim
 .netrwhist
 *~
+
+# rpm
+*/*.spec.processed
\ No newline at end of file
diff --git a/buildlib/cbuild b/buildlib/cbuild
index 5228ec1b..cf7828eb 100755
--- a/buildlib/cbuild
+++ b/buildlib/cbuild
@@ -404,7 +404,12 @@  def get_image_id(args,image_name):
 
 def run_rpm_build(args,spec_file,env):
     version = get_version();
-    with open(spec_file,"r") as F:
+
+    # Pre-process file with rpm spec to avoid manually replacing macros
+    f = open(spec_file + ".processed", "w");
+    subprocess.check_call(["rpmspec", "-P", spec_file], stdout=f);
+
+    with open(spec_file + ".processed" ,"r") as F:
         for ln in F:
             if ln.startswith("Version:"):
                 ver = ln.strip().partition(' ')[2].strip();
@@ -412,7 +417,6 @@  def run_rpm_build(args,spec_file,env):
 
             if ln.startswith("Source:"):
                 tarfn = ln.strip().partition(' ')[2].strip();
-    tarfn = tarfn.replace("%{version}",version);
 
     image_id = get_image_id(args,env.image_name());
     with private_tmp(args) as tmpdir: